pyccolo
Declarative instrumentation for Python
What it is and what it does
Pyccolo is a metaprogramming library that instruments Python code by rewriting its abstract syntax tree to emit fine-grained events—over 100 event types covering statements, attribute access, operators, assignments, literals, calls, and returns. Instead of manually patching bytecode or writing ast.NodeTransformer classes, you subclass BaseTracer, decorate handler methods with event decorators like @pyc.before_stmt or @pyc.after_assign_rhs, and register them to observe or modify behavior. Handlers receive the instrumented value, AST node, stack frame, and event object, and can override the value that flows out of an expression by returning a replacement.
The library is designed to be ergonomic, composable, and portable. Multiple independently-written tracers can be nested in context managers and their handlers compose automatically without manual conflict resolution. Because instrumentation is embedded at the source level rather than bytecode, the same code runs across Python 3.6 through 3.14. It powers production tools like ipyflow (a reactive Jupyter kernel), pipescript (pipe operators and macros for IPython), and pycograd (automatic differentiation for plain numpy code), and has been used to build code coverage, syntactic macros, optional chaining, lazy imports, and concolic execution tools.
Use it for:
- Build a reactive notebook kernel that tracks dataflow between cells by instrumenting variable assignments and attribute access.
- Implement statement-level code coverage by registering a handler on before_stmt to log which lines execute.
- Add syntax extensions like pipe operators or optional chaining by defining an AugmentationSpec and attaching handlers to the resulting AST nodes.
- Trace computation graphs for automatic differentiation by intercepting operations on ordinary numpy arrays without requiring a special namespace.
- Instrument imports to implement lazy loading or concolic execution by hooking module load events.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pyccolo is a library for declarative instrumentation in Python that rewrites source code with event-emitting AST transformations, letting you specify what instrumentation to perform and handling the implementation details automatically.
Yes, with conditions. Pyccolo is actively maintained, has no known vulnerabilities, and installs with minimal friction. It is genuinely useful for building observability and syntax-augmentation tools that would otherwise require manual bytecode patching or complex AST visitor logic. However, it is classified as Alpha, so production use should account for potential API changes. Start with it if you need composable, source-level instrumentation; avoid it if you need guaranteed stability or are looking for a simple logging library.
Install
pyccolo on PyPI
pip
pip install pyccolouv
uv add pyccolopoetry
poetry add pyccoloInstalling pyccolo
Before you install
Low friction: pure Python wheel with only two lightweight runtime dependencies (traitlets and typing_extensions). Active maintenance with a recent release 34 days ago and ongoing repository activity.
License in practice
BSD-3-Clause is permissive; you can use, modify, and distribute Pyccolo with minimal restrictions, provided you include the license notice.
Quickstart
pip install pyccolo
import pyccolo as pyc
class HelloTracer(pyc.BaseTracer):
@pyc.before_stmt
def handle_stmt(self, *_, **__):
print("Hello, world!")
with HelloTracer:
pyc.exec("for _ in range(10): pass")
Code to be instrumented must be passed to pyc.exec() or imported inside a tracing context; source code at module level where the tracer class is defined will not be instrumented unless quoted.
Verify before relying
- Performance overhead of AST transformation and event emission at runtime compared to uninstrumented code.
- Compatibility edge cases or limitations across the stated Python 3.6–3.14 range beyond the general claim of portability.
- Maturity and stability guarantees given the Alpha development status classification.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — traitlets, typing_extensions |
| Maintenance | actively maintained — 34 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 222,978/month — #9,254 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyccolo-0.0.94-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
google-pastaParse Python source code into an AST, modify…
permissive · top 1,000 on PyPI
ipyflow-coreA reactive Python kernel for Jupyter that…
permissive · top 15,000 on PyPI
aiocopDetects and logs blocking I/O and CPU calls in…
permissive · top 15,000 on PyPI
pycnitePycnite provides pure Python parsers for Python…
permissive · top 5,000 on PyPI
dncildncil is a Python library for disassembling…
permissive · top 15,000 on PyPI
diastatic-maltDiastaticMalt performs source-to-source…
permissive · top 15,000 on PyPI
llama-index-instrumentationProvides instrumentation hooks for…
permissive · top 5,000 on PyPI
ast-grep-pyast-grep-py is a Python binding for ast-grep, a…
permissive · top 5,000 on PyPI
RxRxPY provides a library for composing…
permissive · top 5,000 on PyPI
logfuryLogfury adds automatic method-call tracing to…
permissive · top 15,000 on PyPI