hbutils.system.python.implementation
Python implementation detection utilities.
This module provides lightweight helpers to detect the active Python
implementation (such as CPython, PyPy, IronPython, or Jython). It exposes
an PythonImplementation enumeration for normalized representation
and a set of convenience predicate functions for common checks. Detection
is based on platform.python_implementation() and the result is cached
for performance.
The module contains the following main components:
PythonImplementation- Enumeration of supported implementationsis_cpython()- Predicate for CPython detectionis_ironpython()- Predicate for IronPython detectionis_jython()- Predicate for Jython detectionis_pypy()- Predicate for PyPy detection
Example:
>>> from hbutils.system.python.implementation import is_cpython, is_pypy
>>> if is_cpython():
... print("Running on CPython")
>>> if is_pypy():
... print("Running on PyPy")
__all__
- hbutils.system.python.implementation.__all__ = ['is_cpython', 'is_ironpython', 'is_jython', 'is_pypy']
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
PythonImplementation
- class hbutils.system.python.implementation.PythonImplementation(value)[source]
Enumeration of Python implementations.
This enum represents the different Python implementations that can be detected. The enum values are loaded from string names (case-insensitive) via the
hbutils.model.enum.int_enum_loads()decorator.- Variables:
CPYTHON – The standard CPython implementation.
IRONPYTHON – The IronPython implementation (.NET-based).
JYTHON – The Jython implementation (JVM-based).
PYPY – The PyPy implementation (JIT-compiled).
Example:
>>> PythonImplementation.loads('cpython') <PythonImplementation.CPYTHON: 1> >>> PythonImplementation.loads('PyPy') <PythonImplementation.PYPY: 4>