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-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

pydantic_base_aiogram-1.0.165.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

pydantic_base_aiogram-1.0.165-py3-none-any.whl (49.1 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_base_aiogram-1.0.165.tar.gz.

File metadata

  • Download URL: pydantic_base_aiogram-1.0.165.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.6 Linux/5.15.0-1064-azure

File hashes

Hashes for pydantic_base_aiogram-1.0.165.tar.gz
Algorithm Hash digest
SHA256 83a29bba381b8632cd676b1ec95b8855ec616c88d3e6003cf1b05b81430044a3
MD5 a4555d8a1b1a7989296124748479422e
BLAKE2b-256 43dfc575b52bd4794050d337ff4c2ed225fb51931e2cb1cc29171900dcf14e98

See more details on using hashes here.

File details

Details for the file pydantic_base_aiogram-1.0.165-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_base_aiogram-1.0.165-py3-none-any.whl
Algorithm Hash digest
SHA256 f290a2d0f50b5b202df391151940a28dc6b5ccfbd9b179aa5f7c6f4384e5b997
MD5 1b4c2c09bf64b5b976477081901d4f42
BLAKE2b-256 4a6ffb8b83ff4174bec13f8d277a662d023c4046789ff57dedcb06c39f6a4cd9

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