blob: 069993c36922447241a2e9d7920e460017e3f41e [file] [log] [blame]
Georg Brandl42a82642009-06-08 07:57:35 +00001:mod:`platform` --- Access to underlying platform's identifying data
2=====================================================================
Georg Brandl8ec7f652007-08-15 14:28:01 +00003
4.. module:: platform
5 :synopsis: Retrieves as much platform identifying data as possible.
6.. moduleauthor:: Marc-Andre Lemburg <mal@egenix.com>
7.. sectionauthor:: Bjorn Pettersen <bpettersen@corp.fairisaac.com>
8
9
10.. versionadded:: 2.3
11
12.. note::
13
14 Specific platforms listed alphabetically, with Linux included in the Unix
15 section.
16
17
18Cross Platform
19--------------
20
21
22.. function:: architecture(executable=sys.executable, bits='', linkage='')
23
24 Queries the given executable (defaults to the Python interpreter binary) for
25 various architecture information.
26
27 Returns a tuple ``(bits, linkage)`` which contain information about the bit
28 architecture and the linkage format used for the executable. Both values are
29 returned as strings.
30
31 Values that cannot be determined are returned as given by the parameter presets.
32 If bits is given as ``''``, the :cfunc:`sizeof(pointer)` (or
33 :cfunc:`sizeof(long)` on Python version < 1.5.2) is used as indicator for the
34 supported pointer size.
35
36 The function relies on the system's :file:`file` command to do the actual work.
37 This is available on most if not all Unix platforms and some non-Unix platforms
38 and then only if the executable points to the Python interpreter. Reasonable
39 defaults are used when the above needs are not met.
40
Antoine Pitrou5cf36722010-12-21 18:56:45 +000041 .. note::
42
43 On Mac OS X (and perhaps other platforms), executable files may be
44 universal files containing multiple architectures.
45
46 To get at the "64-bitness" of the current interpreter, it is more
47 reliable to query the :attr:`sys.maxsize` attribute::
48
49 is_64bits = sys.maxsize > 2**32
50
Georg Brandl8ec7f652007-08-15 14:28:01 +000051
52.. function:: machine()
53
54 Returns the machine type, e.g. ``'i386'``. An empty string is returned if the
55 value cannot be determined.
56
57
58.. function:: node()
59
60 Returns the computer's network name (may not be fully qualified!). An empty
61 string is returned if the value cannot be determined.
62
63
64.. function:: platform(aliased=0, terse=0)
65
66 Returns a single string identifying the underlying platform with as much useful
67 information as possible.
68
69 The output is intended to be *human readable* rather than machine parseable. It
70 may look different on different platforms and this is intended.
71
72 If *aliased* is true, the function will use aliases for various platforms that
73 report system names which differ from their common names, for example SunOS will
74 be reported as Solaris. The :func:`system_alias` function is used to implement
75 this.
76
77 Setting *terse* to true causes the function to return only the absolute minimum
78 information needed to identify the platform.
79
80
81.. function:: processor()
82
83 Returns the (real) processor name, e.g. ``'amdk6'``.
84
85 An empty string is returned if the value cannot be determined. Note that many
86 platforms do not provide this information or simply return the same value as for
87 :func:`machine`. NetBSD does this.
88
89
90.. function:: python_build()
91
92 Returns a tuple ``(buildno, builddate)`` stating the Python build number and
93 date as strings.
94
95
96.. function:: python_compiler()
97
98 Returns a string identifying the compiler used for compiling Python.
99
100
101.. function:: python_branch()
102
103 Returns a string identifying the Python implementation SCM branch.
104
105 .. versionadded:: 2.6
106
107
108.. function:: python_implementation()
109
110 Returns a string identifying the Python implementation. Possible return values
Ezio Melotti001cc952011-05-03 20:41:48 +0300111 are: 'CPython', 'IronPython', 'Jython', 'PyPy'.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000112
113 .. versionadded:: 2.6
114
115
116.. function:: python_revision()
117
118 Returns a string identifying the Python implementation SCM revision.
119
120 .. versionadded:: 2.6
121
122
123.. function:: python_version()
124
125 Returns the Python version as string ``'major.minor.patchlevel'``
126
127 Note that unlike the Python ``sys.version``, the returned value will always
128 include the patchlevel (it defaults to 0).
129
130
131.. function:: python_version_tuple()
132
133 Returns the Python version as tuple ``(major, minor, patchlevel)`` of strings.
134
135 Note that unlike the Python ``sys.version``, the returned value will always
136 include the patchlevel (it defaults to ``'0'``).
137
138
139.. function:: release()
140
141 Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'`` An empty string is
142 returned if the value cannot be determined.
143
144
145.. function:: system()
146
147 Returns the system/OS name, e.g. ``'Linux'``, ``'Windows'``, or ``'Java'``. An
148 empty string is returned if the value cannot be determined.
149
150
151.. function:: system_alias(system, release, version)
152
153 Returns ``(system, release, version)`` aliased to common marketing names used
154 for some systems. It also does some reordering of the information in some cases
155 where it would otherwise cause confusion.
156
157
158.. function:: version()
159
160 Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
161 returned if the value cannot be determined.
162
163
164.. function:: uname()
165
166 Fairly portable uname interface. Returns a tuple of strings ``(system, node,
167 release, version, machine, processor)`` identifying the underlying platform.
168
169 Note that unlike the :func:`os.uname` function this also returns possible
170 processor information as additional tuple entry.
171
172 Entries which cannot be determined are set to ``''``.
173
174
175Java Platform
176-------------
177
178
179.. function:: java_ver(release='', vendor='', vminfo=('','',''), osinfo=('','',''))
180
Georg Brandl18187e22009-06-06 18:21:58 +0000181 Version interface for Jython.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000182
183 Returns a tuple ``(release, vendor, vminfo, osinfo)`` with *vminfo* being a
184 tuple ``(vm_name, vm_release, vm_vendor)`` and *osinfo* being a tuple
185 ``(os_name, os_version, os_arch)``. Values which cannot be determined are set to
186 the defaults given as parameters (which all default to ``''``).
187
188
189Windows Platform
190----------------
191
192
193.. function:: win32_ver(release='', version='', csd='', ptype='')
194
195 Get additional version information from the Windows Registry and return a tuple
196 ``(version, csd, ptype)`` referring to version number, CSD level and OS type
197 (multi/single processor).
198
199 As a hint: *ptype* is ``'Uniprocessor Free'`` on single processor NT machines
200 and ``'Multiprocessor Free'`` on multi processor machines. The *'Free'* refers
201 to the OS version being free of debugging code. It could also state *'Checked'*
202 which means the OS version uses debugging code, i.e. code that checks arguments,
203 ranges, etc.
204
205 .. note::
206
Antoine Pitrou5cf36722010-12-21 18:56:45 +0000207 This function works best with Mark Hammond's
Marc-André Lemburg53c7a602008-03-20 17:55:31 +0000208 :mod:`win32all` package installed, but also on Python 2.3 and
Marc-André Lemburg4e0c72b2008-03-20 18:58:14 +0000209 later (support for this was added in Python 2.6). It obviously
210 only runs on Win32 compatible platforms.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000211
212
213Win95/98 specific
214^^^^^^^^^^^^^^^^^
215
Georg Brandl8ec7f652007-08-15 14:28:01 +0000216.. function:: popen(cmd, mode='r', bufsize=None)
217
218 Portable :func:`popen` interface. Find a working popen implementation
219 preferring :func:`win32pipe.popen`. On Windows NT, :func:`win32pipe.popen`
220 should work; on Windows 9x it hangs due to bugs in the MS C library.
221
Georg Brandl8ec7f652007-08-15 14:28:01 +0000222
223Mac OS Platform
224---------------
225
226
227.. function:: mac_ver(release='', versioninfo=('','',''), machine='')
228
229 Get Mac OS version information and return it as tuple ``(release, versioninfo,
230 machine)`` with *versioninfo* being a tuple ``(version, dev_stage,
231 non_release_version)``.
232
233 Entries which cannot be determined are set to ``''``. All tuple entries are
234 strings.
235
Georg Brandl8ec7f652007-08-15 14:28:01 +0000236
237Unix Platforms
238--------------
239
240
Marc-André Lemburg53c7a602008-03-20 17:55:31 +0000241.. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...))
Georg Brandl8ec7f652007-08-15 14:28:01 +0000242
Marc-André Lemburg1d0b5cc2009-02-17 12:48:19 +0000243 This is an old version of the functionality now provided by
244 :func:`linux_distribution`. For new code, please use the
245 :func:`linux_distribution`.
246
247 The only difference between the two is that ``dist()`` always
248 returns the short name of the distribution taken from the
249 ``supported_dists`` parameter.
250
251 .. deprecated:: 2.6
Georg Brandl8ec7f652007-08-15 14:28:01 +0000252
Marc-André Lemburg53c7a602008-03-20 17:55:31 +0000253.. function:: linux_distribution(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...), full_distribution_name=1)
254
255 Tries to determine the name of the Linux OS distribution name.
256
Benjamin Peterson3e876fd2008-09-22 22:13:29 +0000257 ``supported_dists`` may be given to define the set of Linux distributions to
258 look for. It defaults to a list of currently supported Linux distributions
259 identified by their release file name.
Marc-André Lemburg53c7a602008-03-20 17:55:31 +0000260
Benjamin Peterson3e876fd2008-09-22 22:13:29 +0000261 If ``full_distribution_name`` is true (default), the full distribution read
262 from the OS is returned. Otherwise the short name taken from
263 ``supported_dists`` is used.
Marc-André Lemburg53c7a602008-03-20 17:55:31 +0000264
Benjamin Peterson3e876fd2008-09-22 22:13:29 +0000265 Returns a tuple ``(distname,version,id)`` which defaults to the args given as
266 parameters. ``id`` is the item in parentheses after the version number. It
267 is usually the version codename.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000268
Marc-André Lemburg1d0b5cc2009-02-17 12:48:19 +0000269 .. versionadded:: 2.6
270
Georg Brandl8ec7f652007-08-15 14:28:01 +0000271.. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048)
272
273 Tries to determine the libc version against which the file executable (defaults
274 to the Python interpreter) is linked. Returns a tuple of strings ``(lib,
275 version)`` which default to the given parameters in case the lookup fails.
276
277 Note that this function has intimate knowledge of how different libc versions
Georg Brandl907a7202008-02-22 12:31:45 +0000278 add symbols to the executable is probably only usable for executables compiled
Georg Brandl8ec7f652007-08-15 14:28:01 +0000279 using :program:`gcc`.
280
281 The file is read and scanned in chunks of *chunksize* bytes.
282