Python Glossary Русский

Python 3.13+typesterm

types.CapsuleType

interpreter objects

The type of a capsule — an opaque wrapper around a C pointer through which C modules share their API. Python code can do nothing with it.

Syntax

isinstance(obj, types.CapsuleType)

You meet it while exploring a module: datetime.datetime_CAPI, for instance, is a capsule. It has no useful attributes and cannot be called or unpacked from Python — only C extensions use it. The name appeared in types only in 3.13; before that the type had to be obtained with type() of an existing capsule.

Examples

# Python 3.13+
import datetime
import types
print(isinstance(datetime.datetime_CAPI, types.CapsuleType))  # → True
print(type(datetime.datetime_CAPI).__name__)  # → PyCapsule

See also

Open in the full glossarydocs.python.orgReport an inaccuracy