| 1 |
.. highlight:: c |
| 2 |
|
| 3 |
.. _apiabiversion: |
| 4 |
|
| 5 |
*********************** |
| 6 |
API and ABI Versioning |
| 7 |
*********************** |
| 8 |
|
| 9 |
CPython exposes its version number in the following macros. |
| 10 |
Note that these correspond to the version code is **built** with, |
| 11 |
not necessarily the version used at **run time**. |
| 12 |
|
| 13 |
See :ref:`stable` for a discussion of API and ABI stability across versions. |
| 14 |
|
| 15 |
.. c:macro:: PY_MAJOR_VERSION |
| 16 |
|
| 17 |
The ``3`` in ``3.4.1a2``. |
| 18 |
|
| 19 |
.. c:macro:: PY_MINOR_VERSION |
| 20 |
|
| 21 |
The ``4`` in ``3.4.1a2``. |
| 22 |
|
| 23 |
.. c:macro:: PY_MICRO_VERSION |
| 24 |
|
| 25 |
The ``1`` in ``3.4.1a2``. |
| 26 |
|
| 27 |
.. c:macro:: PY_RELEASE_LEVEL |
| 28 |
|
| 29 |
The ``a`` in ``3.4.1a2``. |
| 30 |
This can be ``0xA`` for alpha, ``0xB`` for beta, ``0xC`` for release |
| 31 |
candidate or ``0xF`` for final. |
| 32 |
|
| 33 |
.. c:macro:: PY_RELEASE_SERIAL |
| 34 |
|
| 35 |
The ``2`` in ``3.4.1a2``. Zero for final releases. |
| 36 |
|
| 37 |
.. c:macro:: PY_VERSION_HEX |
| 38 |
|
| 39 |
The Python version number encoded in a single integer. |
| 40 |
|
| 41 |
The underlying version information can be found by treating it as a 32 bit |
| 42 |
number in the following manner: |
| 43 |
|
| 44 |
+-------+-------------------------+-------------------------+--------------------------+ |
| 45 |
| Bytes | Bits (big endian order) | Meaning | Value for ``3.4.1a2`` | |
| 46 |
+=======+=========================+=========================+==========================+ |
| 47 |
| 1 | 1-8 | ``PY_MAJOR_VERSION`` | ``0x03`` | |
| 48 |
+-------+-------------------------+-------------------------+--------------------------+ |
| 49 |
| 2 | 9-16 | ``PY_MINOR_VERSION`` | ``0x04`` | |
| 50 |
+-------+-------------------------+-------------------------+--------------------------+ |
| 51 |
| 3 | 17-24 | ``PY_MICRO_VERSION`` | ``0x01`` | |
| 52 |
+-------+-------------------------+-------------------------+--------------------------+ |
| 53 |
| 4 | 25-28 | ``PY_RELEASE_LEVEL`` | ``0xA`` | |
| 54 |
+ +-------------------------+-------------------------+--------------------------+ |
| 55 |
| | 29-32 | ``PY_RELEASE_SERIAL`` | ``0x2`` | |
| 56 |
+-------+-------------------------+-------------------------+--------------------------+ |
| 57 |
|
| 58 |
Thus ``3.4.1a2`` is hexversion ``0x030401a2`` and ``3.10.0`` is |
| 59 |
hexversion ``0x030a00f0``. |
| 60 |
|
| 61 |
Use this for numeric comparisons, e.g. ``#if PY_VERSION_HEX >= ...``. |
| 62 |
|
| 63 |
This version is also available via the symbol :c:var:`Py_Version`. |
| 64 |
|
| 65 |
.. c:var:: const unsigned long Py_Version |
| 66 |
|
| 67 |
The Python runtime version number encoded in a single constant integer, with |
| 68 |
the same format as the :c:macro:`PY_VERSION_HEX` macro. |
| 69 |
This contains the Python version used at run time. |
| 70 |
|
| 71 |
.. versionadded:: 3.11 |
| 72 |
|
| 73 |
All the given macros are defined in :source:`Include/patchlevel.h`. |