Package: buche
Helper package to pretty-print and interact with Python objects using theBuchelogger.The package includes a repl and a debugger.Requires Python >= 3.6UsageYou must installBuchefirst, either from thereleaseor through npm (npm install-gbuche). This package helps interact with Buche, but it is not the application itself. Once you have written your script, use it as follows:python-mbucheyourscript.pyAlternatively, usingbuchedirectly:buchepython-uyourscript.pyDisplayHere’s an example of what you can do with Buche. You can run this code usingbuche python3 examples/demo.py.frombucheimportbuche,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=...`buche.command_template(content=H.div['my-template'](address="/"))# Use this command to add styles, stylesheets, scripts, etc.buche.command_resource(content=H.style("""
    .my-template {
        background-color: #eee;
        padding: 5px;
        display: flex;
        flex-direction: column;
        align-items: start;
    }
    """))# Display simple HTMLbuche.html.h3('Welcome!')# Display objectsbuche(1234)buche([x*xforxinrange(100)])buche.dict(avocado="green",banana="yellow",cherry="red")# Open automatically creates an address for an elementdiv1=buche.open.div(style="border: 3px solid red")# You can also set an address explicitlybuche.html.div(address='/two',style="border: 3px solid blue")# Get a printer for the given addressdiv2=buche['/two']# These objects will go in the divsdiv1('One')div2('Two')div1('One again')# Handy tabs componentgrocery_list=buche.open.boxTabs()fruit=grocery_list.open.tabEntry(label='Fruits',active=True,)vegetable=grocery_list.open.tabEntry(label='Veggies',)fruit.html.div(H.s("Pineapple"))fruit.html.div("Raspberry")fruit.html.div("Grape")vegetable.html.div("Carrot")vegetable.html.div("Potato")vegetable.html.div("Yam")# Customize the representation of a classclassColor:def__init__(self,r,g,b):self.r=rself.g=gself.b=bdef__hrepr__(self,H,hrepr):sz=hrepr.config.swatch_sizeor20returnH.div(style=f'display:inline-block;width:{sz}px;height:{sz}px;margin:2px;'f'background-color:rgb({self.r},{self.g},{self.b});')# This will call __hrepr__buche(Color(255,0,0))# Configuration values can be anything and are propagated recursivelybuche(Color(0,0,255),swatch_size=50)# You can evaluate JavaScript on elementsbutton=buche.open.button("Tickle me")button.command_eval(expression="this.onclick = () => alert('Hihihihi!')")ReplYou can start an interactive evaluator very easily:# repl.pyfrombucheimportreplrepl.start()Runbuche python3 repl.pyand 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:startis non-blocking. For a blocking version you can do this:frombucheimportreplrepl.start(synchronous=True)repl.query()# Processes a single command, blockingDebuggerBy setting the environment variablePYTHONBREAKPOINTtobuche.breakpoint, calls to the builtinbreakpoint()will use Buche’s repl for debugging. You can use it essentially the same way aspdb, but you get pretty HTML printing.PYTHONBREAKPOINT=buche.breakpointbuchepython3mycode.pyThis variable is automatically set when you run a script withpython-mbuche.