Skip to main content

Pydantic Function Models

uv PyPI Supported Python versions License pre-commit.ci status

A library to model Python function signatures using Pydantic, inspired by the now-deprecated ValidatedFunction from Pydantic v1. This package helps validate function arguments according to type hints, bridging the gap between Pydantic v1 and v2.

Installation

pip install pydantic-function-models

Features

  • Signature modelling: Wrap any Python function to model its signature (positional, keyword, etc.) using Pydantic. Note that if you are after just validation (whether the arguments are valid) then you want validate call
  • Painless migration from Pydantic v1: Provides a ValidatedFunction class ported to v2, for those who relied on ValidatedFunction in v1.
  • Clear error messages: Raises Pydantic ValidationError with helpful details if input arguments do not match the declared types.
  • Reserved name checks: Prevents usage of special parameter names (e.g., v__args, v__kwargs) that could conflict with internal validation logic.

Usage

Below is a general overview of how to use pydantic-function-models in your own code.

Example: Basic Validated Function

from pydantic_function_models import ValidatedFunction

def add(a: int, b: int) -> int:
    return a + b

vf = ValidatedFunction(add)

# Build arguments for validation
args_to_validate = (1,)
kwargs_to_validate = {"b": 2}

validated = vf.model.model_validate({
    "a": args_to_validate[0],
    "b": kwargs_to_validate["b"]
})
result = add(**validated.model_dump(exclude_unset=True))

print(result)  # 3

Here, ValidatedFunction creates an internal Pydantic model that enforces integer values for a and b. If you passed a string for a or b, it would raise a ValidationError.

Library Usage

Internally, each ValidatedFunction builds a Pydantic model representing the function’s signature. When you call .model.model_validate(...) or .build_values(...), it validates the provided arguments (whether positional or keyword-based) against the signature.


Project Structure

Take a look at the internals here:

  • validated_function.py: Core logic for ValidatedFunction, which encapsulates argument validation and Pydantic model generation.
  • parameters.py: Model definitions for function parameters/signatures, with checks for reserved argument names.

Contributing

Maintained by lmmx. Contributions are welcome!

  1. Issues & Discussions: Please open a GitHub issue or discussion for bugs, feature requests, or questions.
  2. Pull Requests: PRs are welcome!
    • Install the dev extra (e.g. with uv: uv pip install -e .[dev])
    • Run tests (e.g. pytest) and include updates to docs or examples if relevant.
    • If reporting a bug, please include the version and error message/traceback if available.

License

This project is licensed under the MIT License.

Metadata

Release files for pydantic-function-models 0.1.12

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

Source distribution (sdist)

Source distribution for pydantic-function-models 0.1.12
File Size Uploaded
pydantic_function_models-0.1.12.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-function-models 0.1.12
File Interpreter ABI Platform
pydantic_function_models-0.1.12-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / pydantic_function_models-0.1.12.tar.gz

Download URL pydantic_function_models-0.1.12.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
530964fe7d77a3e153a7394bd4a6b1bbd7aa4bdfc7bc1420e58ebf815a527175
BLAKE2b-256 checksum
How to use checksums
1ad76afa9458be0e522b9332995cf15afacda5bdd081efe2965812d16b251cf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.

Transparency log

Release files / pydantic_function_models-0.1.12-py3-none-any.whl

Download URL pydantic_function_models-0.1.12-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef009e84000870770579895c490be7397f900112ba7a36bed5d0e5b98ea4f108
BLAKE2b-256 checksum
How to use checksums
fbcacc63a2ad7ddd490f77c59e37e2e88d8ad2a39bdaa8588101082b94359333
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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