summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fplatform.html
blob: dfe0be6dbc76ea8cdb68322ed58765582e982d63 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 <span id="platform-access-to-underlying-platform-s-identifying-data"></span><h1>platform — Access to underlying platform’s identifying data</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/platform.py">Lib/platform.py</a></p>  <div class="admonition note"> <p class="admonition-title">Note</p> <p>Specific platforms listed alphabetically, with Linux included in the Unix section.</p> </div> <section id="cross-platform"> <h2>Cross Platform</h2> <dl class="py function"> <dt class="sig sig-object py" id="platform.architecture">
<code>platform.architecture(executable=sys.executable, bits='', linkage='')</code> </dt> <dd>
<p>Queries the given executable (defaults to the Python interpreter binary) for various architecture information.</p> <p>Returns a tuple <code>(bits, linkage)</code> which contain information about the bit architecture and the linkage format used for the executable. Both values are returned as strings.</p> <p>Values that cannot be determined are returned as given by the parameter presets. If bits is given as <code>''</code>, the <code>sizeof(pointer)</code> (or <code>sizeof(long)</code> on Python version &lt; 1.5.2) is used as indicator for the supported pointer size.</p> <p>The function relies on the system’s <code>file</code> command to do the actual work. This is available on most if not all Unix platforms and some non-Unix platforms and then only if the executable points to the Python interpreter. Reasonable defaults are used when the above needs are not met.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>On macOS (and perhaps other platforms), executable files may be universal files containing multiple architectures.</p> <p>To get at the “64-bitness” of the current interpreter, it is more reliable to query the <a class="reference internal" href="sys#sys.maxsize" title="sys.maxsize"><code>sys.maxsize</code></a> attribute:</p> <pre data-language="python">is_64bits = sys.maxsize &gt; 2**32
</pre> </div> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.machine">
<code>platform.machine()</code> </dt> <dd>
<p>Returns the machine type, e.g. <code>'AMD64'</code>. An empty string is returned if the value cannot be determined.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.node">
<code>platform.node()</code> </dt> <dd>
<p>Returns the computer’s network name (may not be fully qualified!). An empty string is returned if the value cannot be determined.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.platform">
<code>platform.platform(aliased=False, terse=False)</code> </dt> <dd>
<p>Returns a single string identifying the underlying platform with as much useful information as possible.</p> <p>The output is intended to be <em>human readable</em> rather than machine parseable. It may look different on different platforms and this is intended.</p> <p>If <em>aliased</em> is true, the function will use aliases for various platforms that report system names which differ from their common names, for example SunOS will be reported as Solaris. The <a class="reference internal" href="#platform.system_alias" title="platform.system_alias"><code>system_alias()</code></a> function is used to implement this.</p> <p>Setting <em>terse</em> to true causes the function to return only the absolute minimum information needed to identify the platform.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>On macOS, the function now uses <a class="reference internal" href="#platform.mac_ver" title="platform.mac_ver"><code>mac_ver()</code></a>, if it returns a non-empty release string, to get the macOS version rather than the darwin version.</p> </div> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.processor">
<code>platform.processor()</code> </dt> <dd>
<p>Returns the (real) processor name, e.g. <code>'amdk6'</code>.</p> <p>An empty string is returned if the value cannot be determined. Note that many platforms do not provide this information or simply return the same value as for <a class="reference internal" href="#platform.machine" title="platform.machine"><code>machine()</code></a>. NetBSD does this.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.python_build">
<code>platform.python_build()</code> </dt> <dd>
<p>Returns a tuple <code>(buildno, builddate)</code> stating the Python build number and date as strings.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.python_compiler">
<code>platform.python_compiler()</code> </dt> <dd>
<p>Returns a string identifying the compiler used for compiling Python.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.python_branch">
<code>platform.python_branch()</code> </dt> <dd>
<p>Returns a string identifying the Python implementation SCM branch.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.python_implementation">
<code>platform.python_implementation()</code> </dt> <dd>
<p>Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.python_revision">
<code>platform.python_revision()</code> </dt> <dd>
<p>Returns a string identifying the Python implementation SCM revision.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.python_version">
<code>platform.python_version()</code> </dt> <dd>
<p>Returns the Python version as string <code>'major.minor.patchlevel'</code>.</p> <p>Note that unlike the Python <code>sys.version</code>, the returned value will always include the patchlevel (it defaults to 0).</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.python_version_tuple">
<code>platform.python_version_tuple()</code> </dt> <dd>
<p>Returns the Python version as tuple <code>(major, minor, patchlevel)</code> of strings.</p> <p>Note that unlike the Python <code>sys.version</code>, the returned value will always include the patchlevel (it defaults to <code>'0'</code>).</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.release">
<code>platform.release()</code> </dt> <dd>
<p>Returns the system’s release, e.g. <code>'2.2.0'</code> or <code>'NT'</code>. An empty string is returned if the value cannot be determined.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.system">
<code>platform.system()</code> </dt> <dd>
<p>Returns the system/OS name, such as <code>'Linux'</code>, <code>'Darwin'</code>, <code>'Java'</code>, <code>'Windows'</code>. An empty string is returned if the value cannot be determined.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.system_alias">
<code>platform.system_alias(system, release, version)</code> </dt> <dd>
<p>Returns <code>(system, release, version)</code> aliased to common marketing names used for some systems. It also does some reordering of the information in some cases where it would otherwise cause confusion.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.version">
<code>platform.version()</code> </dt> <dd>
<p>Returns the system’s release version, e.g. <code>'#3 on degas'</code>. An empty string is returned if the value cannot be determined.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.uname">
<code>platform.uname()</code> </dt> <dd>
<p>Fairly portable uname interface. Returns a <a class="reference internal" href="collections#collections.namedtuple" title="collections.namedtuple"><code>namedtuple()</code></a> containing six attributes: <a class="reference internal" href="#platform.system" title="platform.system"><code>system</code></a>, <a class="reference internal" href="#platform.node" title="platform.node"><code>node</code></a>, <a class="reference internal" href="#platform.release" title="platform.release"><code>release</code></a>, <a class="reference internal" href="#platform.version" title="platform.version"><code>version</code></a>, <a class="reference internal" href="#platform.machine" title="platform.machine"><code>machine</code></a>, and <a class="reference internal" href="#platform.processor" title="platform.processor"><code>processor</code></a>.</p> <p><a class="reference internal" href="#platform.processor" title="platform.processor"><code>processor</code></a> is resolved late, on demand.</p> <p>Note: the first two attribute names differ from the names presented by <a class="reference internal" href="os#os.uname" title="os.uname"><code>os.uname()</code></a>, where they are named <code>sysname</code> and <code>nodename</code>.</p> <p>Entries which cannot be determined are set to <code>''</code>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span>Result changed from a tuple to a <a class="reference internal" href="collections#collections.namedtuple" title="collections.namedtuple"><code>namedtuple()</code></a>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.9: </span><a class="reference internal" href="#platform.processor" title="platform.processor"><code>processor</code></a> is resolved late instead of immediately.</p> </div> </dd>
</dl> </section> <section id="java-platform"> <h2>Java Platform</h2> <dl class="py function"> <dt class="sig sig-object py" id="platform.java_ver">
<code>platform.java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', ''))</code> </dt> <dd>
<p>Version interface for Jython.</p> <p>Returns a tuple <code>(release, vendor, vminfo, osinfo)</code> with <em>vminfo</em> being a tuple <code>(vm_name, vm_release, vm_vendor)</code> and <em>osinfo</em> being a tuple <code>(os_name, os_version, os_arch)</code>. Values which cannot be determined are set to the defaults given as parameters (which all default to <code>''</code>).</p> </dd>
</dl> </section> <section id="windows-platform"> <h2>Windows Platform</h2> <dl class="py function"> <dt class="sig sig-object py" id="platform.win32_ver">
<code>platform.win32_ver(release='', version='', csd='', ptype='')</code> </dt> <dd>
<p>Get additional version information from the Windows Registry and return a tuple <code>(release, version, csd, ptype)</code> referring to OS release, version number, CSD level (service pack) and OS type (multi/single processor). Values which cannot be determined are set to the defaults given as parameters (which all default to an empty string).</p> <p>As a hint: <em>ptype</em> is <code>'Uniprocessor Free'</code> on single processor NT machines and <code>'Multiprocessor Free'</code> on multi processor machines. The <em>‘Free’</em> refers to the OS version being free of debugging code. It could also state <em>‘Checked’</em> which means the OS version uses debugging code, i.e. code that checks arguments, ranges, etc.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.win32_edition">
<code>platform.win32_edition()</code> </dt> <dd>
<p>Returns a string representing the current Windows edition, or <code>None</code> if the value cannot be determined. Possible values include but are not limited to <code>'Enterprise'</code>, <code>'IoTUAP'</code>, <code>'ServerStandard'</code>, and <code>'nanoserver'</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="platform.win32_is_iot">
<code>platform.win32_is_iot()</code> </dt> <dd>
<p>Return <code>True</code> if the Windows edition returned by <a class="reference internal" href="#platform.win32_edition" title="platform.win32_edition"><code>win32_edition()</code></a> is recognized as an IoT edition.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
</dl> </section> <section id="macos-platform"> <h2>macOS Platform</h2> <dl class="py function"> <dt class="sig sig-object py" id="platform.mac_ver">
<code>platform.mac_ver(release='', versioninfo=('', '', ''), machine='')</code> </dt> <dd>
<p>Get macOS version information and return it as tuple <code>(release, versioninfo,
machine)</code> with <em>versioninfo</em> being a tuple <code>(version, dev_stage,
non_release_version)</code>.</p> <p>Entries which cannot be determined are set to <code>''</code>. All tuple entries are strings.</p> </dd>
</dl> </section> <section id="unix-platforms"> <h2>Unix Platforms</h2> <dl class="py function"> <dt class="sig sig-object py" id="platform.libc_ver">
<code>platform.libc_ver(executable=sys.executable, lib='', version='', chunksize=16384)</code> </dt> <dd>
<p>Tries to determine the libc version against which the file executable (defaults to the Python interpreter) is linked. Returns a tuple of strings <code>(lib,
version)</code> which default to the given parameters in case the lookup fails.</p> <p>Note that this function has intimate knowledge of how different libc versions add symbols to the executable is probably only usable for executables compiled using <strong class="program">gcc</strong>.</p> <p>The file is read and scanned in chunks of <em>chunksize</em> bytes.</p> </dd>
</dl> </section> <section id="linux-platforms"> <h2>Linux Platforms</h2> <dl class="py function"> <dt class="sig sig-object py" id="platform.freedesktop_os_release">
<code>platform.freedesktop_os_release()</code> </dt> <dd>
<p>Get operating system identification from <code>os-release</code> file and return it as a dict. The <code>os-release</code> file is a <a class="reference external" href="https://www.freedesktop.org/software/systemd/man/os-release.html">freedesktop.org standard</a> and is available in most Linux distributions. A noticeable exception is Android and Android-based distributions.</p> <p>Raises <a class="reference internal" href="exceptions#OSError" title="OSError"><code>OSError</code></a> or subclass when neither <code>/etc/os-release</code> nor <code>/usr/lib/os-release</code> can be read.</p> <p>On success, the function returns a dictionary where keys and values are strings. Values have their special characters like <code>"</code> and <code>$</code> unquoted. The fields <code>NAME</code>, <code>ID</code>, and <code>PRETTY_NAME</code> are always defined according to the standard. All other fields are optional. Vendors may include additional fields.</p> <p>Note that fields like <code>NAME</code>, <code>VERSION</code>, and <code>VARIANT</code> are strings suitable for presentation to users. Programs should use fields like <code>ID</code>, <code>ID_LIKE</code>, <code>VERSION_ID</code>, or <code>VARIANT_ID</code> to identify Linux distributions.</p> <p>Example:</p> <pre data-language="python">def get_like_distro():
    info = platform.freedesktop_os_release()
    ids = [info["ID"]]
    if "ID_LIKE" in info:
        # ids are space separated and ordered by precedence
        ids.extend(info["ID_LIKE"].split())
    return ids
</pre> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
</dl> </section> <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/library/platform.html" class="_attribution-link">https://docs.python.org/3.12/library/platform.html</a>
  </p>
</div>