rbs builds Python projects with a fully hermetic toolchain: it downloads a standalone
CPython interpreter, resolves your PyPI dependencies into a shared cache, and produces
runnable targets that bundle everything they need. No system Python, no virtualenvs,
no pip install steps.
Set up the toolchain
Declare the Python toolchain once in your workspace’sWORKSPACE.rbs. It downloads a
standalone CPython build for your platform and registers it automatically:
3.11, 3.12, and 3.13 (patch versions such as 3.12.7 are
accepted and normalized). Keep the toolchain name python3 — the Python rules look it
up by that name. When you cross-compile — for example building a Linux container image
from macOS — a host interpreter is also downloaded so build-time tools run natively.
Declare pip dependencies
External packages come from PyPI. Declare each one inWORKSPACE.rbs with
py_repository:
py_repositories with package:version
specs (each package gets its own target named <name>_<package>):
rbs resolves the full transitive
dependency tree from PyPI, selects the correct wheel for your platform and interpreter
version, downloads packages in parallel, and records the resolution in the workspace
lockfile (rbs.lock) so subsequent builds resolve instantly.
Reference dependencies from BUILD.rbs targets in either form:
:django_repo— the repository target you declared. Name repository targets with a_reposuffix; that suffix is what marks a label as an external package reference.@external://django:5.0.1— a direct package reference, which works regardless of how the repository target is named.
Rules
Load the rules at the top of yourBUILD.rbs:
py_binary
Builds a runnable Python application. The output is a self-contained launcher that bundles your sources, all resolved dependencies, and the hermetic interpreter — run it withrbs run or execute it directly.
py_library
Groups source files into a reusable library thatpy_binary and py_test targets can
depend on. External dependencies of a library propagate transitively to whatever
depends on it.
py_test
Defines a test target. pytest and coverage support are included automatically — you only declare the code under test:Testing
Enable the shared test dependencies once inWORKSPACE.rbs — this pre-installs
pytest, coverage, pytest-cov, and pytest-xdist:
min_line_coverage, etc.) are enforced
when you run rbs coverage — a target below its threshold fails.
Linting
py_lint runs Black and isort using the workspace’s own hermetic interpreter — no
system installs. Register the linters in WORKSPACE.rbs, then declare a lint target:
Protocol Buffers
Generate Python protobuf (and optionally gRPC) code from aproto_library with
python_proto_library:
enable_grpc = True) are added
automatically. See Other languages for the shared proto
toolchain and proto_library setup.
Editor support
Python language support in the ReasonOS editor (completions, diagnostics, go-to-definition)
is provisioned automatically when Python is detected in your workspace — there is
nothing to configure in your build files. See the editor language support documentation
for details.