aiogram-forms
Introduction
aiogram-forms is an addition for aiogram which allows you to create different forms and process user input step by step easily.
Documentation
Documentation can be found here.
Installation
pip install aiogram-forms
Usage
Create form you need by subclassing aiogram_forms.forms.Form. Fields can be added from aiogram_forms.forms.fields subpackage.
from aiogram_forms import dispatcher
from aiogram_forms.forms import Form, fields, FormsManager
from aiogram_forms.errors import ValidationError
def validate_username_format(value: str):
"""Validate username starts with leading @."""
if not value.startswith('@'):
raise ValidationError('Username should starts with "@".', code='username_prefix')
@dispatcher.register('test-form')
class TestForm(Form):
username = fields.TextField(
'Username', min_length=4, validators=[validate_username_format],
error_messages={'min_length': 'Username must contain at least 4 characters!'}
)
email = fields.EmailField('Email', help_text='We will send confirmation code.')
phone = fields.PhoneNumberField('Phone number', share_contact=True)
language = fields.ChoiceField('Language', choices=(
('English', 'en'),
('Russian', 'ru')
))
@classmethod
async def callback(cls, message: types.Message, forms: FormsManager, **data) -> None:
data = await forms.get_data('test-form') # Get form data from state
await message.answer(
text=f'Thank you, {data["username"]}!',
reply_markup=types.ReplyKeyboardRemove() # Use this for reset if last field contains keyboard
)
router = Router()
@router.message(Command(commands=['start']))
async def command_start(message: types.Message, forms: FormsManager) -> None:
await forms.show('test-form') # Start form processing
async def main():
dp = Dispatcher()
dp.include_router(router)
dispatcher.attach(dp) # Attach aiogram to forms dispatcher
bot = Bot(...)
await dp.start_polling(bot)
History
All notable changes to this project will be documented in CHANGELOG file.
Metadata
Release files for aiogram-forms 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiogram_forms-1.1.1.tar.gz | 10.0 kB | Without provenance | Details for aiogram_forms-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiogram_forms-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for aiogram_forms-1.1.1-py3-none-any.whl |
Total release size: 24.9 kB
Release files / aiogram_forms-1.1.1.tar.gz
| Download URL | aiogram_forms-1.1.1.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db42ea088fde4480896ed0ec3829c521ab26b1c87697c58ff721958d077d83b3
|
|
BLAKE2b-256 checksum How to use checksums |
5506670b4bb3444af5614dc4088f9533a6962049e5f94752eca3199737e1c06e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.10.4 Darwin/22.3.0
|
Release files / aiogram_forms-1.1.1-py3-none-any.whl
| Download URL | aiogram_forms-1.1.1-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d153381ce8c03cf8c3491cc1ccb069fefa0cb41e04357be2a67f99b8207d5e7
|
|
BLAKE2b-256 checksum How to use checksums |
ce8ee314d4613a5f91df3d560a9f1bda5f8648536e285310fdf98156ae94b5a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.10.4 Darwin/22.3.0
|
Security for aiogram-forms 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.