Module pyo3::ffi

source ·
Expand description

Raw FFI declarations for Python’s C API.

This module provides low level bindings to the Python interpreter. It is meant for advanced users only - regular PyO3 users shouldn’t need to interact with this module at all.

The contents of this module are not documented here, as it would entail basically copying the documentation from CPython. Consult the Python/C API Reference Manual for up-to-date documentation.

Safety

The functions in this module lack individual safety documentation, but generally the following apply:

  • Pointer arguments have to point to a valid Python object of the correct type, although null pointers are sometimes valid input.
  • The vast majority can only be used safely while the GIL is held.
  • Some functions have additional safety requirements, consult the Python/C API Reference Manual for more information.

Modules

Structs

PyByteArrayObjectNeither PyPy nor Py_LIMITED_API
PyBytesObjectNeither PyPy nor Py_LIMITED_API
PyCFunctionObjectPy_3_9 and non-Py_LIMITED_API
PyCodeObjectNon-PyPy and Py_3_8 and non-Py_3_11
Structure representing a datetime.date
Structure representing a datetime.datetime.
Structure representing a datetime.timedelta.
Structure representing a datetime.time.
PyFloatObjectNon-Py_LIMITED_API
PyFrameObjectNeither PyPy nor Py_3_11
PyFunctionObjectNon-PyPy and Py_3_10
PyGenObjectNon-PyPy
PyHash_FuncDefNeither Py_LIMITED_API nor PyPy
PyListObjectNon-PyPy
PyObjectArenaAllocatorNeither Py_LIMITED_API nor PyPy
PySetObjectNeither Py_LIMITED_API nor PyPy
PySliceObjectNon-Py_LIMITED_API
PyTryBlockNeither PyPy nor Py_3_11
Structure representing a datetime.datetime without a tzinfo member.
Structure representing a datetime.time without a tzinfo member.
_frozenNon-PyPy
_inittabNon-PyPy
setentryNeither Py_LIMITED_API nor PyPy

Enums

Constants

METH_FASTCALLPy_3_10 or non-Py_LIMITED_API
METH_METHODPy_3_9 and non-Py_LIMITED_API
Maximum number of dimensions
PyUnicode_WCHAR_KINDDeprecatedNon-Py_3_12
Set if the type allows subclassing
Objects support garbage collection (see objimp.h)
Py_TPFLAGS_HAVE_VECTORCALLPy_3_8 and non-Py_LIMITED_API
Set if the type implements the vectorcall protocol (PEP 590)
This flag does nothing in Python 3.10+
Set if the type object is dynamically allocated
Py_TPFLAGS_MAPPINGPy_3_10 and non-Py_LIMITED_API
Set if the type is ‘ready’ – fully initialized
Set while the type is being ‘readied’, to prevent recursive ready calls
Py_TPFLAGS_SEQUENCEPy_3_10 and non-Py_LIMITED_API

Statics

built-in ‘object’
PyFunction_TypeNot (PyPy and non-Py_3_8)
built-in ‘super’
built-in ‘type’
_PyManagedBuffer_TypeNon-Py_LIMITED_API

Functions

PyCFunction_CallDeprecated
PyCode_CheckNon-PyPy
PyCode_GetNumFreeNon-PyPy and Py_3_10 and non-Py_3_11
PyCodec_UnregisterPy_3_10 and non-PyPy
Returns a pointer to a PyDateTime_CAPI instance
Check if op is a PyDateTimeAPI.DateTimeType or subtype.
Check if op’s type is exactly PyDateTimeAPI.DateTimeType.
Retrieve the fold component of a PyDateTime_DateTime. Returns a signed integer in the interval [0, 1]
Retrieve the hour component of a PyDateTime_DateTime. Returns a signed integer in the interval [0, 23]
Retrieve the microsecond component of a PyDateTime_DateTime. Returns a signed integer in the interval [0, 999999]
Retrieve the minute component of a PyDateTime_DateTime. Returns a signed integer in the interval [0, 59]
Retrieve the second component of a PyDateTime_DateTime. Returns a signed integer in the interval [0, 59]
Retrieve the tzinfo component of a PyDateTime_DateTime. Returns a pointer to a PyObject that should be either NULL or an instance of a datetime.tzinfo subclass.
Retrieve the days component of a PyDateTime_Delta.
Retrieve the seconds component of a PyDateTime_Delta.
Retrieve the seconds component of a PyDateTime_Delta.
Retrieve the day component of a PyDateTime_Date or PyDateTime_DateTime. Returns a signed integer in the interval [1, 31].
Retrieve the month component of a PyDateTime_Date or PyDateTime_DateTime. Returns a signed integer in the range [1, 12].
Retrieve the year component of a PyDateTime_Date or PyDateTime_DateTime. Returns a signed integer greater than 0.
Populates the PyDateTimeAPI object
Retrieve the fold component of a PyDateTime_Time. Returns a signed integer in the interval [0, 1]
Retrieve the hour component of a PyDateTime_Time. Returns a signed integer in the interval [0, 23]
Retrieve the microsecond component of a PyDateTime_DateTime. Returns a signed integer in the interval [0, 999999]
Retrieve the minute component of a PyDateTime_Time. Returns a signed integer in the interval [0, 59]
Retrieve the second component of a PyDateTime_DateTime. Returns a signed integer in the interval [0, 59]
Retrieve the tzinfo component of a PyDateTime_Time. Returns a pointer to a PyObject that should be either NULL or an instance of a datetime.tzinfo subclass.
Type Check macros
Check if op’s type is exactly PyDateTimeAPI.DateType.
Check if op is a PyDateTimeAPI.DetaType or subtype.
Check if op’s type is exactly PyDateTimeAPI.DeltaType.
PyEval_CallFunctionDeprecated
PyEval_CallMethodDeprecated
PyEval_CallObjectDeprecated
PyFloat_AS_DOUBLENon-Py_LIMITED_API
PyFrame_BlockPopNeither PyPy nor Py_3_11
PyFrame_GetCodePy_3_10, or Py_3_9 and non-Py_LIMITED_API
PyFunction_CheckNot (PyPy and non-Py_3_8)
PyGC_DisablePy_3_10
PyGC_EnablePy_3_10
PyGC_IsEnabledPy_3_10
PyHash_GetFuncDefNeither Py_LIMITED_API nor PyPy
PyIndex_CheckNeither Py_LIMITED_API nor PyPy
PyInterpreterState_GetPy_3_9 and non-PyPy
PyInterpreterState_GetDictPy_3_8 and non-PyPy
PyIter_CheckPy_3_8 or PyPy
PyIter_SendNon-PyPy and Py_3_10
PyList_GET_ITEMNon-PyPy
Macro, trading safety for speed
PyList_GET_SIZENon-PyPy
PyList_SET_ITEMNon-PyPy
Macro, only to be used to fill in brand new lists
PyMapping_LengthNon-PyPy
PyModule_AddTypePy_3_10, or Py_3_9 and non-Py_LIMITED_API
PyModule_Create2Non-py_sys_config="Py_TRACE_REFS"
PyModule_FromDefAndSpec2Non-py_sys_config="Py_TRACE_REFS"
PyModule_GetFilenameDeprecatedNot (Windows and PyPy)
PyOS_AfterForkDeprecated
PyObject_CallMethodNoArgsPy_3_9 and non-PyPy
PyObject_CallMethodOneArgPy_3_9 and non-PyPy
PyObject_CallNoArgsNon-PyPy and (Py_3_10, or non-Py_LIMITED_API and Py_3_9)
PyObject_CallOneArgPy_3_8 and non-PyPy
PyObject_CheckBufferPy_3_9 and non-PyPy and non-Py_3_11
PyObject_GET_WEAKREFS_LISTPTRNon-Py_LIMITED_API
PyObject_GenericGetDictNot (Py_LIMITED_API and non-Py_3_10)
PyObject_GetArenaAllocatorNeither Py_LIMITED_API nor PyPy
PyObject_IS_GCNon-Py_LIMITED_API
Test if an object has a GC head
PyObject_SetArenaAllocatorNeither Py_LIMITED_API nor PyPy
PyObject_VectorcallPy_3_8 and non-PyPy
PyObject_VectorcallMethodPy_3_9 and non-PyPy
PyRun_AnyFileNon-PyPy
PyRun_AnyFileExNon-PyPy
PyRun_FileExNon-PyPy
PyRun_FileFlagsNon-PyPy
PyRun_SimpleFileNon-PyPy
PySet_CheckNon-PyPy
PySet_GET_SIZENon-PyPy and non-Py_LIMITED_API
PyStructSequence_GET_ITEMNeither Py_LIMITED_API nor PyPy
PyStructSequence_InitTypeNon-Py_LIMITED_API
PyStructSequence_InitType2Non-Py_LIMITED_API
PyStructSequence_SET_ITEMNeither Py_LIMITED_API nor PyPy
Check if op is a PyDateTimeAPI.TZInfoType or subtype.
Check if op’s type is exactly PyDateTimeAPI.TZInfoType.
Check if op is a PyDateTimeAPI.TimeType or subtype.
Check if op’s type is exactly PyDateTimeAPI.TimeType.
PyTuple_GET_ITEMNon-PyPy
PyTuple_GET_SIZENon-PyPy
Macro, trading safety for speed
PyTuple_SET_ITEMNon-PyPy
Macro, only to be used to fill in brand new tuples
PyType_FromModuleAndSpecPy_3_10, or Py_3_9 and non-Py_LIMITED_API
PyType_GetModulePy_3_10, or Py_3_9 and non-Py_LIMITED_API
PyType_GetModuleStatePy_3_10, or Py_3_9 and non-Py_LIMITED_API
PyType_HasFeatureNon-Py_LIMITED_API
Test if a type has a GC head
PyType_SUPPORTS_WEAKREFSNon-Py_LIMITED_API
Test if a type supports weak references
PyUnicode_1BYTE_DATALittle-endian
PyUnicode_2BYTE_DATALittle-endian
PyUnicode_4BYTE_DATALittle-endian
PyUnicode_AsUTF8AndSizePy_3_10 or non-Py_LIMITED_API
PyUnicode_AsUnicodeDeprecatedNon-Py_3_12
PyUnicode_AsUnicodeAndSizeDeprecatedNon-Py_3_12
PyUnicode_CheckNon-PyPy
PyUnicode_DATALittle-endian
PyUnicode_FillNon-PyPy
PyUnicode_FromUnicodeDeprecatedNon-Py_3_12
PyUnicode_GET_LENGTHLittle-endian
PyUnicode_IS_ASCIILittle-endian
PyUnicode_IS_COMPACTLittle-endian
PyUnicode_IS_READYLittle-endian
PyUnicode_KINDLittle-endian
PyUnicode_READYDeprecatedNon-Py_3_12 and little-endian
PyVectorcall_FunctionPy_3_8 and non-PyPy
Py_CompileStringObjectNon-Py_LIMITED_API
Py_NewRefPy_3_10
Py_XNewRefPy_3_10
Get the frame evaluation function.
Set the frame evaluation function.
_PyObject_CallNoArgPy_3_8 and non-PyPy
_PyObject_FastCallPy_3_8 and non-PyPy
_PyObject_FastCallTstatePy_3_8 and non-PyPy
_PyObject_GC_CallocNon-Py_LIMITED_API
_PyObject_GC_MallocNon-Py_LIMITED_API
_PyObject_MakeTpCallPy_3_8 and non-PyPy
_PyObject_VectorcallTstatePy_3_8 and non-PyPy
_PySet_NextEntryNon-Py_LIMITED_API
_PyStack_AsDictPy_3_8 and non-PyPy
_PyUnicode_COMPACT_DATALittle-endian
_Py_CheckFunctionResultPy_3_8 and non-PyPy
_Py_GetAllocatedBlocksNon-Py_LIMITED_API
_Py_HashBytesNeither Py_LIMITED_API nor PyPy

Type Definitions

Unions

Function types used to implement Python callables.