Skip to main content

version: 0.1.0

Func Analyzer

A Python library for dynamic function analysis, schema generation, and CLI integration.

Features

  • Dynamic Pydantic Model Generation: Automatically create Pydantic models from function signatures
  • Intelligent Annotation Cleaning: Convert complex type annotations to clean, readable strings
  • Docstring Parsing: Extract parameter descriptions from Google, NumPy, and Sphinx docstring styles
  • CLI-Ready Metadata: Generate comprehensive function metadata for CLI auto-generation
  • Schema Generation: Create JSON schemas from function signatures with descriptions

Installation

# From local development
pip install -e .

# Or clone and install
git clone https://github.com/crimson206/func-analyzer
cd func-analyzer
pip install -e .

Quick Start

Basic Function Analysis

from func_analyzer import analyze_function

def sample_user_info(name: str, age: int, email: str = None, active: bool = True) -> dict:
    """
    Create user information dictionary.
    
    Args:
        name: User's full name
        age: User's age in years
        email: User's email address (optional)
        active: Whether user account is active
        
    Returns:
        Dictionary containing user information
    """
    return {"name": name, "age": age, "email": email, "active": active}

# Analyze function
info = analyze_function(sample_user_info)
print(info)

Dynamic Model Generation

from func_analyzer import create_function_model

# Create Pydantic model from function
UserModel = create_function_model(sample_user_info)

# Use the model
user_data = UserModel(name="John Doe", age=30, email="john@example.com")
print(user_data.model_dump())

Annotation Cleaning

from func_analyzer import clean_annotation_string

# Clean complex annotations
annotations = [
    "typing.List[str]",
    "typing.Optional[typing.Dict[str, typing.Any]]",
    "<class 'str'>",
    "Union[str, int, float]"
]

for annotation in annotations:
    cleaned = clean_annotation_string(annotation)
    print(f"{annotation} -> {cleaned}")

Core Components

Function Analysis

The analyze_function() function extracts comprehensive metadata:

  • Function name and module
  • Parameter information (name, type, default, description)
  • Return type annotation
  • Docstring content
  • Async/generator status

Dynamic Model Creation

create_function_model() generates Pydantic models with:

  • Type annotations from function signature
  • Parameter descriptions from docstrings
  • Default values
  • Field validation

Annotation Cleaning

clean_annotation_string() handles:

  • typing. prefix removal
  • <class 'type'> string conversion
  • Complex nested type simplification
  • Union type formatting

Examples

See the examples/ directory for comprehensive usage examples:

  • example_basic_analysis.py - Basic function analysis
  • example_annotation_cleaning.py - Annotation cleaning with tests
  • example_docstring_parsing.py - Docstring parsing examples

CLI Integration

The extracted metadata is designed for CLI auto-generation:

# Example CLI generation data
{
    'name': 'sample_user_info',
    'parameters': [
        {
            'name': 'name',
            'annotation': 'str',
            'description': "User's full name",
            'default': None
        },
        {
            'name': 'age', 
            'annotation': 'int',
            'description': "User's age in years",
            'default': None
        }
    ]
}

Development

Running Examples

# Run all examples
cd examples
python example_basic_analysis.py
python example_annotation_cleaning.py

Testing

# Run tests
python -m pytest tests/

License

MIT License

Metadata

Release files for func-analyzer 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for func-analyzer 0.1.1
File Size Uploaded Provenance Actions
func_analyzer-0.1.1.tar.gz 6.9 kB Without provenance Details for func_analyzer-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for func-analyzer 0.1.1
File Interpreter ABI Platform Actions
func_analyzer-0.1.1-py3-none-any.whl Python 3 none any Details for func_analyzer-0.1.1-py3-none-any.whl

Total release size: 14.4 kB

Release files / func_analyzer-0.1.1.tar.gz

Download URL func_analyzer-0.1.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
596dc97ba4dbace9410fafb64c5a95a4c37e01a0b42a21a7f0af2a305402f105
BLAKE2b-256 checksum
How to use checksums
1272d5c357a209ccb92330aa1f3313e3238179aea71960795c13521537d663b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release files / func_analyzer-0.1.1-py3-none-any.whl

Download URL func_analyzer-0.1.1-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c074656af5adea2f028a2d7b80756ab02395c25d446bf16098e62ec2ecc4fa1
BLAKE2b-256 checksum
How to use checksums
e659636837af75b413a01bb484262748680e7c526a934d219be0cea5ff1c32ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Security for func-analyzer 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page