Note
Under active development. Core trading functionality (live trading, backtesting, adapters, strategies, execution algorithms) works through PyO3 bindings. Some features from v1 are still being ported.
This directory contains the nautilus_trader v2 Python package.
v2 replaces the Cython layer with Rust core bindings exposed through PyO3.
Rules during the transition:
- The
python/directory is self-contained. Everything Python-related for v2 lives here. - This directory will remain when v1 is removed (the top-level
nautilus_trader/goes away). - Nothing outside this directory should reference anything inside it for now.
python/
├── README.md # This file
├── generate_docstrings.py # Copies Rust doc comments to PyO3 wrappers
├── generate_stubs.py # Generates Python type stubs from Rust bindings
├── pyproject.toml # Maturin build configuration
├── uv.lock # Dependency lock file
├── examples/ # Python examples using v2 bindings
├── tests/
│ ├── conftest.py # Shared pytest fixtures
│ ├── unit/
│ │ ├── common/actor.py # Test actor/strategy/algorithm fixtures
│ │ └── test_live_node.py # LiveNode registration tests
│ └── acceptance/ # Acceptance tests
└── nautilus_trader/
├── __init__.py # Re-exports from _libnautilus
├── _libnautilus/ # Compiled Rust extension (created by the build)
├── core/
│ ├── __init__.py # Re-exports from _libnautilus.core
│ └── __init__.pyi # Type stubs (auto-generated)
├── model/
│ ├── __init__.py # Re-exports from _libnautilus.model
│ └── __init__.pyi # Type stubs (auto-generated)
└── ... # Other submodules follow the same pattern
Note
The v2 build uses target-v2/ for Cargo artifacts to avoid conflicts with
the v1 build in target/. This separation is temporary until the v2
transition completes.
From the repository root:
make build-debug-v2 # Compile and install into python/.venv (debug mode)
make py-stubs-v2 # Regenerate type stubs and docstrings
make pytest-v2 # Run Python tests- Rust toolchain (via
rustup) - Python 3.12-3.14
patchelf(Linux only) for setting rpath on the compiled extension
From within this python/ directory:
uv run maturin develop --extras dev,testThis compiles the Rust extension and installs it into the project venv (python/.venv).
Run again after Rust changes.
- Build:
maturin developcompiles all Rust code into a single extension module undernautilus_trader/_libnautilus/. - Re-exports: Each submodule's
__init__.pyre-exports components from_libnautilus. - Type stubs:
.pyifiles provide type information for IDEs andmypy. - Docstrings:
generate_docstrings.pycopies///doc comments from the Rust source to PyO3 wrappers, so__doc__stays in sync without manual duplication.
from nautilus_trader.core import UUID4
UUID4()git clone https://github.com/nautechsystems/nautilus_trader.git
cd nautilus_trader/python
uv run maturin develop --extras dev,testCI publishes a wheel to the v2 index on every successful develop or nightly build.
pip install --index-url https://packages.nautechsystems.io/v2/simple/ --pre nautilus-trader| Platform | Python | Develop | Nightly |
|---|---|---|---|
Linux (x86_64) |
3.12-14 | ✓ | ✓ |
The --pre flag is required because wheels are tagged as development releases.
Tests live in tests/ and require a built extension module.
make build-debug-v2 # Build first
make pytest-v2 # Run testsUse pytest-style free functions and fixtures. Do not use test classes.
Importable test fixtures (actors, strategies, algorithms) live in tests/unit/common/actor.py.
Type stubs (.pyi files) are auto-generated using
pyo3-stub-gen. To regenerate after modifying
Rust bindings:
make py-stubs-v2This runs generate_docstrings.py first to copy doc comments from Rust source to PyO3
wrappers, then generates the .pyi stub files.