pyo3

Attribute Macro pyfunction

Source
#[pyfunction]
Expand description

A proc macro used to expose Rust functions to Python.

Functions annotated with #[pyfunction] can also be annotated with the following #[pyo3] options:

AnnotationDescription
#[pyo3(name = "...")]Defines the name of the function in Python.
#[pyo3(text_signature = "...")]Defines the __text_signature__ attribute of the function in Python.
#[pyo3(pass_module)]Passes the module containing the function as a &PyModule first argument to the function.

For more on exposing functions see the function section of the guide.

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