Developer documentation, architecture details, and contribution guidelines.
- Rust 1.83+ —
rustup update stable - Python 3.10+
- maturin —
pip install maturin - pytest + pytest-asyncio —
pip install pytest pytest-asyncio
git clone https://github.com/AllDotPy/Ryx
cd Ryx
maturin develop # compile Rust workspace + install in dev mode# Rust unit tests (across all workspace crates)
cargo test
# Python unit tests
python test.py
# Integration tests (SQLite)
python test.py --integration
# All tests
python test.py --allTo measure the performance of the query compiler:
cargo bench -p ryx-querymypy ryx/Ryx uses a Rust Workspace to isolate core logic, backend implementations, and Python bindings.
Ryx/
├── Cargo.toml # Workspace configuration
├── pyproject.toml # maturin build config
├── Makefile # dev shortcuts
│
├── ryx-core/ # CORE TYPES & TRAITS
│ └── src/ # Connection/Transaction enums, Base types
│
├── ryx-backend/ # DATABASE ADAPTERS
│ └── src/ # Executor implementations, Row decoding
│
├── ryx-query/ # SQL COMPILER
│ └── src/ # AST, Compiler, Lookup registry
│
├── ryx-python/ # PyO3 BINDINGS
│ └── src/ # Module entry, Type bridges, Bound object handling
│
├── ryx/ # PYTHON PACKAGE
│ ├── __init__.py # Public API surface
│ ├── models.py # Model, Metaclass, Manager
│ ├── queryset.py # Lazy QuerySet implementation
│ ├── fields.py # Field types and validators
│ └── ... (other python modules)
│
├── tests/ # Test suites
└── examples/ # Usage examples
Ryx is designed for extreme performance, targeting 1-2 $\mu$s overhead for query construction and row decoding.
- Enum Dispatch: We avoid
dyntraits and vtable lookups in the hot path.RyxConnectionandRyxTransactionare enums that allow the compiler to inline backend-specific logic. - Zero-Allocation Rows: Instead of creating a
HashMapfor every database row, we useRowViewandRowMapping. A single mapping is shared across all rows in a result set, and values are accessed via index. - GIL Minimization: Data is decoded into optimized Rust structures before being converted to Python objects at the very last moment, minimizing the time the GIL is held.
Python: Post.objects.filter(active=True).limit(10)
│
▼
QuerySet → PyQueryBuilder (ryx-python)
│
▼
compiler::compile (ryx-query) → CompiledQuery { sql, values }
│
▼
executor::fetch_all (ryx-backend) → sqlx::query(sql).fetch_all(pool)
│
▼
decode_rows (ryx-backend) → Vec<RowView> (Zero-allocation)
│
▼
RowView → PyDict (ryx-python)
│
▼
Model._from_row(row) → Model instances
- No Dynamic Dispatch: Avoid
Box<dyn Trait>in hot paths. Use enums or generics. - PyO3 0.28.3: Always use
Bound<'py, T>for Python objects. Usecast::<_>()for type conversions. - Immutability:
QuerySetandQueryNodemust remain immutable. Methods should return new instances. - Documentation: Every public Rust item must have a doc comment. Python signatures must have full type hints.
- English Only: All code and comments must be in English.