Skip to main content

This code simplifies the conversion of Pydantic schemas into Aiogram handler groups, making it easy to create form-filling handlers.

Project description

Pydantic-handler-converter

This code simplifies the conversion of Pydantic schemas into Aiogram handler groups, making it easy to create form-filling handlers.

Usage:

>>> from enum import Enum
>>> from pydantic import BaseModel
>>> from pydantic_handler_converter import BasePydanticFormHandlers
>>>
>>> # Simple datatypes schema 
>>> class PersonPydanticFormSchema(BaseModel):
...     name: str
...     age: int
...     height: float 
... 

>>> class PersonFormHanlders(BasePydanticFormHandlers[PersonPydanticFormSchema]): pass
>>> assert PersonFormHanlders.Schema == PersonPydanticFormSchema
>>> dirs = dir(PersonFormHanlders)
>>> assert len(tuple(filter(lambda x: not x in dirs, ['_name_view', '_age_view', '_height_view']))) == 0


# >>> class SportT
>>> class Mood(Enum):
...     HAPPY = "😄 Happy"
...     SAD = "😢 Sad"
...     EXCITED = "🤩 Excited"
...     RELAXED = "😌 Relaxed"
...
>>>
>>>
>>>  # Enum datatype schema
>>> class PersonMoodPydanticFormSchema(BaseModel):
...     name: str
...     current_mood: Mood
...

>>> class PersonMoodFormHanlders(BasePydanticFormHandlers[PersonMoodPydanticFormSchema]): pass
>>> assert PersonMoodFormHanlders.Schema == PersonMoodPydanticFormSchema
>>> dirs = dir(PersonMoodFormHanlders)
>>> assert len(tuple(filter(lambda x: not x in dirs, ['_name_view', '_current_mood_view']))) == 0

Project details


Release history Release notifications | RSS feed

This version

0.1.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_handler_converter-0.1.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file pydantic_handler_converter-0.1.3.tar.gz.

File metadata

  • Download URL: pydantic_handler_converter-0.1.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.6 Linux/5.15.0-1047-azure

File hashes

Hashes for pydantic_handler_converter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f7aaa527176e67086ffeb8692d377e37daed63ca09305ae15e92b2eb18d2acd2
MD5 01b23277b4b92d6e87364c9416854a68
BLAKE2b-256 ff0a698bf8223ec4f763a3e81d1b314e845e7d263335cd54b84ad762c3d998e5

See more details on using hashes here.

File details

Details for the file pydantic_handler_converter-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_handler_converter-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8944f68eab09630ca7fad8df3218d0e440a3802cacd3f0ab07c5720fd70be311
MD5 306bd3d09fd963d7df236f38a0706511
BLAKE2b-256 5d239a91496b118573501747d1483765175723206e8d2a41d968c0fbc35a2932

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