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.
Re-exports§
#[doc(hidden)] pub use crate::impl_::pymethods::ipowfunc;
Modules§
- C API Compatibility Shims
- marshal
Non- Py_LIMITED_API
- structmember
Deprecated
Macros§
- This is a helper macro to create a
&'static CStr
.
Structs§
- PyByte
Array Object Neither PyPy
norGraalPy
norPy_LIMITED_API
- PyBytes
Object Neither PyPy
norGraalPy
norPy_LIMITED_API
- PyCode
Object Neither PyPy
norGraalPy
andPy_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
. - PyDict
Object Non- GraalPy
- PyFrame
Object Neither PyPy
norGraalPy
norPy_3_11
- PyFunction
Object Neither PyPy
norGraalPy
and non-Py_3_10
- PyFuture
Features Neither PyPy
norGraalPy
norPy_3_13
- PyGen
Object Neither PyPy
norGraalPy
- Represents the PyGetSetDef structure.
- PyHash_
Func Def Neither Py_LIMITED_API
norPyPy
norGraalPy
- PyImport
Error Object Neither PyPy
norGraalPy
- PyList
Object Neither PyPy
norGraalPy
- PyMem
Allocator Ex Neither PyPy
norGraalPy
- Represents the PyMemberDef structure.
- Represents the PyMethodDef structure.
- PyOS
Error Object Neither PyPy
norGraalPy
- PyObject
Arena Allocator Neither PyPy
norGraalPy
- PySet
Object Neither Py_LIMITED_API
norPyPy
norGraalPy
- PySlice
Object Non- Py_LIMITED_API
- PySyntax
Error Object Neither PyPy
norGraalPy
- PySystem
Exit Object Neither PyPy
norGraalPy
- PyTry
Block Neither PyPy
norGraalPy
norPy_3_11
- PyUnicode
Error Object Neither PyPy
norGraalPy
- PyWeak
Reference Neither PyPy
norGraalPy
- _PyDate
Time_ Base Date Time Neither PyPy
norGraalPy
Structure representing adatetime.datetime
without atzinfo
member. - _PyDate
Time_ Base Time Neither PyPy
norGraalPy
Structure representing adatetime.time
without atzinfo
member. - _PyErr_
Stack Item Non- PyPy
- _PyWeak
Reference Neither PyPy
norGraalPy
- _frozen
Non- PyPy
- _inittab
Non- PyPy
- setentry
Neither Py_LIMITED_API
norPyPy
norGraalPy
Enums§
Constants§
- METH_
FASTCALL Py_3_10
or non-Py_LIMITED_API
- PY_
BIG_ ENDIAN Little-endian - PY_
LITTLE_ ENDIAN Little-endian - Maximum number of dimensions
- PyUnicode_
WCHAR_ KIND Deprecated Non- Py_3_12
- Set if the type allows subclassing
- Objects support garbage collection (see objimp.h)
- Py_
TPFLAGS_ HAVE_ VECTORCALL Py_3_12
, orPy_3_8
and non-Py_LIMITED_API
Set if the type implements the vectorcall protocol (PEP 590) - 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
- Py_
func_ type_ input Py_3_8
- _Py_
T_ NONE Deprecated - _Py_
T_ OBJECT Deprecated - _Py_
WRITE_ RESTRICTED Deprecated
Statics§
- built-in ‘object’
- PyDict
RevIter Item_ Type Py_3_8
- PyDict
RevIter Key_ Type Py_3_8
- PyDict
RevIter Value_ Type Py_3_8
- PyFunction_
Type Not ( PyPy
and non-Py_3_8
) - PyImport_
Frozen Modules Non- PyPy
- PyImport_
Inittab Non- PyPy
- built-in ‘super’
- built-in ‘type’
- Py_
Bytes Warning Flag Deprecated - Py_
Debug Flag Deprecated - Py_
Dont Write Bytecode Flag Deprecated - Py_
File System Default Encode Errors Deprecated - Py_
File System Default Encoding Deprecated - Py_
Frozen Flag Deprecated - Py_
HasFile System Default Encoding Deprecated - Py_
Ignore Environment Flag Deprecated - Py_
Inspect Flag Deprecated - Py_
Interactive Flag Deprecated - Py_
Isolated Flag Deprecated - Py_
NoSite Flag Deprecated - Py_
NoUser Site Directory Deprecated - Py_
Optimize Flag Deprecated - Py_
Quiet Flag Deprecated - Py_
Unbuffered Stdio Flag Deprecated - Py_
UseClass Exceptions Flag Deprecated - Py_
Verbose Flag Deprecated - _PyManaged
Buffer_ Type Non- Py_LIMITED_API
Functions§
- PyAST_
Compile ⚠Ex Neither PyPy
norPy_3_10
- PyAST_
Compile ⚠Object Neither PyPy
norPy_3_10
- PyAny
Set_ ⚠Check Exact Non- PyPy
- PyCFunction_
Call ⚠Non- Py_3_13
- PyCFunction_
Check ⚠Non- Py_3_9
- PyCFunction_
Clear ⚠Free List Non- Py_3_9
- PyCode_
Addr2 ⚠Line Non- GraalPy
- PyCode_
Check ⚠Neither PyPy
norGraalPy
- PyCode_
New ⚠Non- GraalPy
- PyCode_
NewEmpty ⚠Non- GraalPy
- PyCode_
NewWith ⚠PosOnly Args Non- GraalPy
andPy_3_8
- Returns a pointer to a
PyDateTime_CAPI
instance - Check if
op
is aPyDateTimeAPI.DateTimeType
or subtype. - Check if
op
’s type is exactlyPyDateTimeAPI.DateTimeType
. - PyDate
Time_ ⚠DATE_ GET_ FOLD Neither PyPy
norGraalPy
Retrieve the fold component of aPyDateTime_DateTime
. Returns a signed integer in the interval[0, 1]
- PyDate
Time_ ⚠DATE_ GET_ HOUR Neither PyPy
norGraalPy
Retrieve the hour component of aPyDateTime_DateTime
. Returns a signed integer in the interval[0, 23]
- PyDate
Time_ ⚠DATE_ GET_ MICROSECOND Neither PyPy
norGraalPy
Retrieve the microsecond component of aPyDateTime_DateTime
. Returns a signed integer in the interval[0, 999999]
- PyDate
Time_ ⚠DATE_ GET_ MINUTE Neither PyPy
norGraalPy
Retrieve the minute component of aPyDateTime_DateTime
. Returns a signed integer in the interval[0, 59]
- PyDate
Time_ ⚠DATE_ GET_ SECOND Neither PyPy
norGraalPy
Retrieve the second component of aPyDateTime_DateTime
. Returns a signed integer in the interval[0, 59]
- PyDate
Time_ ⚠DATE_ GET_ TZINFO Neither PyPy
norGraalPy
Retrieve the tzinfo component of aPyDateTime_DateTime
. Returns a pointer to aPyObject
that should be either NULL or an instance of adatetime.tzinfo
subclass. - PyDate
Time_ ⚠DELTA_ GET_ DAYS Neither PyPy
norGraalPy
Retrieve the days component of aPyDateTime_Delta
. - PyDate
Time_ ⚠DELTA_ GET_ MICROSECONDS Neither PyPy
norGraalPy
Retrieve the seconds component of aPyDateTime_Delta
. - PyDate
Time_ ⚠DELTA_ GET_ SECONDS Neither PyPy
norGraalPy
Retrieve the seconds component of aPyDateTime_Delta
. - PyDate
Time_ ⚠From Timestamp Non- PyPy
- PyDate
Time_ ⚠GET_ DAY Neither PyPy
norGraalPy
Retrieve the day component of aPyDateTime_Date
orPyDateTime_DateTime
. Returns a signed integer in the interval[1, 31]
. - PyDate
Time_ ⚠GET_ MONTH Neither PyPy
norGraalPy
Retrieve the month component of aPyDateTime_Date
orPyDateTime_DateTime
. Returns a signed integer in the range[1, 12]
. - PyDate
Time_ ⚠GET_ YEAR Neither PyPy
norGraalPy
Retrieve the year component of aPyDateTime_Date
orPyDateTime_DateTime
. Returns a signed integer greater than 0. - Populates the
PyDateTimeAPI
object - PyDate
Time_ ⚠TIME_ GET_ FOLD Neither PyPy
norGraalPy
Retrieve the fold component of aPyDateTime_Time
. Returns a signed integer in the interval[0, 1]
- PyDate
Time_ ⚠TIME_ GET_ HOUR Neither PyPy
norGraalPy
Retrieve the hour component of aPyDateTime_Time
. Returns a signed integer in the interval[0, 23]
- PyDate
Time_ ⚠TIME_ GET_ MICROSECOND Neither PyPy
norGraalPy
Retrieve the microsecond component of aPyDateTime_DateTime
. Returns a signed integer in the interval[0, 999999]
- PyDate
Time_ ⚠TIME_ GET_ MINUTE Neither PyPy
norGraalPy
Retrieve the minute component of aPyDateTime_Time
. Returns a signed integer in the interval[0, 59]
- PyDate
Time_ ⚠TIME_ GET_ SECOND Neither PyPy
norGraalPy
Retrieve the second component of aPyDateTime_DateTime
. Returns a signed integer in the interval[0, 59]
- PyDate
Time_ ⚠TIME_ GET_ TZINFO Neither PyPy
norGraalPy
Retrieve the tzinfo component of aPyDateTime_Time
. Returns a pointer to aPyObject
that should be either NULL or an instance of adatetime.tzinfo
subclass. - Type Check macros
- Check if
op
’s type is exactlyPyDateTimeAPI.DateType
. - PyDate_
From ⚠Timestamp Non- PyPy
- Check if
op
is aPyDateTimeAPI.DetaType
or subtype. - Check if
op
’s type is exactlyPyDateTimeAPI.DeltaType
. - PyEval_
Call ⚠Function Non- Py_3_13
- PyEval_
Call ⚠Method Non- Py_3_13
- PyEval_
Call ⚠Object Non- Py_3_13
- PyEval_
Call ⚠Object With Keywords Non- Py_3_13
- PyEval_
Threads ⚠Initialized Non- Py_3_13
- PyException
Instance_ ⚠Class Non- PyPy
- PyFrame_
Block ⚠Pop Neither PyPy
norGraalPy
norPy_3_11
- PyFrame_
Clear ⚠Free List Non- Py_3_9
- PyFrame_
New ⚠Non- GraalPy
- PyFrozen
Set_ ⚠Check Non- PyPy
- PyFrozen
Set_ ⚠Check Exact Neither PyPy
norGraalPy
- PyFunction_
Check ⚠Not ( PyPy
and non-Py_3_8
) - PyFuture_
FromAST ⚠Neither PyPy
norPy_3_10
- PyFuture_
FromAST ⚠Object Neither PyPy
norPy_3_10
- PyGIL
State_ ⚠GetThis Thread State Non- PyPy
- PyGen_
Needs ⚠Finalizing Deprecated Neither Py_3_9
norPyPy
- PyHash_
GetFunc ⚠Def Neither Py_LIMITED_API
norPyPy
norGraalPy
- PyHeap
Type_ ⚠GET_ MEMBERS Non- Py_3_11
- PyImport_
Cleanup ⚠Deprecated Non- Py_3_9
- PyImport_
Extend ⚠Inittab Non- PyPy
- PyIndex_
Check ⚠Neither Py_LIMITED_API
norPyPy
- PyInterpreter
State_ ⚠Clear Non- PyPy
- PyInterpreter
State_ ⚠Delete Non- PyPy
- PyInterpreter
State_ ⚠GetDict Py_3_8
and non-PyPy
- PyInterpreter
State_ ⚠GetID Non- PyPy
- PyInterpreter
State_ ⚠Main Non- PyPy
- PyInterpreter
State_ ⚠New Non- PyPy
- PyInterpreter
State_ ⚠Thread Head Non- PyPy
- PyIter_
Check ⚠Py_3_8
orPyPy
- PyList_
GET_ ⚠ITEM Neither PyPy
norGraalPy
Macro, trading safety for speed - PyList_
GET_ ⚠SIZE Non- PyPy
- PyList_
SET_ ⚠ITEM Neither PyPy
norGraalPy
Macro, only to be used to fill in brand new lists - PyMapping_
Length ⚠Non- PyPy
- PyMem_
GetAllocator ⚠Neither PyPy
norGraalPy
- PyMem_
SetAllocator ⚠Neither PyPy
norGraalPy
- PyMem_
Setup ⚠Debug Hooks Neither PyPy
norGraalPy
- PyMemory
View_ ⚠From Buffer Py_3_11
or non-Py_LIMITED_API
- PyModule_
Create2 ⚠Non- py_sys_config="Py_TRACE_REFS"
- PyModule_
From ⚠DefAnd Spec2 Non- py_sys_config="Py_TRACE_REFS"
- PyModule_
GetFilename ⚠Deprecated Not (Windows and PyPy
) - PyModule_
GetFilename ⚠Object Non- PyPy
- PyModule_
GetName ⚠Object Non- PyPy
- PyNode_
Compile ⚠Neither PyPy
norPy_3_10
- PyOS_
After ⚠Fork Deprecated - PyOS_
Init ⚠Interrupts Deprecated Non- Py_3_10
- PyObject_
Call ⚠OneArg Py_3_8
and neitherPyPy
norGraalPy
- PyObject_
Check ⚠Buffer Neither Py_3_9
norPyPy
- PyObject_
DelAttr ⚠Non- Py_3_13
and non-PyPy
- PyObject_
DelAttr ⚠String Non- Py_3_13
and non-PyPy
- PyObject_
GC_ ⚠Track Non- PyPy
- PyObject_
GC_ ⚠UnTrack Non- PyPy
- PyObject_
Generic ⚠GetDict Not ( Py_LIMITED_API
and non-Py_3_10
) - PyObject_
GetArena ⚠Allocator Neither PyPy
norGraalPy
- PyObject_
IS_ ⚠GC Non- Py_3_9
- PyObject_
SetArena ⚠Allocator Neither PyPy
norGraalPy
- PyObject_
Vectorcall ⚠Py_3_8
and neitherPyPy
norGraalPy
- PyObject_
Vectorcall ⚠Dict Py_3_8
- PyParser_
ASTFrom ⚠File Neither PyPy
norGraalPy
norPy_3_10
- PyParser_
ASTFrom ⚠File Object Neither PyPy
norGraalPy
norPy_3_10
- PyParser_
ASTFrom ⚠String Neither PyPy
norGraalPy
norPy_3_10
- PyParser_
ASTFrom ⚠String Object Neither PyPy
norGraalPy
norPy_3_10
- PyParser_
Simple ⚠Parse File Neither PyPy
norPy_LIMITED_API
norPy_3_10
- PyParser_
Simple ⚠Parse File Flags Neither PyPy
norGraalPy
norPy_3_10
- PyParser_
Simple ⚠Parse String Neither PyPy
norPy_LIMITED_API
norPy_3_10
- PyParser_
Simple ⚠Parse String Flags Neither PyPy
norGraalPy
norPy_3_10
- PyParser_
Simple ⚠Parse String Flags Filename Neither PyPy
norGraalPy
norPy_3_10
- PyRun_
AnyFile ⚠Neither PyPy
norGraalPy
- PyRun_
AnyFile ⚠Ex Neither PyPy
norGraalPy
- PyRun_
AnyFile ⚠Flags Neither PyPy
norGraalPy
- PyRun_
File ⚠Ex Neither PyPy
norGraalPy
- PyRun_
File ⚠ExFlags Neither PyPy
norGraalPy
- PyRun_
File ⚠Flags Neither PyPy
norGraalPy
- PyRun_
Interactive ⚠Loop Neither PyPy
norGraalPy
- PyRun_
Interactive ⚠One Neither PyPy
norGraalPy
- PyRun_
Simple ⚠File Neither PyPy
norGraalPy
- PyRun_
Simple ⚠File Ex Neither PyPy
norGraalPy
- PySequence_
Length ⚠Non- PyPy
- PySet_
Check ⚠Non- PyPy
- PySet_
GET_ ⚠SIZE Neither PyPy
norGraalPy
and non-Py_LIMITED_API
- PyStruct
Sequence_ ⚠GET_ ITEM Neither Py_LIMITED_API
norPyPy
norGraalPy
- PyStruct
Sequence_ ⚠GetItem Non- PyPy
- PyStruct
Sequence_ ⚠Init Type Non- Py_LIMITED_API
- PyStruct
Sequence_ ⚠Init Type2 Non- Py_LIMITED_API
- PyStruct
Sequence_ ⚠NewType Non- PyPy
- PyStruct
Sequence_ ⚠SET_ ITEM Neither Py_LIMITED_API
norPyPy
norGraalPy
- PyStruct
Sequence_ ⚠SetItem Non- PyPy
- Check if
op
is aPyDateTimeAPI.TZInfoType
or subtype. - Check if
op
’s type is exactlyPyDateTimeAPI.TZInfoType
. - PyThread
State_ ⚠Next Non- PyPy
- PyThread
State_ ⚠SetAsync Exc Non- PyPy
- Check if
op
is aPyDateTimeAPI.TimeType
or subtype. - Check if
op
’s type is exactlyPyDateTimeAPI.TimeType
. - PyTrace
Back_ ⚠Check Non- PyPy
- PyTuple_
Clear ⚠Free List Non- Py_3_9
- PyTuple_
GET_ ⚠ITEM Neither PyPy
norGraalPy
- PyTuple_
GET_ ⚠SIZE Non- PyPy
Macro, trading safety for speed - PyTuple_
SET_ ⚠ITEM Neither PyPy
norGraalPy
Macro, only to be used to fill in brand new tuples - PyUnicode
Decode ⚠Error_ Create Non- PyPy
- PyUnicode_
1BYTE_ ⚠DATA Neither GraalPy
norPyPy
- PyUnicode_
2BYTE_ ⚠DATA Neither GraalPy
norPyPy
- PyUnicode_
4BYTE_ ⚠DATA Neither GraalPy
norPyPy
- PyUnicode_
AsUT ⚠F8And Size Py_3_10
or non-Py_LIMITED_API
- PyUnicode_
AsUnicode ⚠Deprecated Non- Py_3_12
- PyUnicode_
AsUnicode ⚠AndSize Deprecated Non- Py_3_12
- PyUnicode_
Check ⚠Non- PyPy
- PyUnicode_
Check ⚠Exact Non- PyPy
- PyUnicode_
Copy ⚠Characters Non- PyPy
- PyUnicode_
DATA ⚠Neither GraalPy
norPyPy
- PyUnicode_
Fill ⚠Non- PyPy
- PyUnicode_
From ⚠Unicode Deprecated Non- Py_3_12
- PyUnicode_
GET_ ⚠LENGTH Non- GraalPy
- PyUnicode_
GetSize ⚠Deprecated Non- Py_3_12
- PyUnicode_
IS_ ⚠ASCII Non- GraalPy
- PyUnicode_
IS_ ⚠COMPACT Non- GraalPy
- PyUnicode_
IS_ ⚠COMPACT_ ASCII Non- GraalPy
- PyUnicode_
IS_ ⚠READY Neither GraalPy
norPy_3_12
- PyUnicode_
Intern ⚠Immortal Non- Py_3_12
- PyUnicode_
KIND ⚠Non- GraalPy
- PyUnicode_
READY ⚠Neither Py_3_12
norGraalPy
- PyVectorcall_
Call ⚠Py_3_8
- PyVectorcall_
Function ⚠Py_3_8
and neitherPyPy
norGraalPy
- PyVectorcall_
NARGS ⚠Py_3_8
- PyWeakref_
Check ⚠Proxy Non- PyPy
- PyWeakref_
Check ⚠Ref Non- PyPy
- PyWeakref_
Check ⚠RefExact Non- PyPy
- Py_
Compile ⚠String Neither PyPy
norGraalPy
- Py_
Compile ⚠String ExFlags Neither PyPy
norGraalPy
- Py_
Compile ⚠String Flags Neither PyPy
norGraalPy
- Py_
Compile ⚠String Object Non- Py_LIMITED_API
- Py_
GETENV ⚠Non- Py_3_11
- Py_Is⚠
Not ( PyPy
andPy_3_10
) - Py_
SetPath ⚠Non- Py_3_13
- Py_
Symtable ⚠String Neither PyPy
norPy_3_10
- Py_
Symtable ⚠String Object Neither PyPy
norPy_LIMITED_API
norPy_3_10
- _PyDict_
Contains ⚠Non- Py_3_10
- _PyEval_
Eval ⚠Frame Default Non- Py_3_11
- _PyImport_
Find ⚠Builtin Non- Py_3_9
- _PyImport_
Find ⚠Extension Object Non- Py_3_11
- _PyObject_
Call ⚠Function_ SizeT Non- Py_3_13
- _PyObject_
Call ⚠Method_ SizeT Non- Py_3_13
- _PyObject_
Call ⚠NoArg Py_3_8
and neitherPyPy
norGraalPy
- _PyObject_
Fast ⚠Call Py_3_8
and neitherPyPy
norGraalPy
- _PyObject_
Fast ⚠Call Tstate Py_3_8
and neitherPyPy
norGraalPy
- _PyObject_
Make ⚠TpCall Py_3_8
and neitherPyPy
norGraalPy
- _PyObject_
Vectorcall ⚠Tstate Py_3_8
and neitherPyPy
norGraalPy
- _PySequence_
Iter ⚠Search Neither PyPy
norGraalPy
- _PySet_
Next ⚠Entry Non- Py_LIMITED_API
- _PyStack_
AsDict ⚠Py_3_8
and neitherPyPy
norGraalPy
- _PyUnicode_
COMPACT_ ⚠DATA Non- GraalPy
- _PyUnicode_
Check ⚠Consistency Neither PyPy
norGraalPy
- _PyUnicode_
NONCOMPACT_ ⚠DATA Neither GraalPy
norPyPy
- _Py_
Check ⚠Function Result Py_3_8
and neitherPyPy
norGraalPy
- _Py_
Hash ⚠Bytes Neither Py_LIMITED_API
norPyPy
norGraalPy
Type Aliases§
- PyCFunction
Fast Py_3_10
or non-Py_LIMITED_API
- PyCFunction
Fast With Keywords Py_3_10
or non-Py_LIMITED_API
- PyFrame
State Neither PyPy
norGraalPy
norPy_3_11
- PyObject
ObRefcnt Non- Py_3_12
and non-Py_GIL_DISABLED
- PyStruct
Sequence Non- Py_LIMITED_API
- Py_
UNICODE Non- Py_LIMITED_API
- _PyC
Function Fast Deprecated Py_3_10
or non-Py_LIMITED_API
- _PyC
Function Fast With Keywords Deprecated Py_3_10
or non-Py_LIMITED_API
- vectorcallfunc
Py_3_8
Unions§
- Function types used to implement Python callables.