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.132.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2eced52ac718984b84d4918f3139c75d39f32e5f07061fb5e109c1857522a01 |
|
MD5 | 483676d1468fd5cb2b718f84fa72bba2 |
|
BLAKE2b-256 | 3a55d08560c7de2e19433ad14f70da7a6cd21f728e991d91969fa93ce194d269 |
Close
Hashes for pydantic_base_aiogram-1.0.132-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d995610e1c7ed47d85a093d6c9dc6c2a398ff375097e89d391836effd6b0c182 |
|
MD5 | 6f7b6083cb8bff9c1f832cb6f3d60f5b |
|
BLAKE2b-256 | 6d9ee492bcde2bf6736c447893de0b8b0d7eed94a4ea5daf0b7f045f9d14bb4b |