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, types
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, router=router):
    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",
        error_message_text="Age should be numeric!",
    )


@NameForm.submit()
async def name_form_submit_handler(form: NameForm, event_chat: types.Chat):
    # handle form data
    # also supports aiogram standart DI (e. g. middlewares, filters, etc)
    await form.answer(
        f"{form.first_name} {form.second_name} of age {form.age} in chat {event_chat.title}"
    )


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


async def main():
    await dispatcher.start_polling(bot)


asyncio.run(main())

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-0.6.7.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

aiogram3_form-0.6.7-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiogram3_form-0.6.7.tar.gz
  • Upload date:
  • Size: 5.1 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-0.6.7.tar.gz
Algorithm Hash digest
SHA256 e9b1c8849d1e186383cbb83ed9388bd0c0e44e081e213183a4ce283c9efc5cbe
MD5 8bac1656da058bd126ee4862e867d016
BLAKE2b-256 18d53802486ef8b178c0f2c7b3f15cb8872d0581810202b7787c4efcb747e0f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiogram3_form-0.6.7-py3-none-any.whl
  • Upload date:
  • Size: 6.4 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-0.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1ddeb6a70a882130bd65eaa1debf04dd49d76c07f7d22a529f0ec0599d88c3c5
MD5 e61796d2f629b4295b309de5a793a3e0
BLAKE2b-256 03bae043e332c1da2f36c209fbcd007d31f310dbac54c5ce5e252cb90e1851b1

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