Welcome to peep’s documentation!

Release v0.9.0.

Peep provides simple but useful tools for Python development.

It includes a reloading function runner that can minimize your edit-compile-run cycle and some tools for estimating deep memory usage of objects.

The reloading function runner was inspired by Bret Victor’s talk, “Inventing on Principle”. Automatic reexecution is the first step, and peep may grow to include more functionality from that talk.

Peep is a small API and has no dependencies outside of the Python standard library. It works with Python 2.6 and 2.7.

Reporting memory usage

It supports getting memory usage (in bytes) of object trees:

>>> obj = {"foo": "bar", "baz": ("quux", "quuux", "quuuux")}
>>> peep.mem_usage(obj)
606

The same information, broken down by object type:

>>> obj = {"foo": "bar", "baz": ("quux", "quuux", "quuuux")}
>>> peep.mem_usage_by_type(obj)
{<type 'dict'>: 280, <type 'str'>: 246, <type 'tuple'>: 80}

Reloading function runner

The reloading function runner takes a callable that accepts no arguments and will not be reloaded itself. This means you can’t pass a reference to an already compiled function; use a partial function or a lambda expression.

With foo.py:

def run():
    return "This is returned from foo.run()"
>>> import foo
>>> peep.call_on_change(lambda: foo.run())
======== 1365429591.13
This is returned from foo.run()

[ modify foo.py ]

=== reloading <module 'foo' from 'foo.py'>
======== 1365429594.64
This is newly returned from foo.run()
peep.call_on_change(callable)[source]

Call callable() once, then whenever Python source files are changed

Print the result after each execution. Catch exceptions and print those, too.

This doesn’t yet manage dependencies between loaded modules, so if “bar” requires “foo” it will not be reloaded when “foo” is changed.

peep.mem_usage(obj)[source]

Sum the bytes used by obj and any object reachable from obj

>>> peep.mem_usage([1, 2, 3, 4])
200
peep.mem_usage_by_type(obj)[source]

Aggregate the memory usage of objects reachable from obj (by type)

>>> peep.mem_usage_by_type([1, 2, 3, 4, (1, 2)])
{<type 'list'>: 112, <type 'tuple'>: 72, <type 'int'>: 24}

Project Versions

Table Of Contents

This Page