Skip to main content

Pure Python introspection toolkit for function signatures, dataclasses, and type hints

Project description

python-introspect

Pure Python introspection toolkit for function signatures, dataclasses, and type hints

Python 3.9+ License: MIT CI PyPI version

Features

  • 🔍 Function/Method Signature Analysis - Extract parameter info from any callable
  • 📦 Dataclass Field Extraction - Analyze dataclass fields and types
  • 📝 Docstring Parsing - Extract and parse docstrings (Google, NumPy, Sphinx styles)
  • 🏷️ Type Hint Resolution - Resolve complex type hints and annotations
  • 🎯 Unified API - Single interface for all parameter sources
  • 🚀 Pure Python - No external dependencies, pure stdlib

Installation

pip install python-introspect

Quick Start

from python_introspect import SignatureAnalyzer

def example_function(name: str, age: int = 25, *, active: bool = True):
    """
    Example function with parameters.
    
    Args:
        name: The person's name
        age: The person's age
        active: Whether the person is active
    """
    pass

# Analyze the function
analyzer = SignatureAnalyzer()
params = analyzer.analyze_function(example_function)

for param in params:
    print(f"{param.name}: {param.annotation} = {param.default}")

Use Cases

  • Form Generation - Generate UI forms from function signatures
  • API Documentation - Auto-generate API docs from code
  • Configuration Validation - Validate config against function parameters
  • Dynamic UI - Build dynamic UIs based on function signatures
  • Parameter Analysis - Analyze and validate function parameters

Documentation

Full documentation available at: https://github.com/trissim/python-introspect

Development

Setup

# Clone the repository
git clone https://github.com/trissim/python-introspect.git
cd python-introspect

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode with dev dependencies
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest tests/

# Run with coverage
pytest tests/ --cov=python_introspect --cov-report=term --cov-report=html

# Run linting and formatting checks
ruff check src/ tests/
black --check src/ tests/
mypy src/python_introspect/

Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

Credits

Developed by Tristan Simas as part of the OpenHCS project.

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

python_introspect-0.1.4.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

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

python_introspect-0.1.4-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file python_introspect-0.1.4.tar.gz.

File metadata

  • Download URL: python_introspect-0.1.4.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for python_introspect-0.1.4.tar.gz
Algorithm Hash digest
SHA256 74d0b32be1176b2d45d82a16f6989bf855cac38c2269a247aeae605344c52828
MD5 20b9342b9994a723e253445867cf29e1
BLAKE2b-256 27c2ad3d1fd57b9a531c360896ac07552ef25e9997405601dbd66bcb4e95464d

See more details on using hashes here.

File details

Details for the file python_introspect-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for python_introspect-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 461a5c07d04080c40619f870f72053ff3e589c1205cbc9b3533a7fb1f352e3a0
MD5 9fe34545a6d477e763179d70fd6a4f17
BLAKE2b-256 d167baefe3e860a8aec9304eece15e7069e7cdc10800ae416c99c446a48a9c4a

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