Pretty SimpleNamespace
Table of Contents
What is it?
- A stringifier and formatter for SimpleNamespace which attempts to make the data as readable as possible.
Why create it?
- I use SimpleNamespace often to hold state and needed a way to print it out for debugging purposes.
Simple usage
from pretty_simple_namespace import pprint
from types import SimpleNamespace as o
joe = o(
name={"first": "joe", "last": "schmo"},
age=30,
favoriteFoods=["apples", "steak"],
)
pprint(joe)
# prints
# {
# name: {
# first: 'joe'
# last: 'schmo'
# }
# age: 30
# favoriteFoods: [
# 'apples'
# 'steak'
# ]
# }
Features
- handles recursive structures by tracking and printing references nicely
- recurses into types
list,dictandSimpleNamespacefor now - has special-case printing for types
bool,str,callableandNone- booleans and None are printed lowercase
- strings are wrapped in single quotes
- callable appends
()e.g.myMethod(). Arguments aren't represented
- all other types are printed by wrapping it in
stre.g.str(userDefinedType)
Limitations
- multi-line strings look ugly
- doesn't have a way to recurse into structures other than what's listed above
Related projects
Api
format(something, indent=2) => str
- formats
somethingto a string as seen in Simple usage
pprint(something, indent=2) => None
- just prints the formated
something
wrapWith(*, indent) => Wrapped module
-
use this when you want to call
formatorpprintwith a different default indent value so you don't have to pass it manually all the time.e.g.
from pretty_simple_namespace import wrapWith pprint = wrapWith(indent=4).pprint pprint(o(tabbed4spaces=True)) # { # tabbed4spaces: true # }
Wrapped module
- just an instance of SimpleNamespace with two attributes
formatandpprint.
Test
#
# you must have poetry installed
#
$ poetry shell
$ poetry install
$ python runTests.py
Metadata
Release files for pretty-simple-namespace 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pretty_simple_namespace-0.1.1.tar.gz | 914.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pretty_simple_namespace-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.0 MB
Release files / pretty_simple_namespace-0.1.1.tar.gz
| Download URL | pretty_simple_namespace-0.1.1.tar.gz |
|---|---|
| Size | 914.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7579dcb10091defe84d3702aa0680b8ccf4ee00f93e8b0bf85195a7b93aef4af
|
|
BLAKE2b-256 checksum How to use checksums |
1edf54830ecc0bc254b7a53e160f734fcad933a69c901c42cadaca71892c5369
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH
|
Release files / pretty_simple_namespace-0.1.1-py3-none-any.whl
| Download URL | pretty_simple_namespace-0.1.1-py3-none-any.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17cb165fa3a3e55605c6f3204bf077d62fc53a7005afe2de3cb9c4ed6c2718a5
|
|
BLAKE2b-256 checksum How to use checksums |
b28c461c20ac66fe60e912985ec578fe9cebad62033198e559482d6fc6311ba7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH
|
Security for pretty-simple-namespace 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.