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 crimson-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)
Output:
class MyFunctionInputProps(BaseModel):
arg1: int = Field(...)
arg2: str = Field(default="'default'")
def __init__(self, arg1: int, arg2: str='default'):
super().__init__(arg1=arg1, arg2=arg2)
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)
Output:
class MyFunctionOutputProps(BaseModel):
return: str
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")
Validation Error:
ValidationError: 1 validation error for MyFunctionInputProps
arg1
Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='not an int', input_type=str]
For further information visit https://errors.pydantic.dev/2.8/v/int_parsing
Metadata
Release files for crimson-auto-pydantic 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crimson_auto_pydantic-0.1.9.tar.gz | 7.9 kB | Without provenance | Details for crimson_auto_pydantic-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crimson_auto_pydantic-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for crimson_auto_pydantic-0.1.9-py3-none-any.whl |
Total release size: 16.1 kB
Release files / crimson_auto_pydantic-0.1.9.tar.gz
| Download URL | crimson_auto_pydantic-0.1.9.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b06568f2fccb5cec3f49d4147c0efd7a00ac691b485407eee5aeac784c20fa40
|
|
BLAKE2b-256 checksum How to use checksums |
487bc202d83ed6f2638e844c11a32f33c219be43d9cef9893c70d177f68e6b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Release files / crimson_auto_pydantic-0.1.9-py3-none-any.whl
| Download URL | crimson_auto_pydantic-0.1.9-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8bf9f6719af3a0478e759dd6e1ed8f6a13c217ccc9c05121b0b616c2a290309
|
|
BLAKE2b-256 checksum How to use checksums |
e0b5441ea5318b1a0971a4e9c45141377691484697618f4f45d41ffbefabc998
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for crimson-auto-pydantic 0.1.9
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.