Skip to main content

NAME

data_printer - data printer and dumper

VERSION

0.0.8

SYNOPSIS

from data_printer import p, np

import sys
from colored import fore, back, style

class A:
    def __init__(self, **kw):
        for k, v in kw.items():
            setattr(self, k, v)

data = A(abc="acc", a=A(x=dict(p=10, r=[20, (2, 0.01)])), s='Строка\n', b=b'binary\n', r=r'\n')

# add ref to themselwes:
data.a.x['r'].append(data)  

# print colored structure to sys.stdout
p(data)

# print colored structure to file stream
p(data, file=sys.stderr)

# print uncolored structure to file stream
p(data, file=sys.stderr, color=False)

# serialize structure to string
s = np(data)

# serialize structure to string without indexes: [6] -> [0] 6
s = np(data, indexes=False)

# serialize structure to colored string (colors as escape sequences)
s = np(data, color=True)

# default color scheme
p(data, color=dict(
    bool = fore.LIGHT_BLUE,
    none = fore.LIGHT_BLUE,
    int = fore.LIGHT_YELLOW,
    float = fore.LIGHT_YELLOW,
    str = fore.LIGHT_GREEN,
    bytes = fore.LIGHT_MAGENTA,
    object = fore.LIGHT_RED,
    any = fore.LIGHT_GRAY,
    key = fore.LIGHT_CYAN,
    ref = fore.RED,
    punct = fore.WHITE,
))

# replace two colors
s = np(data, color=dict(
    bool = fore.LIGHT_RED,
    none = fore.LIGHT_YELLOW,
))

# print in perl-style (python - default) and without "[0] 7" in list "[7]". 
p(data, sep="perl", indexes=False)

# print in node-style
p(data, sep="node")

# self-style
p(data, sep=dict(
    kword=True,
    oword=True,
    kw=" => ",
    kv=" => ",
    object_open="bless {",
    object_close="}, %n",
    dict_open="{",
    dict_close="}",
    list_open="[",
    list_close="]",
    tuple_open="[",
    tuple_close="]",
    str='"%s"',
    bytes='do { use bytes; "%s" }',
    scalar='%n("%s")',      # for datetime.datetime and others
    none="undef",
    true="1",
    false="0"
))

# self-style with two and lambda on bytes
p(data, sep=dict(
    str='"%s"',
    bytes=lambda s: "".join(['Buffer.from(", ', ", ".join(["0x%X" % ch for ch in s]) ,')']),
))

# filters use for specific objects
import datetime
p([datetime.datetime.now()], filters={
    datetime.datetime: lambda obj, ddp: ddp.echo("⎈ ", ddp.color.key).echo(repr(obj), ddp.color.any),
})


# print without newline on the end
p(data, end="")

DESCRIPTION

Data recursive printer. Serialize any python3 data to string or print in console or file.

Is colorised output.

Data printer check many references to one structure.

INSTALL

$ pip install data-printer

REQUIREMENTS

  • colored

AUTHOR

Kosmina O. Yaroslav darviarush@mail.ru

LICENSE

MIT License

Copyright (c) 2020 Kosmina O. Yaroslav

Release files for data-printer 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for data-printer 0.0.8
File Size Uploaded
data-printer-0.0.8.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for data-printer 0.0.8
File Interpreter ABI Platform
data_printer-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / data-printer-0.0.8.tar.gz

Download URL data-printer-0.0.8.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
55292b14c49a2b2ba4441a068f2fe77abcda8f8956f4d5d2d694831f8eb5dbcb
BLAKE2b-256 checksum
How to use checksums
5ce13e63662d835af86346b65ab0ebdce9e818bbdde552a592d4824e309a8588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / data_printer-0.0.8-py3-none-any.whl

Download URL data_printer-0.0.8-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9253a914a15a7ba65f78f7b9ead786f20a8deeb0bba1b27a9e924e17f7380ffd
BLAKE2b-256 checksum
How to use checksums
ee25af14e62213d964fed5600e3a55c06bd3b005cbf1bff85161617e85da6e92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page