Attribute Macro pyo3_macros::pyclass[][src]

#[pyclass]
Expand description

A proc macro used to expose Rust structs 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.
gcParticipate in Python’s garbage collection. Required if your type contains references to other Python objects. If you don’t (or incorrectly) implement this, contained Python objects may be hidden from Python’s garbage collector and you may leak memory. Note that leaking memory, while undesirable, is safe behavior.
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.
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.