pycpuid: CPUID for Python
pycpuid is a very simple Python extension. It reads the information available from the CPUID assembly instruction, and makes it available to any Python program. I needed it to decide on some codepath based on whether the box supported SSE2. In particular, I needed to know if I could import an extension module that was optimized with SSE2
import pycpuid
if pycpuid.HAS_SSE2EX:
import foobar_sse2 as foobar
else:
import foobar
I didn’t found anything alike, so I coded it myself. And here it is for the rest of you …
using it
There’s not much to it, really. pycpuid is just a bunch of module constants. Just import the module and access the constants. the HAS_FOOBARs are Boolean flags to indicate whether the feature is available. The constant features is a string that lists all the available features.
import pycpuid print "has SSE2:", pycpuid.HAS_SSE2EX print "all availabe features:", pycpuid.features
subversion repository
download
building and installing
There’s two simple steps to it:
- Unpack the source code into a temporary directory, or grab it from the repository
- Enter
setup.py installon the command line. If you’re doing this on a Windows box and things freak out because you don’t have a C++ compiler installed or properly configured, you might be interested in my five little steps how to use the Visual C++ 2005 Express compiler (which is availabe for free!)
license
pycpuid is licensed under the GNU Lesser General Public License (LGPL) so that you can import pycpuid in your Python code without it imposing any license restrictions on your code.



