Skip to main content

Pretty-print Python objects to Buche logger.

Project description

Helper package to pretty-print and interact with Python objects using the Buche logger.

The package includes a repl and a debugger.

Requires Python >= 3.6


You must install Buche first, either from the release or through npm (npm install -g buche). This package helps interact with Buche, but it is not the application itself. Once you have written your script, use it as follows:

python -m buche

Alternatively, using buche directly:

buche python -u


Here’s an example of what you can do with Buche. You can run this code using buche python3 examples/

from buche import buche, H

# You don't have to set a template, but if you do, it must be the
# very first command you emit, before any printing.
# You can also give `src=<path-to-file>` instead of `content=...`

# Use this command to add styles, stylesheets, scripts, etc.
    .my-template {
        background-color: #eee;
        padding: 5px;
        display: flex;
        flex-direction: column;
        align-items: start;

# Display simple HTML

# Display objects
buche([x * x for x in range(100)])
buche.dict(avocado="green", banana="yellow", cherry="red")

# Open automatically creates an address for an element
div1 ="border: 3px solid red")

# You can also set an address explicitly
buche.html.div(address='/two', style="border: 3px solid blue")

# Get a printer for the given address
div2 = buche['/two']

# These objects will go in the divs
div1('One again')

# Handy tabs component
grocery_list =
fruit =
vegetable =



# Customize the representation of a class
class Color:
    def __init__(self, r, g, b):
        self.r = r
        self.g = g
        self.b = b

    def __hrepr__(self, H, hrepr):
        sz = hrepr.config.swatch_size or 20
        return H.div(

# This will call __hrepr__
buche(Color(255, 0, 0))

# Configuration values can be anything and are propagated recursively
buche(Color(0, 0, 255), swatch_size=50)

# You can evaluate JavaScript on elements
button ="Tickle me")
button.command_eval(expression="this.onclick = () => alert('Hihihihi!')")


You can start an interactive evaluator very easily:

from buche import repl

Run buche python3 and you will get an empty window and an input box at the bottom. You can evaluate Python expressions in the input box and get very pretty output, and you can also click on the representations of the objects in order to put them in temporary variables.

Note: start is non-blocking. For a blocking version you can do this:

from buche import repl
repl.query()  # Processes a single command, blocking


By setting the environment variable PYTHONBREAKPOINT to buche.breakpoint, calls to the builtin breakpoint() will use Buche’s repl for debugging. You can use it essentially the same way as pdb, but you get pretty HTML printing.

PYTHONBREAKPOINT=buche.breakpoint buche python3

This variable is automatically set when you run a script with python -m buche.

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 buche, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size buche-0.2.0-py3-none-any.whl (15.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size buche-0.2.0.tar.gz (16.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page