Skip to content
Discussion options

You must be logged in to vote

This is really about how Python packages/modules work on top of your Rust extension. To make from my_package.module1 import sum_as_string and from my_package.module2 import greet work, structure your package like this:

my_package/
init.py
module1.py
module2.py

Each .py file just needs to expose the relevant function — sum_as_string in module1.py, greet in module2.py. The init.py (can be empty) is what makes my_package a proper Python package.

With maturin specifically, if your Rust code compiles into one extension module, you can keep this clean structure on the Python side by having each file import from your compiled Rust module internally and re-export the function. For example, module…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Khabib73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants