Skip to main content

Automatic Pydantic model generation and validation for function parameters and return types.

Project description

auto-pydantic

  • Author : Sonnet3.5
  • Editor : Sisung Kim

auto-pydantic is a Python module that provides automatic Pydantic model generation and validation for function parameters and return types.

Features

  • Generate Pydantic input models from function signatures
  • Generate Pydantic output models from function return types
  • Automatic validation of function inputs using generated Pydantic models
  • Support for simple and complex function signatures, including *args and **kwargs

Installation

To install crimson-auto-pydantic, you can use pip:

pip install acrimson-auto-pydantic

Usage

Generating Input Props

from crimson.auto_pydantic.generator import generate_input_props

def my_function(arg1: int, arg2: str = "default") -> str:
    return f"{arg1} {arg2}"

input_props = generate_input_props(my_function)
print(input_props)

Generating Output Props

from crimson.auto_pydantic.generator import generate_output_props

def my_function(arg1: int, arg2: str = "default") -> str:
    return f"{arg1} {arg2}"

output_props = generate_output_props(my_function)
print(output_props)

Validating Function Inputs

from crimson.auto_pydantic.validator import validate
from inspect import currentframe

def my_function(arg1: int, arg2: str = "default") -> str:
    validate(my_function, currentframe(), arg1, arg2)
    return f"{arg1} {arg2}"

# This will pass validation
my_function(1, "test")

# This will raise a validation error
my_function("not an int", "test")

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

crimson_auto_pydantic-0.1.8.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

crimson_auto_pydantic-0.1.8-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file crimson_auto_pydantic-0.1.8.tar.gz.

File metadata

  • Download URL: crimson_auto_pydantic-0.1.8.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for crimson_auto_pydantic-0.1.8.tar.gz
Algorithm Hash digest
SHA256 c9467e57b1c525908b8d807bf4ecc2ae49608b795447dc45e9e95fcd46fa7dd7
MD5 7c9b143dd33efaeb3023457a472fdc8e
BLAKE2b-256 155163bf7c67752d9836c2557ae064627d7c9f7ba1aeafd51bf5581c7c4a535a

See more details on using hashes here.

File details

Details for the file crimson_auto_pydantic-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for crimson_auto_pydantic-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 cdafdb99b7b3987c9449071c7d28b2ae1d1c8311c8ffdcae29a6803e0e94b805
MD5 0384b835cf53f1d44deb2587b51df37a
BLAKE2b-256 364bec86e0ce1a57c5064aacce245f5c7b2f87ee4d3ff57692eb3434ee451e43

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page