Skip to main content

Introspection and stack-walking utilities for the simplibs ecosystem.

Project description

simplibs-introspection

Diagnostic and structural inspection tools for the simplibs ecosystem — safe, non-crashing tools for understanding the runtime state.

Python Licence PyPI


Contents


Installation

pip install simplibs-introspection

Why introspection?

In complex systems, a function often needs to know who called it or from which file execution originated — typically for logging, defensive error handling, or dynamic configuration.

Python's inspect module is powerful but can be heavy and prone to raising exceptions if the stack is not as expected. simplibs-introspection provides a defensive wrapper that prioritises stability: it either gives you the data you need or returns None, but it never crashes your program.


Stack Frames

Tools for examining the Python call stack and execution frames.

extract_caller_info

Walks the call stack and returns info about the first relevant frame. It automatically skips internal Python frames and allows you to filter out specific parts of your own codebase.

from simplibs.introspection import extract_caller_info

# Basic usage
info = extract_caller_info()

if info:
    print(f"Called from {info['function']} in {info['file']} at line {info['line']}")
    # Output: Called from my_function in logic.py at line 42

Advanced filtering

You can skip a specific number of frames or exclude files whose paths contain certain strings (e.g., when building a wrapper library where you want to skip the wrapper's own frames).

info = extract_caller_info(
    skip_frames=1, 
    excluded_patterns=("my_internal_tool", "decorators")
)

Key features:

  • Performance: Uses context=0 to avoid reading source files from disk.
  • Cleanliness: Automatically filters out dynamic frames like <string> or <frozen importlib>.
  • Safety: Wrapped in a total try/except block — guaranteed not to raise.

About the simplibs ecosystem

simplibs-introspection is part of the simplibs ecosystem — a collection of small, self-contained Python libraries. Each one solves exactly one thing — but all of them share a common philosophy:

Dyslexia-friendly — minimise mental load. Atomise code into self-contained units, name files after the logic they contain, write explanations that describe why — not just what.

Programmer's zen — nothing should be missing and nothing should be superfluous. The journey is the destination: code should be fully understood; better to go slowly and correctly than quickly and with mistakes. The crystallisation approach — not perfection on the first try, but gradual refinement towards it.

Defensive style — anticipate all possible failure modes so that only safe paths remain. Never raise unexpected errors; degrade gracefully.

Minimalism — find the path to the goal in as few steps as possible, but leave nothing out. Each file has one responsibility.

Code as craft — code should be pleasant to look at and evoke a sense of harmony. Treat code as a small work of art — like a carpenter carving a sculpture. Optimise for the user: everything should make sense without having to study the documentation at length.

These are aspirations — a sense of direction. And that is exactly what the note about the journey becoming the destination is all about. 🙂


The library is covered by tests across all modules. Tests are part of the repository and serve as living documentation of the expected behaviour.

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

simplibs_introspection-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

simplibs_introspection-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file simplibs_introspection-0.1.0.tar.gz.

File metadata

  • Download URL: simplibs_introspection-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for simplibs_introspection-0.1.0.tar.gz
Algorithm Hash digest
SHA256 091ee178d876810778a6f76cf703fc8c5667edf7f274c5f9ce0dedc99922a581
MD5 16a593161d8ba5063038535a404b2021
BLAKE2b-256 0faf223f7ce097f04d95b9dda85cca8b9111c6d355e47673c02e685138f09b04

See more details on using hashes here.

File details

Details for the file simplibs_introspection-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simplibs_introspection-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 218f32736a8983b4977a3da5432d3dade4840542fa7d16370f4645780beca57e
MD5 287f99dc3c0421c8af898c61adfa6ea1
BLAKE2b-256 0c5e8502129d875b592907e25e2176d6b42f3ff00e8b22e9776b1cc9ba65b64a

See more details on using hashes here.

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