Attribute Macro pyo3::pyclass

source · []
#[pyclass]
This is supported on crate feature macros only.
Expand description

A proc macro used to expose Rust structs and fieldless enums as Python objects.

#[pyclass] accepts the following parameters:

ParameterDescription
name = "python_name"Sets the name that Python sees this class as. Defaults to the name of the Rust struct.
freelist = NImplements a free list of size N. This can improve performance for types that are often created and deleted in quick succession. Profile your code to see whether freelist is right for you.
weakrefAllows this class to be weakly referenceable.
extends = BaseTypeUse a custom baseclass. Defaults to PyAny
subclassAllows other Python classes and #[pyclass] to inherit from this class. Enums cannot be subclassed.
unsendableRequired if your struct is not Send. Rather than using unsendable, consider implementing your struct in a threadsafe way by e.g. substituting Rc with Arc. By using unsendable, your class will panic when accessed by another thread.
module = "module_name"Python code will see the class as being defined in this module. Defaults to builtins.

For more on creating Python classes, see the class section of the guide.