Attribute Macro pyo3_macros::pymodule

source ·
#[pymodule]
Expand description

A proc macro used to implement Python modules.

The name of the module will be taken from the function name, unless #[pyo3(name = "my_name")] is also annotated on the function to override the name. Important: the module name should match the lib.name setting in Cargo.toml, so that Python is able to import the module without needing a custom import loader.

Functions annotated with #[pymodule] can also be annotated with the following:

AnnotationDescription
#[pyo3(name = "...")]Defines the name of the module in Python.

For more on creating Python modules see the module section of the guide.

Due to technical limitations on how #[pymodule] is implemented, a function marked #[pymodule] cannot have a module with the same name in the same scope. (The #[pymodule] implementation generates a hidden module with the same name containing metadata about the module, which is used by wrap_pymodule!).