This code simplifies the conversion of Pydantic schemas into Aiogram handler groups, making it easy to create form-filling handlers.
Project description
Pydantic-base-aiogram
This code simplifies the conversion of Pydantic schemas into Aiogram handler groups, making it easy to create form-filling handlers.
Installation
pip install pydantic_base_aiogram
Usage:
>>> from enum import Enum
>>> from typing import Union
>>> from pydantic import BaseModel
>>> from pydantic_base_aiogram import SchemaBaseHandlersGroup
# ----------------------------------------utils-methods--------------------------------------
>>> def check_for_properties_existense(cls, properties: list[str]):
... dirs = dir(cls)
... assert len(tuple(filter(lambda x: not x in dirs, properties))) == 0
... assert cls(finish_call=None)
# ----------------------------------------Simple datatypes schema--------------------------------------
>>> class PersonPydanticFormSchema(BaseModel):
... name: str
... age: int
... height: float
...
>>> class PersonFormHanlders(SchemaBaseHandlersGroup[PersonPydanticFormSchema]):
... pass
...
...
>>> check_for_properties_existense(PersonFormHanlders, ['name_view', 'age_view', 'height_view'])
# ----------------------------------------Enum datatype schema-----------------------------------------
>>> class Mood(Enum):
... HAPPY = "😄 Happy"
... SAD = "😢 Sad"
... EXCITED = "🤩 Excited"
... RELAXED = "😌 Relaxed"
...
>>>
>>>
>>> class PersonMoodPydanticFormSchema(BaseModel):
... name: str
... current_mood: Mood
...
>>> class PersonMoodFormHanlders(SchemaBaseHandlersGroup[PersonMoodPydanticFormSchema]):
... pass
...
...
>>> check_for_properties_existense(PersonMoodFormHanlders, ['name_view', 'current_mood_view'])
# ----------------------------------------Complex schema-----------------------------------------------
>>> class Address(BaseModel):
... street: str
... city: str
... postal_code: str
...
>>> class Person(BaseModel):
... name: str
... age: int
... address: Address
...
...
>>> class PersonFormHanlders(SchemaBaseHandlersGroup[Person]):
... pass
...
...
>>> check_for_properties_existense(
... PersonFormHanlders,
... [
... 'name_view',
... 'address_street_view',
... 'address_city_view',
... 'address_postal_code_view'
... ]
... )
...
# ------------------------------------Combined Enum datatype schema------------------------------------
>>> class HappyMood(Enum):
... HAPPY = "😄 Happy"
...
>>> class SadMood(Enum):
... SAD = "😢 Sad"
...
>>> class ExcitedMood(Enum):
... EXCITED = "🤩 Excited"
...
>>> class RelaxedMood(Enum):
... RELAXED = "😌 Relaxed"
...
>>>
>>> class PersonMoodPydanticFormSchema(BaseModel):
... name: str
... current_mood: Union[HappyMood, SadMood, ExcitedMood, RelaxedMood]
... future_mood: HappyMood | SadMood | ExcitedMood | RelaxedMood
...
...
>>> class PersonMoodFormHanlders(SchemaBaseHandlersGroup[PersonMoodPydanticFormSchema]):
... pass
...
...
>>> check_for_properties_existense(PersonMoodFormHanlders, ['name_view', 'current_mood_view'])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pydantic_base_aiogram-1.0.148.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c99c8bde6bd116ee41a1daea4cd737aa161e0828bfad1ae86b19190451a49e1 |
|
MD5 | 13dd50b6e1cb98b1f6f103a02838455b |
|
BLAKE2b-256 | a14e4ca5eddd4b89c71c8e1baf2b9faeb2964c4eb68716064ee596b993011e90 |
Close
Hashes for pydantic_base_aiogram-1.0.148-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8b4a65326b243effc267ea57cfb219f8b47aef10544d659bae6c4443bd856ff |
|
MD5 | cf39957a873e1b11f894f7b87d5d17fe |
|
BLAKE2b-256 | 750997726ab0055e944f61f6f593aa7e1b44a9c926414dd07a02fce0a266ab23 |