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

This code simplifies the conversion of Pydantic schemas into Aiogram handler groups, making it easy to create form-filling handlers.

Installation

    pip install pydantic_handler_converter

Usage:

>>> from enum import Enum
>>> from pydantic import BaseModel
>>> from pydantic_handler_converter import BasePydanticFormHandlers
>>>
>>> # Simple datatypes schema 
>>> class PersonPydanticFormSchema(BaseModel):
...     name: str
...     age: int
...     height: float 
... 

>>> class PersonFormHanlders(BasePydanticFormHandlers[PersonPydanticFormSchema]):
...     pass
...
...
>>> assert PersonFormHanlders.Schema == PersonPydanticFormSchema
>>> dirs = dir(PersonFormHanlders)
>>> assert len(tuple(filter(lambda x: not x in dirs, ['_name_view', '_age_view', '_height_view']))) == 0


>>> class Mood(Enum):
...     HAPPY = "😄 Happy"
...     SAD = "😢 Sad"
...     EXCITED = "🤩 Excited"
...     RELAXED = "😌 Relaxed"
...
>>>
>>>
>>>  # Enum datatype schema
>>> class PersonMoodPydanticFormSchema(BaseModel):
...     name: str
...     current_mood: Mood
...
>>> class PersonMoodFormHanlders(BasePydanticFormHandlers[PersonMoodPydanticFormSchema]): 
...     pass
...
...
>>> assert PersonMoodFormHanlders.Schema == PersonMoodPydanticFormSchema
>>> dirs = dir(PersonMoodFormHanlders)
>>> assert len(tuple(filter(lambda x: not x in dirs, ['_name_view', '_current_mood_view']))) == 0

Project details


Release history Release notifications | RSS feed

This version

0.1.6

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_handler_converter-0.1.6.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file pydantic_handler_converter-0.1.6.tar.gz.

File metadata

  • Download URL: pydantic_handler_converter-0.1.6.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.6 Linux/5.15.0-1047-azure

File hashes

Hashes for pydantic_handler_converter-0.1.6.tar.gz
Algorithm Hash digest
SHA256 4da335cae79535804dbc147d4abfa3a927472db463760f2b7fd6a64bf622bfe2
MD5 b221774941c352ecfbbcd79a105c07a6
BLAKE2b-256 404572d1599e105f37b4eae2cc69258e43c66defea4dad3a7431add24e61b1f5

See more details on using hashes here.

File details

Details for the file pydantic_handler_converter-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_handler_converter-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5040ad8943253c481ce4013b81ef27c33e7eca0b11c36637c833f0f7a382cc88
MD5 be7b4af7b28c3cdc9d63b4c0b4e4f76e
BLAKE2b-256 77b7a6c923fc270d4d5f76ad7d2861ef117c2cc81153b7c5f0d21d4cc2e28be4

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