summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/c-api%2Fapiabiversion.html
blob: 7ef6a990c9fe9aa8f0d0451ab46ee4fac1d85c81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 <span id="apiabiversion"></span><h1>API and ABI Versioning</h1> <p>CPython exposes its version number in the following macros. Note that these correspond to the version code is <strong>built</strong> with, not necessarily the version used at <strong>run time</strong>.</p> <p>See <a class="reference internal" href="stable#stable"><span class="std std-ref">C API Stability</span></a> for a discussion of API and ABI stability across versions.</p> <dl class="c macro"> <dt class="sig sig-object c" id="c.PY_MAJOR_VERSION">
<code>PY_MAJOR_VERSION</code> </dt> <dd>
<p>The <code>3</code> in <code>3.4.1a2</code>.</p> </dd>
</dl> <dl class="c macro"> <dt class="sig sig-object c" id="c.PY_MINOR_VERSION">
<code>PY_MINOR_VERSION</code> </dt> <dd>
<p>The <code>4</code> in <code>3.4.1a2</code>.</p> </dd>
</dl> <dl class="c macro"> <dt class="sig sig-object c" id="c.PY_MICRO_VERSION">
<code>PY_MICRO_VERSION</code> </dt> <dd>
<p>The <code>1</code> in <code>3.4.1a2</code>.</p> </dd>
</dl> <dl class="c macro"> <dt class="sig sig-object c" id="c.PY_RELEASE_LEVEL">
<code>PY_RELEASE_LEVEL</code> </dt> <dd>
<p>The <code>a</code> in <code>3.4.1a2</code>. This can be <code>0xA</code> for alpha, <code>0xB</code> for beta, <code>0xC</code> for release candidate or <code>0xF</code> for final.</p> </dd>
</dl> <dl class="c macro"> <dt class="sig sig-object c" id="c.PY_RELEASE_SERIAL">
<code>PY_RELEASE_SERIAL</code> </dt> <dd>
<p>The <code>2</code> in <code>3.4.1a2</code>. Zero for final releases.</p> </dd>
</dl> <dl class="c macro"> <dt class="sig sig-object c" id="c.PY_VERSION_HEX">
<code>PY_VERSION_HEX</code> </dt> <dd>
<p>The Python version number encoded in a single integer.</p> <p>The underlying version information can be found by treating it as a 32 bit number in the following manner:</p> <table class="docutils align-default">  <thead> <tr>
<th class="head"><p>Bytes</p></th> <th class="head"><p>Bits (big endian order)</p></th> <th class="head"><p>Meaning</p></th> <th class="head"><p>Value for <code>3.4.1a2</code></p></th> </tr> </thead>  <tr>
<td><p>1</p></td> <td><p>1-8</p></td> <td><p><code>PY_MAJOR_VERSION</code></p></td> <td><p><code>0x03</code></p></td> </tr> <tr>
<td><p>2</p></td> <td><p>9-16</p></td> <td><p><code>PY_MINOR_VERSION</code></p></td> <td><p><code>0x04</code></p></td> </tr> <tr>
<td><p>3</p></td> <td><p>17-24</p></td> <td><p><code>PY_MICRO_VERSION</code></p></td> <td><p><code>0x01</code></p></td> </tr> <tr>
<td rowspan="2"><p>4</p></td> <td><p>25-28</p></td> <td><p><code>PY_RELEASE_LEVEL</code></p></td> <td><p><code>0xA</code></p></td> </tr> <tr>
<td><p>29-32</p></td> <td><p><code>PY_RELEASE_SERIAL</code></p></td> <td><p><code>0x2</code></p></td> </tr>  </table> <p>Thus <code>3.4.1a2</code> is hexversion <code>0x030401a2</code> and <code>3.10.0</code> is hexversion <code>0x030a00f0</code>.</p> <p>Use this for numeric comparisons, e.g. <code>#if PY_VERSION_HEX &gt;= ...</code>.</p> <p>This version is also available via the symbol <a class="reference internal" href="#c.Py_Version" title="Py_Version"><code>Py_Version</code></a>.</p> </dd>
</dl> <dl class="c var"> <dt class="sig sig-object c" id="c.Py_Version">
<code>const unsigned long Py_Version</code> </dt> <dd>
<em class="stableabi"> Part of the <a class="reference internal" href="stable#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.11.</em><p>The Python runtime version number encoded in a single constant integer, with the same format as the <a class="reference internal" href="#c.PY_VERSION_HEX" title="PY_VERSION_HEX"><code>PY_VERSION_HEX</code></a> macro. This contains the Python version used at run time.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd>
</dl> <p>All the given macros are defined in <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Include/patchlevel.h">Include/patchlevel.h</a>.</p> <div class="_attribution">
  <p class="_attribution-p">
    &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
    <a href="https://docs.python.org/3.12/c-api/apiabiversion.html" class="_attribution-link">https://docs.python.org/3.12/c-api/apiabiversion.html</a>
  </p>
</div>