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.125.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aa09ab703a56d452c234b91b04682970f00af6e2f6109ed87dc49a55fa8fe50 |
|
MD5 | c1fae94c3289e0c05bbf2741580dfd4d |
|
BLAKE2b-256 | 20c795d0a08fce073369a75e1fcba4bb3361028eadcd297e156f88be6e05b7aa |
Close
Hashes for pydantic_base_aiogram-1.0.125-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e94a4b06a3000b745d9635c2b0b7c0b4b4823da22c1f94e11607f9504caeb4fb |
|
MD5 | 38c71d251ea869b6ba745d8d08dfe062 |
|
BLAKE2b-256 | dc289a25e534b99262a8d1bdcb28ea67493bc114656c013ba0f08ba12a468936 |