Skip to main content
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’s WORKSPACE.rbs. It downloads a standalone CPython build for your platform and registers it automatically:
Supported versions are 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 in WORKSPACE.rbs with py_repository:
To declare several packages at once, use py_repositories with package:version specs (each package gets its own target named <name>_<package>):
When a target that uses these packages is built, 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 _repo suffix; 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 your BUILD.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 with rbs run or execute it directly.

py_library

Groups source files into a reusable library that py_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 in WORKSPACE.rbs — this pre-installs pytest, coverage, pytest-cov, and pytest-xdist:
Then run tests with the standard commands:
Coverage thresholds declared on the target (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 a proto_library with python_proto_library:
The protobuf runtime (and gRPC libraries when 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.