Skip to main content

A tool to derive parameter information from Python functions and classes for contract generation.

Project description

SigScaffold

A lightweight Python tool to derive structured information from the signatures of functions and classes.

SigScaffold inspects any callable (like a function or a class constructor) and extracts details about its parameters, including their names, types, and default values. This is particularly useful for automatically generating documentation, configuration files, or API contracts.

Features

  • Get parameter names and their type annotations.
  • Recursively inspect signatures of class-based parameters.
  • Identify which parameters are required.
  • Generate sensible default values for all parameters.
  • No external dependencies.

Installation

pip install sig-scaffold

Usage

Here is a quick example of how to use SigScaffold:

from sig_scaffold import SigScaffold

# -- Define a class to inspect ---
class DatabaseConfig:
    def __init__(self, host: str, port: int = 5432):
        self.host = host
        self.port = port

def connect(db_config: DatabaseConfig, timeout: int = 30):
    """Connects to a database with the given configuration."""
    pass

# -- Use SigScaffold ---

# 1. Inspect the 'connect' function
scaffold = SigScaffold(connect)

# 2. Get parameter types (with recursion)
# This will look inside the DatabaseConfig class as well.
param_types = scaffold.get_param_types(recursive=True)
print("Parameter Types:")
# Expected output:
# {
#   'db_config': {'host': <class 'str'>, 'port': <class 'int'>},
#   'timeout': <class 'int'>
# }
import json
print(json.dumps(
    {k: str(v) for k, v in param_types.items()},
    indent=2
))


# 3. Get only the required parameters
required = scaffold.get_required_params()
print(f"\nRequired Parameters: {required}")
# Expected output: ['db_config']

# 4. Generate default values for all parameters
defaults = scaffold.generate_defaults()
print(f"\nGenerated Defaults: {defaults}")
# Expected output: {'db_config': '', 'timeout': 30}

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

sigscaffold-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

sigscaffold-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sigscaffold-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for sigscaffold-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e6b082f03c060cdabc5095a33907acaf8ca0838f6503222cb302e6997135839d
MD5 fbc33fd8fa248f4c03f5f3130a27449a
BLAKE2b-256 6e9124aeedc832fa3c2c34cfb845c0cd407af356d222652d411f60502ddcb880

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sigscaffold-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for sigscaffold-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d84ff4b21dde2298b7c802534595d7dc649c8ca337527f028f2b338bd1c1528d
MD5 babc596294f627715feec1dacd378451
BLAKE2b-256 1d2efe8043483b2124eaf77309a176c4c07d1153fa9b117e501cd83b3e428a8a

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