Skip to main content

Module pymodule

Module pymodule 

Source
Expand description

Implementation details of #[pymodule] which need to be accessible from proc-macro generated code.

Re-exportsΒ§

use core::cell::UnsafeCell; πŸ”’
use core::ffi::CStr; πŸ”’
use core::ffi::c_int; πŸ”’
use core::ffi::c_void; πŸ”’
use core::marker::PhantomData; πŸ”’
use core::sync::atomic::Ordering; πŸ”’ Neither GraalPy nor PyPy and not (Py_LIMITED_API and Windows and non-Py_3_10)
use core::sync::atomic::AtomicI64; πŸ”’ target_has_atomic=64 and neither GraalPy nor PyPy and not (Py_LIMITED_API and Windows and non-Py_3_10)
use crate::exceptions::PyImportError; πŸ”’ Neither GraalPy nor PyPy
use crate::ffi_ptr_ext::FfiPtrExt; πŸ”’
use crate::internal_tricks::array_ptr_as_mut; πŸ”’ Py_3_15 or not (Py_GIL_DISABLED and Py_LIMITED_API)
use crate::prelude::PyTypeMethods; πŸ”’
use crate::Bound; πŸ”’
use crate::PyClass; πŸ”’
use crate::PyErr; πŸ”’
use crate::PyResult; πŸ”’
use crate::PyTypeInfo; πŸ”’
use crate::ffi; πŸ”’
use crate::impl_::pyfunction::PyFunctionDef; πŸ”’
use crate::types::PyModule; πŸ”’
use crate::types::PyModuleMethods; πŸ”’
use crate::Py; πŸ”’
use crate::PyAny; πŸ”’
use crate::Python; πŸ”’
use crate::sync::PyOnceLock; πŸ”’
use crate::types::PyDict; πŸ”’
use crate::types::any::PyAnyMethods; πŸ”’
use crate::types::dict::PyDictMethods; πŸ”’
use crate::err; πŸ”’
use crate::py_result_ext::PyResultExt; πŸ”’
use crate::platform::prelude::*; πŸ”’

StructsΒ§

AddClassToModule
For adding a class to a module.
AddTypeToModule
For adding native types (non-pyclass) to a module.
ModuleDef
Sync wrapper of ffi::PyModuleDef.
PyModuleDefSlotsNot (Py_GIL_DISABLED and Py_LIMITED_API)
Slots to populate a PyModuleDef Cannot create a PyModuleDef on abi3t due to lack of knowledge of object layout
PyModuleSlots
Wrapper to safely store module slots, to be used in a ModuleDef.
PyModuleSlotsBuilder
Builder to create module slots. The size of the number of slots desired must be known up front, and N needs to be at least one greater than the number of actual slots pushed due to the need to have a zeroed element on the end.

ConstantsΒ§

MAX_SLOTS πŸ”’
MAX_SLOTS_WITH_TRAILING_NULL πŸ”’

TraitsΒ§

PyAddToModule
Trait to add an element (class, function…) to a module.
PyModuleInitResult
Used to accept either () or Result<(), E> from a #[pymodule_init] function.

FunctionsΒ§

secondary_slots

Type AliasesΒ§

ModuleExecSlot
Type of the exec slot used to initialise module contents
PrimaryModuleSlotsNon-Py_3_15
On Python 3.14 and older the primary system is ffi::PyModuleDef.
SecondaryModuleSlotsNot (Py_3_15 and not (Py_GIL_DISABLED and Py_LIMITED_API))
⚠️ Internal Docs ⚠️ Not Public API πŸ‘‰ Official Docs Here