Package your project¶
A Detree reader needs no build step: the reader is Python source, and the installed Detree machine compiles it the first time the branch is read. A downstream project is therefore an ordinary Python package.
Project layout¶
A ready-to-use template is available in the example repository. Download the source archive, unzip, and rename the root directory to match your project name.
A Detree-only project needs three things:
my_project/
├── pyproject.toml
└── my_module/
├── __init__.py # registers the factories and target branches
├── factories.py # Factory subclasses
└── readers.py # @reader classes
Readers must live in a .py file inside an importable module: the compiler re-reads their source, so a reader defined in a notebook or a REPL is refused. Splitting readers and factories into separate modules is a convention, not a requirement.
If you later add C++ readers, the package grows a cpp/ directory and a build backend; the Python modules stay as they are.
Create a virtual environment¶
cd /path/to/your/project
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
Install in editable mode¶
pip install -e .
Python changes take effect immediately. If you have C++ sources, re-run pip install -e . to rebuild the extension module after modifying them.
Registration checklist¶
Investigate your data — inspect streamer information and binary bytes as described in Investigate your data. Pay special attention to headers, base-class layout, and any custom
Streamerlogic.Survey built-in code — review the built-in factories and readers in Uproot-custom for patterns you can reuse or subclass.
Implement — write your
Factoryand@readerclasses following Write a Detree reader.Register — obtain the object-path of the target branch and pass it to
uproot_custom.claim()before that branch’s interpretation is first computed (see get started). Registering at import time, in__init__.py, is the usual place.Select the backend — the code default is
cpp, so calluproot_custom.set_backend("detree")(or setUPROOT_CUSTOM_READER_BACKEND=detree), next to the registration.
Building a C++ reader¶
Only the C++ path needs a compiler and a build backend.
Warning
If using C++ readers, pin exact versions of Uproot-custom and pybind11 in pyproject.toml to avoid build-time incompatibilities. pybind11 is a build-only dependency — do not import it at runtime, or reader loading may fail. See Version requirements for details.
Next step
With the package in place, read a branch and check the result with the debugging loop.