Skip to main content

A pretty printer for SimpleNamespace

Project description

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"},
    favoriteFoods=["apples", "steak"],

# prints
# {
#   name: {
#     first: 'joe'
#     last: 'schmo'
#   }
#   age: 30
#   favoriteFoods: [
#     'apples'
#     'steak'
#   ]
# }


  • handles recursive structures by tracking and printing references nicely
  • recurses into types list, dict and SimpleNamespace for now
  • has special-case printing for types bool, str, callable and None
    • 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 str e.g. str(userDefinedType)


  • multi-line strings look ugly
  • doesn't have a way to recurse into structures other than what's listed above

Related projects


format(something, indent=2) => str

pprint(something, indent=2) => None

  • just prints the formated something

wrapWith(*, indent) => Wrapped module

  • use this when you want to call format or pprint with a different default indent value so you don't have to pass it manually all the time.


    from pretty_simple_namespace import wrapWith
    pprint = wrapWith(indent=4).pprint
    # {
    #     tabbed4spaces: true
    # }

Wrapped module

  • just an instance of SimpleNamespace with two attributes format and pprint.


# you must have poetry installed
$ poetry shell
$ poetry install
$ python

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pretty-simple-namespace, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size pretty_simple_namespace-0.1.1-py3-none-any.whl (1.1 MB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pretty_simple_namespace-0.1.1.tar.gz (914.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page