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:

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>

is_cpython

hbutils.system.python.implementation.is_cpython() bool[source]

Check if the current Python implementation is CPython.

Returns:

True if the current Python implementation is CPython, otherwise False.

Return type:

bool

Example:

>>> is_cpython()
True  # When running on CPython

is_ironpython

hbutils.system.python.implementation.is_ironpython() bool[source]

Check if the current Python implementation is IronPython.

Returns:

True if the current Python implementation is IronPython, otherwise False.

Return type:

bool

Example:

>>> is_ironpython()
False  # When running on CPython

is_jython

hbutils.system.python.implementation.is_jython() bool[source]

Check if the current Python implementation is Jython.

Returns:

True if the current Python implementation is Jython, otherwise False.

Return type:

bool

Example:

>>> is_jython()
False  # When running on CPython

is_pypy

hbutils.system.python.implementation.is_pypy() bool[source]

Check if the current Python implementation is PyPy.

Returns:

True if the current Python implementation is PyPy, otherwise False.

Return type:

bool

Example:

>>> is_pypy()
False  # When running on CPython