Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Prints out python variables in an easy to read way, handy for debugging

Project description

A collection of handy functions for printing out variables and debugging code.

print() was too hard to read, pprint wasn’t much better. I was also getting sick of typing: print "var = ", var.

This tries to print out variables with their name, and for good measure, it also prints where the pout function was called from, so you can easily find it and delete it when you’re done.


pout.v(arg1, [arg2, …]) – easy way to print variables


foo = 1

bar = [1, 2, [3, 4], 5]

should print something like:

foo = 1

bar (4) =
        0: 1,
        1: 2,
                        0: 3,
                        1: 4
        3: 5

You can send as many variables as you want into the call

# pass in as many variables as you want
pout.v(foo, bar, che)

# a multi-line call is also fine

pout.h() – easy way to print “here” in the code


# do something else

# do even more of something else

Should print something like:

here 1 (/

here 2 (/

here (/

pout.t() – print a backtrace

Prints a nicely formatted backtrace, by default this should compact system python calls (eg, anything in dist-packages) which makes the backtrace easier for me to follow.



should print something like:

15 - C:\Python27\lib\
14 - C:\Python27\lib\
13 - C:\Python27\lib\unittest\
12 - C:\Python27\lib\unittest\
11 - C:\Python27\lib\unittest\
10 - C:\Python27\lib\unittest\
09 - C:\Python27\lib\unittest\
08 - C:\Python27\lib\unittest\
07 - C:\Python27\lib\unittest\
06 - C:\Python27\lib\unittest\
05 - C:\Python27\lib\unittest\
04 - C:\Python27\lib\unittest\
03 - C:\Python27\lib\unittest\
02 - C:\Python27\lib\unittest\
01 - C:\Projects\Pout\_pout\src\


pout.p([title]) – quick and dirty profiling


p("starting profile")
p() # stop the "starting profile" session

# you can go N levels deep
p() # stop profiling of "two"
p() # stop profiling of "one"

# you can also use with
with p("benchmarking"):

should print something like:

starting profile - 1008.2 ms
  start: 1368137723.7 (/file/path:n)
  stop: 1368137724.71(/file/path:n)

one > two - 509.2 ms
  start: 1368137722.69 (/file/path:n)
  stop: 1368137723.2(/file/path:n)

one - 1025.9 ms
  start: 1368137722.68 (/file/path:n)
  stop: 1368137723.7(/file/path:n)

pout.x([exit_code]) – like sys.exit(exit_code)

This just prints out where it was called from, so you can remember where you exited the code while debugging



will print something like this before exiting with an exit code of 1:

exit (/file/path:n)

pout.b([title[, rows[, sep]]]) – prints lots of lines to break up output

This is is handy if you are printing lots of stuff in a loop and you want to break up the output into sections.


pout.b('this is the title')
pout.b('this is the title 2', 5)
pout.b('this is the title 3', 3, '=')

Would result in output like:


****************************** this is the title *******************************

***************************** this is the title 2 ******************************

============================= this is the title 3 ==============================

pout.c(str1, [str2, …]) – print info about each char in each str

Kind of like od -c on the command line.



will print something like:

Total Characters: 4
t   't' \u0074  LATIN SMALL LETTER T
h   'h' \u0068  LATIN SMALL LETTER H
i   'i' \u0069  LATIN SMALL LETTER I
s   's' \u0073  LATIN SMALL LETTER S

This could fail if Python isn’t compiled with 4 byte unicode support, just something to be aware of, but chances are, if you don’t have 4 byte unicode supported Python, you’re not doing much with 4 byte unicode.

pout.s(arg1, [arg2, …]) – easy way to return pretty versions of variables

Just like pout.v() but will return the value as a string, [arg2, …]) – easy way to return pretty versions of variables without meta information

Just like pout.vv() but will return the value as a string

pout.l([logger_name, [logger_level]]) – turn logging on just for this context

Turns logging on for the given level (defaults to logging.DEBUG) and prints the logs to stderr. Useful when you just want to check the logs of something without modifying your current logging configuration.


with pout.l():
    logger.debug("This will print to the screen even if logging is off")
logger.debug("this will not print if logging is off")

with pout.l("name"):
    # if "name" logger is used it will print to stderr
# "name" logger goes back to previous configuration

Customizing Pout

object magic method

Any class object can define a __pout__ magic method, similar to Python’s built in __str__ magic method that can return a customized string of the object if you want to. This method can return anything, it will be run through Pout’s internal stringify methods to convert it to a string and print it out.


You can create your own class and set this module variable and any pout method will then use your custom class:

class PoutChild(pout.Pout):

# any pout.* calls will now use your child class, customize as you like
pout.pout_class = PoutChild

Console commands


running a command on the command line that outputs a whole a bunch of json? Pout can help:

$ some-command-that-outputs-json | pout.json


Runs pout.c but on the output from a command line script:

$ echo "some string with chars to analyze" | pout.char



pip install pout

Generally, the pypi version and the github version shouldn’t be that out of sync, but just in case, you can install from github also:

pip install git+

Make Pout easier to use

When debugging, it’s really nice not having to put import pout at the top of every module you want to use it in, so there’s a command for that, if you put:

import pout

Somewhere near the top of your application startup script, then pout will be available in all your files whether you imported it or not, it will be just like str(), object, or the rest of python’s standard library.

If you don’t even want to bother with doing that, then just run:

$ pout inject

from the command line and it will modify your python environment to make pout available as a builtin module, just like the python standard library. This is super handy for development virtual environments.

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 pout, version 0.7.9
Filename, size File type Python version Upload date Hashes
Filename, size pout-0.7.9.tar.gz (26.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page