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
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.
PyDictObjectNon-PyPy
PyFloatObjectNon-Py_LIMITED_API
PyFrameObjectNeither PyPy nor Py_3_11
PyFunctionObjectNon-PyPy and non-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
Maximum number of dimensions
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
Set if the type is ‘ready’ – fully initialized
Set while the type is being ‘readied’, to prevent recursive ready calls

Statics

built-in ‘object’
built-in ‘super’
built-in ‘type’
_PyManagedBuffer_TypeNon-Py_LIMITED_API

Functions

PyAST_CompileExNeither PyPy nor Py_3_10
PyAST_CompileObjectNeither PyPy nor Py_3_10
PyCFunction_CheckNon-Py_3_9
PyCode_CheckNon-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.
PyFloat_AS_DOUBLENon-Py_LIMITED_API
PyFrame_BlockPopNeither PyPy nor Py_3_11
PyFunction_CheckNon-PyPy
PyFuture_FromASTNeither PyPy nor Py_3_10
PyFuture_FromASTObjectNeither PyPy nor Py_3_10
PyGen_NeedsFinalizingDeprecatedNeither Py_3_9 nor PyPy
PyHash_GetFuncDefNeither Py_LIMITED_API nor PyPy
PyImport_CleanupDeprecatedNon-Py_3_9
PyIndex_CheckNeither Py_LIMITED_API nor PyPy
PyInterpreterState_GetDictPy_3_8 and non-PyPy
PyIter_CheckNeither Py_LIMITED_API nor PyPy
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_Create2Non-py_sys_config="Py_TRACE_REFS"
PyModule_FromDefAndSpec2Non-py_sys_config="Py_TRACE_REFS"
PyModule_GetFilenameDeprecatedNot (Windows and PyPy)
PyNode_CompileNeither PyPy nor Py_3_10
PyOS_AfterForkDeprecated
PyOS_InitInterruptsDeprecatedNon-Py_3_10
PyObject_CallOneArgPy_3_8 and non-PyPy
PyObject_CheckBufferNeither Py_3_9 nor PyPy
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
PyParser_ASTFromFileNeither PyPy nor Py_3_10
PyParser_ASTFromFileObjectNeither PyPy nor Py_3_10
PyParser_ASTFromStringNeither PyPy nor Py_3_10
PyParser_ASTFromStringObjectNeither PyPy nor Py_3_10
PyParser_SimpleParseFileNeither PyPy nor Py_LIMITED_API nor Py_3_10
PyParser_SimpleParseFileFlagsNeither PyPy nor Py_3_10
PyParser_SimpleParseStringNeither PyPy nor Py_LIMITED_API nor Py_3_10
PyParser_SimpleParseStringFlagsNeither PyPy nor Py_3_10
PyParser_SimpleParseStringFlagsFilenameNeither PyPy nor Py_3_10
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_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_READYNon-Py_3_12 and little-endian
PyVectorcall_FunctionPy_3_8 and non-PyPy
PyVectorcall_NARGSPy_3_8 and non-PyPy
Py_CompileStringObjectNon-Py_LIMITED_API
Py_SymtableStringNeither PyPy nor Py_3_10
Py_SymtableStringObjectNeither PyPy nor Py_LIMITED_API nor Py_3_10
_PyDict_ContainsNon-Py_3_10
_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.