python/README.md
[!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:
python/ directory is self-contained. Everything Python-related for v2 lives here.nautilus_trader/ goes away).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 intarget/. 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
rustup)patchelf (Linux only) for setting rpath on the compiled extensionFrom within this python/ directory:
uv run maturin develop --extras dev,test
This compiles the Rust extension and installs it into the project venv (python/.venv).
Run again after Rust changes.
maturin develop compiles all Rust code into a single extension module
under nautilus_trader/_libnautilus/.__init__.py re-exports components from _libnautilus..pyi files provide type information for IDEs and mypy.generate_docstrings.py copies /// 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,test
CI 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 tests
Use 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-v2
This runs generate_docstrings.py first to copy doc comments from Rust source to PyO3
wrappers, then generates the .pyi stub files.