Package: prettyprinter
PrettyPrinterDocumentationSyntax-highlighting, declarative and composable pretty printer for Python 3.5+pipinstallprettyprinterDrop in replacement for the standard librarypprint: just renamepprinttoprettyprinterin your imports.Uses a modified Wadler-Leijen layout algorithm for optimal formattingWrite pretty printers for your own types with a dead simple, declarative interfacePretty print common Python values:>>>fromdatetimeimportdatetime>>>fromprettyprinterimportpprint>>>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:>>>classMyClass:...def__init__(self,one,two):...self.one=one...self.two=two>>>fromprettyprinterimportregister_pretty,pretty_call>>>@register_pretty(MyClass)...defpretty_myclass(value,ctx):...returnpretty_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 callingprettyprinter.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 withattrsdjango- pretty prints your Models and QuerySetsnumpy- pretty prints numpy scalars with explicit typesrequests- pretty prints Requests, Responses, Sessions, and more from therequestslibraryFree software: MIT licenseDocumentation:Documentation.History0.18.0 (2019-06-21)Improve prettyprinting of builtin bound methods.by@anntzerFix test suite compatibility with hypothesis4.by@anntzerUse $COLORFGBG to help decide whether to use a dark or light styleby@crowsonkbTruncate numpy arrays with ndim >= 2 so that the total printed does not exceed max_seq_lenby@crowsonkbFixed ipython_repr_pretty extra raising an exception when printing Mock instances (GH #61)Added support for pretty printing types.SimpleNamespace (GH #60)Fixed dictionary pretty printing indentation when the value had a comment on the line above (GH #59)0.17.0 (2019-03-14)Add prettyprinter for numpy ndarrays.by@anntzerAdd helper to apply default config.by@anntzerA number of docs and CI improvements:#43,#44,#45.Thanks@anntzerAdd support for functools.partialmethod.by@anntzerFix typo in changelog.Thanks@Vlad-Shcherbina0.16.0 (2019-02-27)Adds a new extra for numpy.The extra currently registers pretty printers for numpy scalar types. Enable it withimport prettyprinter;prettyprinter.install_extras(['numpy']). Thanks@anntzerC-API named tuples are now automatically prettyprinted.C-API named tuples are returned from expressions such assys.flags,time.strptime(...), andos.stat(...). The fieldname of each tuple element is annotated using a comment in the output.0.15.0 (2019-02-25)This release brings bugfixes, an enhancement to pathlib prettyprinting (thanks@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 dataFix infinite loop when rendering strings in highly nested dataOnly split Path prettyprints on “/”, not on “-” or other nonword chars., thanks@anntzerAdd vim swapfiles to gitignore, thanks@anntzerFix typo, thanks@anntzer0.14.0 (2018-07-25)Most likely no breaking changes.Added definitions forpathlibstandard library module thanks to GitHub userRazerMFixed unexpected error output inside Jupyter notebooks thanks to GitHub userjdanbrownFixed missing commas insetup.pyrequirements list0.13.2 (2018-05-29)No breaking changes.Fixed the dataclasses pretty printer that had regressed after changes to the dataclasses API. Fix was contributed by GitHub userdangirsh.0.13.1 (2018-02-03)No breaking changes.Fixed GH issue #17 where Django models showed an incorrect display name for fields with choices.0.13.0 (2018-02-03)No breaking changes.Added definitions for theaststandard library module thanks to GitHub userjohnnoone.0.12.0 (2018-01-22)No breaking changes.Added a definition for classes that look like they were built withcollections.namedtupleIf a pretty printer raises an exception, it is caught and emitted as a warning, and the default repr implementation will be used instead.Added definitions forcollections.ChainMap,collections.defaultdict,collections.deque,functools.partial, and for exception objects.Made pretty printers for primitive types (dict, list, set, etc.) render a subclass constructor around them0.11.0 (2018-01-20)No breaking changes.Added Python 3.5 supportAddedpretty_call_altfunction that doesn’t depend ondictmaintaining insertion orderFixed bug inset_default_configwhere most configuration values were not updatedAddedget_default_config0.10.1 (2018-01-10)No breaking changes.Fixed regression with types.MappingProxyType not being properly registered.0.10.0 (2018-01-09)No breaking changes.Added support for deferred printer registration, where instead of a concrete type value, you can pass a qualified path to a type as astrtoregister_pretty. For an example, seethe deferred printer registration for uuid.UUID0.9.0 (2018-01-03)No breaking changes.Added pretty printer definition fortypes.MappingProxyTypethanks to GitHub userCologlerAdded support for_repr_pretty_in the extraipython_repr_pretty.0.8.1 (2018-01-01)Fixed issue #7 where having astrvalue for IPython’shighlighting_stylesetting was not properly handled inprettyprinter’s IPython integration, and raised an exception when trying to print data.0.8.0 (2017-12-31)Breaking changes:by default,dictkeys are printed in the default order (insertion order in CPython 3.6+). Previously they were sorted like in thepprintstandard library module. To let the user control this, an additional keyword argumentsort_dict_keyswas added tocpprint,pprint, andpformat. Pretty printer definitions can controldictkey sorting with thePrettyContextinstance passed to each pretty printer function.Non-breaking changes:Improved performance of rendering colorized output by caching colors.Addedprettyprinter.pretty_reprthat is assignable to__repr__dunder methods, so you don’t need to write it separately from the pretty printer definition.Deprecated use ofPrettyContext.setin favor of less misleadingPrettyContext.assocDefined pretty printing for instances oftype, i.e. classes.Defined pretty printing for functions0.7.0 (2017-12-23)Breaking change: instances of lists, sets, frozensets, tuples and dicts will be truncated to 1000 elements by default when printing.Added pretty printing definitions fordataclassesImproved performance of splitting strings to multiple lines by ~15%Added a maximum sequence length that applies to subclasses of lists, sets, frozensets, tuples and dicts. The default is 1000. There is a trailing comment that indicates the number of truncated elements. To remove truncation, you can setmax_seq_lentoNoneusingset_default_configexplained below.Added ability to change the default global configuration usingset_default_config. The functions accepts zero to many keyword arguments and replaces those values in the global configuration with the ones provided.fromprettyprinterimportset_default_configset_default_config(style='dark',max_seq_len=1000,width=79,ribbon_width=71,depth=None,)0.6.0 (2017-12-21)No backwards incompatible changes.Added pretty printer definitions for therequestslibrary. To use it, include'requests'in yourinstall_extrascall:prettyprinter.install_extras(include=['requests']).0.5.0 (2017-12-21)No backwards incompatible changes.Added integration for the default Python shellWrote docs to explain integration with the default Python shellCheckinstall_extrasarguments for unknown extras0.4.0 (2017-12-14)Revisedcommentto accept both normal Python values and Docs, and reversed the argument order to be more Pythonic0.3.0 (2017-12-12)Addset_default_stylefunction, improve docs on working with a light background0.2.0 (2017-12-12)Numerous API changes and improvements.0.1.0 (2017-12-07)First release on PyPI.