Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Syntax-highlighting, declarative and composable pretty printer for Python 3.5+
Documentation_
Syntax-highlighting, declarative and composable pretty printer for Python 3.5+
.. code:: bash
pip install prettyprinter
pprint
: just rename pprint
to prettyprinter
in your imports... image:: prettyprinterscreenshot.png :alt:
.. image:: ../prettyprinterscreenshot.png :alt:
.. image:: prettyprinterlightscreenshot.png :alt:
.. image:: ../prettyprinterlightscreenshot.png :alt:
Pretty print common Python values:
.. code:: python
>>> from datetime import datetime
>>> from prettyprinter import pprint
>>> pprint({'beautiful output': datetime.now()})
{
'beautiful output': datetime.datetime(
year=2017,
month=12,
day=12,
hour=0,
minute=43,
second=4,
microsecond=752094
)
}
As well as your own, without any manual string formatting:
.. code:: python
>>> class MyClass:
... def __init__(self, one, two):
... self.one = one
... self.two = two
>>> from prettyprinter import register_pretty, pretty_call
>>> @register_pretty(MyClass)
... def pretty_myclass(value, ctx):
... return pretty_call(ctx, MyClass, one=value.one, two=value.two)
>>> pprint(MyClass((1, 2, 3), {'a': 1, 'b': 2}))
MyClass(one=(1, 2, 3), two={'a': 1, 'b': 2})
>>> pprint({'beautiful output': datetime.now(), 'beautiful MyClass instance': MyClass((1, 2, 3), {'a': 1, 'b': 2})})
{
'beautiful MyClass instance': MyClass(
one=(1, 2, 3),
two={'a': 1, 'b': 2}
),
'beautiful output': datetime.datetime(
year=2017,
month=12,
day=12,
hour=0,
minute=44,
second=18,
microsecond=384219
)
}
Comes packaged with the following pretty printer definitions, which you can enable by calling prettyprinter.install_extras()
:
datetime
- (installed by default)enum
- (installed by default)pytz
- (installed by default)dataclasses
- any new class you create will be pretty printed automaticallyattrs
- pretty prints any new class you create with attrs
django
- pretty prints your Models and QuerySetsnumpy
- pretty prints numpy scalars with explicit typesrequests
- pretty prints Requests, Responses, Sessions, and more from the requests
library.. _Documentation: https://prettyprinter.readthedocs.io
Improve prettyprinting of builtin bound methods. <https://github.com/tommikaikkonen/prettyprinter/pull/57>
_ by @anntzer <https://github.com/anntzer>
_Fix test suite compatibility with hypothesis4. <https://github.com/tommikaikkonen/prettyprinter/pull/58>
_ by @anntzer <https://github.com/anntzer>
_Use $COLORFGBG to help decide whether to use a dark or light style <https://github.com/tommikaikkonen/prettyprinter/pull/62>
_ by @crowsonkb <https://github.com/crowsonkb>
_Truncate numpy arrays with ndim >= 2 so that the total printed does not exceed max_seq_len <https://github.com/tommikaikkonen/prettyprinter/pull/63>
_ by @crowsonkb <https://github.com/crowsonkb>
_Add prettyprinter for numpy ndarrays. <https://github.com/tommikaikkonen/prettyprinter/pull/47>
_ by @anntzer <https://github.com/anntzer>
_Add helper to apply default config. <https://github.com/tommikaikkonen/prettyprinter/pull/46>
_ by @anntzer <https://github.com/anntzer>
_#43 <https://github.com/tommikaikkonen/prettyprinter/pull/43>
, #44 <https://github.com/tommikaikkonen/prettyprinter/pull/44>
, #45 <https://github.com/tommikaikkonen/prettyprinter/pull/45>
_ .Thanks @anntzer <https://github.com/anntzer>
_Add support for functools.partialmethod. <https://github.com/tommikaikkonen/prettyprinter/pull/42>
_ by @anntzer <https://github.com/anntzer>
_Fix typo in changelog. <https://github.com/tommikaikkonen/prettyprinter/pull/40>
_ Thanks @Vlad-Shcherbina <https://github.com/Vlad-Shcherbina>
_Adds a new extra for numpy. <https://github.com/tommikaikkonen/prettyprinter/pull/39>
_ The extra currently registers pretty printers for numpy scalar types. Enable it with import prettyprinter; prettyprinter.install_extras(['numpy'])
. Thanks @anntzer <https://github.com/anntzer>
_C-API named tuples are now automatically prettyprinted. <https://github.com/tommikaikkonen/prettyprinter/pull/38>
_ C-API named tuples are returned from expressions such as sys.flags
, time.strptime(...)
, and os.stat(...)
. The fieldname of each tuple element is annotated using a comment in the output.This release brings bugfixes, an enhancement to pathlib prettyprinting (thanks @anntzer <https://github.com/anntzer>
_ ) and a nice performance boost. There was an redundant subtree call in a tree normalization procedure that caused exponential runtime, worsening quickly if data was highly nested. That extra call is now removed.
Fix exponential runtime in highly nested data <https://github.com/tommikaikkonen/prettyprinter/pull/34>
_Fix infinite loop when rendering strings in highly nested data <https://github.com/tommikaikkonen/prettyprinter/pull/33>
_Only split Path prettyprints on "/", not on "-" or other nonword chars. <https://github.com/tommikaikkonen/prettyprinter/pull/29>
_ , thanks @anntzer <https://github.com/anntzer>
_Add vim swapfiles to gitignore <https://github.com/tommikaikkonen/prettyprinter/pull/30>
_ , thanks @anntzer <https://github.com/anntzer>
_Fix typo <https://github.com/tommikaikkonen/prettyprinter/pull/31>
_ , thanks @anntzer <https://github.com/anntzer>
_Most likely no breaking changes.
pathlib
standard library module thanks to GitHub user RazerM
jdanbrown
setup.py
requirements listNo breaking changes.
dangirsh
.No breaking changes.
No breaking changes.
ast
standard library module thanks to GitHub user johnnoone
.No breaking changes.
collections.namedtuple
collections.ChainMap
, collections.defaultdict
, collections.deque
, functools.partial
, and for exception objects.No breaking changes.
pretty_call_alt
function that doesn't depend on dict
maintaining insertion orderset_default_config
where most configuration values were not updatedget_default_config
No breaking changes.
No breaking changes.
str
to register_pretty
. For an example, see the deferred printer registration for uuid.UUID <https://github.com/tommikaikkonen/prettyprinter/blob/05187126889ade1c2bf0557a40800e5c44a32bab/prettyprinter/pretty_stdlib.py#L38-L40>
_No breaking changes.
types.MappingProxyType
thanks to GitHub user Cologler <https://github.com/Cologler/>
__repr_pretty_
in the extra ipython_repr_pretty
.str
value for IPython's highlighting_style
setting was not properly handled in prettyprinter
's IPython integration, and raised an exception when trying to print data.Breaking changes:
dict
keys are printed in the default order (insertion order in CPython 3.6+). Previously they were sorted like in the pprint
standard library module. To let the user control this, an additional keyword argument sort_dict_keys
was added to cpprint
, pprint
, and pformat
. Pretty printer definitions can control dict
key sorting with the PrettyContext
instance passed to each pretty printer function.Non-breaking changes:
prettyprinter.pretty_repr
that is assignable to __repr__
dunder methods, so you don't need to write it separately from the pretty printer definition.PrettyContext.set
in favor of less misleading PrettyContext.assoc
type
, i.e. classes.Breaking change: instances of lists, sets, frozensets, tuples and dicts will be truncated to 1000 elements by default when printing.
dataclasses
max_seq_len
to None
using set_default_config
explained below.set_default_config
. The functions accepts zero to many keyword arguments and replaces those values in the global configuration with the ones provided... code:: python
from prettyprinter import set_default_config
set_default_config(
style='dark',
max_seq_len=1000,
width=79,
ribbon_width=71,
depth=None,
)
No backwards incompatible changes.
requests
library. To use it, include 'requests'
in your install_extras
call: prettyprinter.install_extras(include=['requests'])
.No backwards incompatible changes.
install_extras
arguments for unknown extrascomment
to accept both normal Python values and Docs, and reversed the argument order to be more Pythonicset_default_style
function, improve docs on working with a light backgroundFAQs
Syntax-highlighting, declarative and composable pretty printer for Python 3.5+
We found that prettyprinter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.