Skip to main content

A library to create forms in aiogram3

Project description

aiogram3-form

A library to create forms in aiogram3

pip install aiogram3-form

Example

import asyncio

from aiogram import Bot, Dispatcher, F, Router
from aiogram3_form import Form, FormField
from aiogram.fsm.context import FSMContext

bot = Bot(token="YOUR_TOKEN")
dispatcher = Dispatcher()
router = Router()
dispatcher.include_router(router)


class NameForm(Form):
    first_name: str = FormField(enter_message_text="Enter your first name please")
    second_name: str = FormField(
        enter_message_text="Enter your second name please",
        filter=(F.text.len() > 10) & F.text,
    )
    age: int = FormField(enter_message_text="Enter age as integer")


@NameForm.submit(router=router)
async def name_form_submit_handler(form: NameForm):
    # handle form data
    # also supports aiogram standart DI (e. g. middlewares, filter data, etc)
    await form.answer(f"{form.first_name} {form.second_name} of age {form.age}")


@router.message(F.text == "/form")
async def form_handler(_, state: FSMContext):
    await NameForm.start(bot, state)  # start your form


asyncio.run(dispatcher.start_polling(bot))

Project details


Download files

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

Source Distribution

aiogram3_form-2.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

aiogram3_form-2.0.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file aiogram3_form-2.0.0.tar.gz.

File metadata

  • Download URL: aiogram3_form-2.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0

File hashes

Hashes for aiogram3_form-2.0.0.tar.gz
Algorithm Hash digest
SHA256 6641b76eaf469af9c0551f0a761395dc70abba7a57fe7aef694a66039ac4be1e
MD5 e00f47f3dbfdd052b06dd8447e7e00b7
BLAKE2b-256 942d5bfb6b0aca10b50748473ed3f60a82eb4fb2fee1075ad9e0d3bf38e51f61

See more details on using hashes here.

File details

Details for the file aiogram3_form-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: aiogram3_form-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0

File hashes

Hashes for aiogram3_form-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5c48efe504aa0c92263abf2d4e4877410658c910d925e7fd07f948a0d641135
MD5 7564b3b956452ed0b2bbe914a1430631
BLAKE2b-256 304ff27a96fa808f3b587a6da48121921b0ed150bdba7744d1ac2ceaf2c50136

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