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.158.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aec1b4e685d79e41af7bbfa564ac9c2602344a33376bc8f042c63a1ad65c7512 |
|
MD5 | 100a021c106f34df7a3c573d2ab08bb8 |
|
BLAKE2b-256 | 755e6d7f7cfe9fae602370bf780cfaf3cc30592fbb53083dc3317d822658b06d |
Close
Hashes for pydantic_base_aiogram-1.0.158-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 143124108d0d5ba3cb3de87a3d87ec109bb27efb7a300844016f9c90dc3e01e4 |
|
MD5 | 342cce044335d6e43adf43ee4544b417 |
|
BLAKE2b-256 | aaa8367171321f69e12c70242aa70f8e359b190ed050169b35a87c93212be349 |