Separate Python & Rust modules, or one repo? #3065
-
Hi! I'm finally getting around to converting a project I have to use PyO3 and amazed at how easy it is to use, so first thank you for that. Second, I'm wondering if there is a best practice for this case. My module is really just a bunch of functions that run on strings. Right now I have a separate repository for the Rust version that can be installed with cargo, and then in the Python repo, I have a dependency on that Rust package and a thin wrapper using PyO3. Is it possible to combine these into one repo so that someone can cargo install or pip install and get the appropriate version? Even if possible, is it advisable or should I leave things as they are? Thanks for any input you have! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Personally, I would recommend having both in the same repository as this makes it easier to evolve them in parallel. This does not really imply much on the code organization though as one can have multiple completely independent Rust crates and Python packages in a single Git repository by just placing them in separate folders. (When installing a crate from such a repository via I also like having the Python bindings behind a Cargo feature of the Rust crate and then possibly use a mixed project layout. There are sometimes complications due to how the PyO3 macros need to be used conditionally, but I have had good experience with just putting everything into a separate module gated behind something like |
Beta Was this translation helpful? Give feedback.
Personally, I would recommend having both in the same repository as this makes it easier to evolve them in parallel. This does not really imply much on the code organization though as one can have multiple completely independent Rust crates and Python packages in a single Git repository by just placing them in separate folders. (When installing a crate from such a repository via
cargo install
, Cargo will traverse it from the root to find the desired crate so ergonomics do not really suffer.)I also like having the Python bindings behind a Cargo feature of the Rust crate and then possibly use a mixed project layout. There are sometimes complications due to how the PyO3 macros need to be us…