API and ABI Versioning

CPython exposes its version number in the following macros.Note that these correspond to the version code isbuilt with,not necessarily the version used atrun time.

SeeC API Stability for a discussion of API and ABI stability across versions.

PY_MAJOR_VERSION

The3 in3.4.1a2.

PY_MINOR_VERSION

The4 in3.4.1a2.

PY_MICRO_VERSION

The1 in3.4.1a2.

PY_RELEASE_LEVEL

Thea in3.4.1a2.This can be0xA for alpha,0xB for beta,0xC for releasecandidate or0xF for final.

PY_RELEASE_SERIAL

The2 in3.4.1a2. Zero for final releases.

PY_VERSION_HEX

The Python version number encoded in a single integer.

The underlying version information can be found by treating it as a 32 bitnumber in the following manner:

Bytes

Bits (big endian order)

Meaning

Value for3.4.1a2

1

1-8

PY_MAJOR_VERSION

0x03

2

9-16

PY_MINOR_VERSION

0x04

3

17-24

PY_MICRO_VERSION

0x01

4

25-28

PY_RELEASE_LEVEL

0xA

29-32

PY_RELEASE_SERIAL

0x2

Thus3.4.1a2 is hexversion0x030401a2 and3.10.0 ishexversion0x030a00f0.

Use this for numeric comparisons, e.g.#ifPY_VERSION_HEX>=....

This version is also available via the symbolPy_Version.

constunsignedlongPy_Version
Part of theStable ABI since version 3.11.

The Python runtime version number encoded in a single constant integer, withthe same format as thePY_VERSION_HEX macro.This contains the Python version used at run time.

Added in version 3.11.

All the given macros are defined inInclude/patchlevel.h.