87

Python has a few different implementations: CPython, Jython, PyPy, etc. I want to programmatically determine which implementation my code is running on. How can I do that?

To be specific, I'm looking for a function, say, get_implementation_name(), that could be used like so:

impl_name = get_implementation_name() if impl_name == "CPython": print "I can abuse CPython implementation details. (I'm a bad, bad man.)" elif impl_name == "PyPy": print "Can't count on reference-counting garbage collection here..." else: print "I better be careful..." 
0

2 Answers 2

158
In [50]: import platform In [52]: platform.python_implementation() Out[52]: 'CPython' 

Docs: platform.python_implementation

Sign up to request clarification or add additional context in comments.

Comments

18

How about platform

it gives you

platform.python_implementation() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.