Skip to main content

Runtime reflection (lite)

Project description

Test Coverage Stable Version Pre-release Version PyPI - Python Version PyPI Downloads

Runtime Reflection Lite

Lightweight runtime reflection for Python — with proper type awareness.

🚀 Why this exists

Python has powerful introspection capabilities, but working with them in practice can be messy:

  • Type hints are not always resolved
  • Metadata is scattered across different APIs
  • Understanding structure at runtime requires a lot of boilerplate

This library provides a clean and consistent abstraction layer for inspecting Python code at runtime.

👉 The goal is simple: Make runtime structure easy to access, understand, and use

✨ Features

  • 🔍 Inspect modules, classes, and functions
  • 🧠 Resolve type hints (including forward references)
  • 🔐 Understand encapsulation and structure
  • ⚡ Lightweight implementation (no source code parsing)
  • 🧩 Clean API for building higher-level tooling

📦 Use cases

This library is especially useful when building:

  • Frameworks
  • Dependency injection systems
  • Code analysis tools
  • Runtime validation systems
  • Developer tooling

👉 If you're working with dynamic architectures, this removes a lot of friction.

🏗 Design philosophy

Unlike heavier reflection systems, this project deliberately avoids:

  • ❌ Parsing source code
  • ❌ Full AST inspection

This keeps it:

✅ Fast ✅ Predictable ✅ Easy to integrate

⚙️ Example

from runtime.reflection.lite import MemberFilter, MemberInfo, Class, Method, reflect, get_signature, get_members

class Class1:
     def __init__(self, value: str):
          self.__value = value

     def do_something(self, suffix: str | None = None) -> str:
          return self.__value + (suffix or "")

reflection: Class = reflect(Class1)
reflection.constructor.signature # -> (value: str)
member_info, method = reflection.members.subset_methods()["do_something"] # -> tuple[MemberInfo, Method]

signature1 = get_signature(Class1.do_something) # -> (suffix: str | None) -> str
signature2 = get_signature(Class1.__init__) # -> (value: str)

members = get_members(Class1, filter = MemberFilter.FUNCTIONS_AND_METHODS)
member_info, member = members["do_something"] # -> MemberInfo, Member

Full documentation

Go to documentation

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_reflection_lite-0.2.1.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

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

runtime_reflection_lite-0.2.1-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file runtime_reflection_lite-0.2.1.tar.gz.

File metadata

  • Download URL: runtime_reflection_lite-0.2.1.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for runtime_reflection_lite-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8d23a71e1c0aab1eb600808d39827cce30d287ea4cf9238b0e3db397def9cc66
MD5 6568128bddbd62e1767b6dee553443a5
BLAKE2b-256 0491b2128f579c244ca5c5118ceaf2f6f1965a256d5d9796837b141e48c38896

See more details on using hashes here.

Provenance

The following attestation bundles were made for runtime_reflection_lite-0.2.1.tar.gz:

Publisher: python-publish.yml on apmadsen/runtime-reflection-lite

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_reflection_lite-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for runtime_reflection_lite-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc8d6184207b87689092a75f4f8616e312f98148c174e846411e1f6c333851e9
MD5 a9dfca76d25f2088d78a306a35aff940
BLAKE2b-256 0bc87ee8bd7ddce7930ea4ecc11678eb52df43630edf0bf85a9cb488b8c6023d

See more details on using hashes here.

Provenance

The following attestation bundles were made for runtime_reflection_lite-0.2.1-py3-none-any.whl:

Publisher: python-publish.yml on apmadsen/runtime-reflection-lite

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