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.

Installation

    pip install pydantic_handler_converter

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
...
...
>>> dirs = dir(PersonFormHanlders)
>>> assert len(tuple(filter(lambda x: not x in dirs, ['name_view', 'age_view', 'height_view']))) == 0


>>> 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
...
...
>>> dirs = dir(PersonMoodFormHanlders)
>>> assert len(tuple(filter(lambda x: not x in dirs, ['name_view', 'current_mood_view']))) == 0



>>>  # Complex schema
>>> class Address(BaseModel):
...     street: str
...     city: str
...     postal_code: str
...
>>> class Person(BaseModel):
...      name: str
...      age: int
...      address: Address
...
...
>>> class PersonFormHanlders(BasePydanticFormHandlers[Person]): 
...     pass
...
...
>>> dirs = dir(PersonFormHanlders)
>>> assert len(tuple(filter(lambda x: not x in dirs, 
...     ['name_view', 'address_street_view', 'address_city_view', 'address_postal_code_view']
... ))) == 0

Project details


Release history Release notifications | RSS feed

This version

0.1.9

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.9.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: pydantic_handler_converter-0.1.9.tar.gz
  • Upload date:
  • Size: 5.6 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.9.tar.gz
Algorithm Hash digest
SHA256 ab921c9e71e1fdf8d6e811d85f996c3fa7c6a356506f156e173c8f02073762ab
MD5 c7781601bce02aa288d4858af9e97087
BLAKE2b-256 47629434083bda0d15f501ac8788d535ec96df55fce241ce8da81404d053bceb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_handler_converter-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 247e0b40d21d51a79a9d39844b34ba57b459392dd9b6ed6a80384869784633e2
MD5 98cbecb95b264b9fca1c5970acb447bd
BLAKE2b-256 ed335de6630b1419ef3f7546f6c38d84b7c4f43b0affdb4adc867ec6fe3668f8

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