pyo3-nest
A clean and ergonomic macro DSL for creating deeply nested submodules in PyO3 with excellent developer experience.
Say goodbye to repetitive PyModule::new + add_submodule boilerplate with zero runtime overhead!
Installation
Add this to your Cargo.toml:
[]
= { = "0.28", = ["extension-module"] }
= "0.1"
Or use cargo:
Usage
Basic Example
use *;
use ;
;
;
Python Usage
After building with maturin, users can import cleanly:
Why?
Before pyo3-nest:
let routing = new?;
routing.?;
routing.?;
m.add_submodule?;
// ... and every now and then for every level + sys.modules management
After pyo3-nest:
submodule!;
Much cleaner, safer, and maintainable, especially as your project grows with many nested modules.
Supported Patterns
submodule!(m, "foo", add_classes!(A, B))submodule!(m, "foo", add_functions!(fn1, fn2))submodule!(m, "foo", add_classes!(A, B) && add_functions!(fn1))submodule!(m, "foo", add_functions!(fn1) && add_classes!(A, B))- Multiple calls to the same path are safe
Requirements
- Rust 1.70+
- PyO3 0.22+
License
Licensed under MIT License
Contributing
Contributions and feedback are welcome! Feel free to open issues or PRs.