Skip to main content

A small Python library to seamlessly introspect interpreter features at runtime

Project description

runtime_introspect

PyPI Supported Python Versions uv

A small Python library to introspect interpreter features in a couple of portable lines of code. The core functionality is to produce diagnostics for which optional features are (un)available, the state they are in (enabled, disabled, active, or inactive), and why. It utilizes implementation specific APIs to abstract away the pain of writing portable code that runs on any configuration.

Scope and development status

This project is currently in alpha, with a flexible scope; Only CPython interpreter features (Free-threading and JIT) are supported at the moment. However, the library design leaves open the possibility to add support for other Python implementations. If you spot something missing please open a feature request or a pull request, contributions are always welcome !

Installation

python -m pip install runtime-introspect

Usage

Create diagnostics

Here's how to produce a complete diagnostic

from runtime_introspect import runtime_feature_set

fs = runtime_feature_set()
print("\n".join(fs.diagnostics()))

example output:

free-threading: unavailable (this interpreter was built without free-threading support)
JIT: disabled (envvar PYTHON_JIT is unset)
py-limited-api: available

Since runtime-introspect 0.3.0, FeatureSet.snapshot and FeatureSet.diagnostics will also accept a features list to fine-tune exactly which features to inspect and report on.

Inspect specific features

To make code conditional on the availability of a specific feature, use FeatureSet.supports. For instance

from runtime_introspect import runtime_feature_set

fs = runtime_feature_set()
if fs.supports("free-threading"):
    ... # cool multi-threading stuff
else:
    ... # also cool, but single-threaded stuff

As of runtime-introspect 0.2.0, supported feature names include 'free-threading', 'JIT' and 'py-limited-api'.

Build a pytest header

You can use this library to customize pytest so that test session headers showcase the runtime feature set at startup. For instance

# conftest.py
import sys
import textwrap
from runtime_introspect import runtime_feature_set

# ...

def pytest_report_header(config, start_path) -> list[str]:
    fs = runtime_feature_set()
    if diagnostics := fs.diagnostics():
        return [
            "Runtime optional features state (snapshot):",
            textwrap.indent("\n".join(diagnostics), "  "),
        ]
    else:
        return []

example output (truncated)

===================================== test session starts ======================================
platform darwin -- Python 3.13.6, pytest-8.4.1, pluggy-1.6.0
Runtime optional features state (snapshot):
  free-threading: unavailable (this interpreter was built without free-threading support)
  JIT: undetermined (no introspection API known for Python 3.13)
  py-limited-api: available
...

Command Line Interface (CLI) examples

Outputs may (really, should) vary depending on which python interpreter is active and how it was invoked

❯ python3.13 -m runtime_introspect
free-threading: unavailable (this interpreter was built without free-threading support)
JIT: undetermined (no introspection API known for Python 3.13)
py-limited-api: available
❯ PYTHON_JIT=1 python3.14 -m runtime_introspect
free-threading: unavailable (this interpreter was built without free-threading support)
JIT: enabled (by envvar PYTHON_JIT=1)
py-limited-api: available
❯ python3.14t -X gil=0 -m runtime_introspect
free-threading: enabled (forced by command line option -Xgil=0)
JIT: unavailable (this interpreter was built without JIT compilation support)
py-limited-api: unavailable (Python 3.14t and earlier free-threaded builds do not support py-limited-api)

Run python -m runtime_introspect --help to browse additional options.

Additional resources

Many more details can be inspected with the standard library sysconfig CLI (python -m sysconfig).

Also refer to python-introspection for a similar tool with a different approach and focus.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runtime_introspect-0.3.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

runtime_introspect-0.3.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file runtime_introspect-0.3.0.tar.gz.

File metadata

  • Download URL: runtime_introspect-0.3.0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for runtime_introspect-0.3.0.tar.gz
Algorithm Hash digest
SHA256 86f8a222f9622a7f8476f1c8e8ea198f3ae25a1ee15aab6685cbdb99059561c5
MD5 8753a7bd6ed1c1fe91933168ebfad817
BLAKE2b-256 92b4658b75ed32005cd687ea0d868cebf57b595f817d4f67494441c053da9002

See more details on using hashes here.

Provenance

The following attestation bundles were made for runtime_introspect-0.3.0.tar.gz:

Publisher: cd.yml on neutrinoceros/runtime-introspect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file runtime_introspect-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for runtime_introspect-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e38f53aab3a450499d09c9603689f2a2ca1827c1fc0fd6d136e4360353cbea63
MD5 ad4f572e38ffbedead26ffd1af21096f
BLAKE2b-256 d1f2cac39d9077a0f4e11d12a7303c99a094b22b0ca5f8a426ac2a9f65aeaa9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for runtime_introspect-0.3.0-py3-none-any.whl:

Publisher: cd.yml on neutrinoceros/runtime-introspect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page