branchy
Live, hierarchical console process trees for Python, with zero dependencies.
Visual sample
A successful run collapses to a calm, depth-styled tree:
✓ Deploy
✓ Validate
✓ Build
✓ Compile
✓ Link
A failed run keeps the transient logs visible:
✗ Publish
starting upload
✗ Sign package
private key not found
Installation
pip install branchy
Quick start
from branchy import process
import time
with process("Build") as build:
with build.child("Compile") as c:
c.log("gcc main.c")
time.sleep(0.5)
with build.child("Link") as l:
l.log("ld -o app")
time.sleep(0.3)
API usage
process(label) starts a root context. Inside the body:
p.log(message)appends transient output under the current node.p.child(label)creates a nested process.p.rename(new_label)retitles the running node — works on the root and on every child.p.input(prompt)waits for one line of typed text: live rendering pauses, the cursor appears, and the prompt is written below the tree. Returns the text without its line ending. Works on the root and on every child. Prompts and answers are not logged automatically, and input is not masked.show_elapsed=True(onprocessorchild, off by default) shows that node's elapsed time: whole seconds while running, frozen at one-decimal precision once the node is done or failed.- Clean exit marks the node done and clears its transient logs.
- Exception exit marks the node failed, keeps the logs, appends the exception message, and re-raises the exception.
Both process and child are context managers.
Output lifecycle
Logs are temporary detail. They disappear once a branch succeeds, but remain visible on failure so the reason can be seen.
During a running branch:
⠋ Build
compiling…
⠙ Compile
gcc main.c
After success:
✓ Build
✓ Compile
After failure:
✗ Build
compiling…
✗ Compile
gcc main.c
error: implicit declaration
A mid-run rename swaps the title in place, with no flash or recolor:
⠋ Compiling deps…
The next frame simply carries the new name:
⠙ Building wheels…
The rename shows in the live view and in the final output. Renaming a finished node is a no-op — finalized rows are immutable — and a longer label re-truncates with ... at the terminal width.
Interactive input
p.input(prompt) blocks for one line of typed text. While it waits, the live spinner freezes, the cursor becomes visible, and the prompt appears at column 0 below the tree:
from branchy import process
with process("Deploy") as deploy:
target = deploy.input("Target environment [production]: ") or "production"
deploy.rename(f"Deploy to {target}")
with deploy.child("Credentials") as creds:
user = creds.input("Deploy user: ")
creds.rename(f"Credentials for {user}")
The returned text excludes its line ending; EOFError is raised at end of input. The prompt is written verbatim, unstyled and untruncated, and is never added to transient logs — the answer is not persisted either. Call p.log(...) yourself when the request matters for failure output. Input is not masked, so do not use it for secrets.
On a live TTY the interaction is temporary: after Enter, EOF, or Ctrl-C, one clean redraw clears the prompt and the echoed answer, and the tree continues with the cursor hidden again. The wait still counts toward elapsed time, so the visible timer catches up after resume.
Static output (non-TTY, TERM=dumb) has no animation to pause and emits no cursor control. The prompt is written once followed by exactly one newline, so sequential prompts and the final tree each start on their own line. A static TTY may echo the answer; redirected output contains only the prompt line. On EOF or Ctrl-C the exception propagates, the prompt is cleared, and the failure tree shows only what you logged before prompting.
Elapsed time
Pass show_elapsed=True to process or child to time that one node — the flag is per node, off by default, and never inherited from the parent. While the node runs, the suffix ticks in whole seconds; when it completes or fails, the duration freezes at one-decimal precision (minute form from 60 s):
from branchy import process
import time
with process("Build", show_elapsed=True) as build:
with build.child("Compile") as c: # untimed node
time.sleep(0.4)
with build.child("Link", show_elapsed=True) as l:
time.sleep(1.1)
While a timed node runs:
⠙ Build (3s)
⠋ Compile
gcc main.c
After failure, the frozen duration stays visible in the final tree:
✗ Publish (4.1s)
starting upload
✗ Sign package
private key not found
On a non-TTY (CI) there are no live frames; the timer appears once, frozen, in the static output:
✓ Build (3.2s)
✓ Compile
✓ Link (1.1s)
Environment / behavior
| Variable / condition | Effect |
|---|---|
NO_COLOR set |
No color styling; cursor movement still works in a TTY. |
TERM=dumb |
Plain ASCII output, no ANSI cursor control. |
| stdout not a TTY | Static output; no animation; transient logs are not erased. |
COLUMNS |
Fallback terminal width when it cannot be queried from the OS. |
Examples
Nested success tree
from branchy import process
import time
with process("Deploy") as deploy:
with deploy.child("Validate") as v:
v.log("schema ok")
time.sleep(0.2)
with deploy.child("Build") as b:
with b.child("Compile") as c:
c.log("gcc -O2 main.c")
time.sleep(0.3)
with b.child("Link") as l:
l.log("ld -o app")
time.sleep(0.3)
Failure handling
from branchy import process
try:
with process("Publish") as p:
p.log("starting upload")
with p.child("Sign package") as s:
s.log("private key not found")
raise RuntimeError("signing failed")
except RuntimeError as exc:
print(f"Expected failure captured: {exc}")
Limitations
- Designed for small trees; rendering is
O(number of live rows)per frame. - Wide-character widths are best-effort via Unicode East Asian Width and combining-mark handling.
- With
show_elapsed=Trueon a very narrow terminal the label budget can reach zero, leaving only the glyph and the timer suffix. - Elapsed minute form (
(XmYYs)) grows unboundedly for runtimes of an hour or more; a right-aligned timer column is a possible future enhancement. - The library intentionally does not persist logs, show progress percentages, or provide pluggable themes.
Metadata
Release files for branchy 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| branchy-1.2.0.tar.gz | 12.8 kB | Without provenance | Details for branchy-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| branchy-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for branchy-1.2.0-py3-none-any.whl |
Total release size: 24.5 kB
Release files / branchy-1.2.0.tar.gz
| Download URL | branchy-1.2.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a777e7c0c2e2766b4149cdd04c1e5aab2bf6886c0ff8ca30a5333c0c633156f
|
|
BLAKE2b-256 checksum How to use checksums |
4c5540acc0edbe754c37880ddc04804afc8c1dc72005675dd04070739c866c0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / branchy-1.2.0-py3-none-any.whl
| Download URL | branchy-1.2.0-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67e2500e701ce83e30e69843036bea9f4f6b8e58d3a0093e246a0b7a2aa87390
|
|
BLAKE2b-256 checksum How to use checksums |
667aecb38dfb9f93a6d074c000ed7a8d2e3efa4b3c11f94803d413394ca5539f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for branchy 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.