All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Support for
chat_type=sendervalue (Mini Apps launched from attachment menu) - Comprehensive tests for
chat_type=sendersupport
- Improved enum serialization in
sign()function to properly handleChatTypeenum values - Fixed backward compatibility when using
ChatTypeenum insign()function
- Version bump
1.0.0 - 2024-01-XX
- Initial release of
telegram-init-dataPython library - Core functionality for validating Telegram Mini App init data
- Support for parsing init data strings into structured Python objects
- Signature validation using HMAC-SHA256 with bot token
- Expiration checking with configurable timeout
- Type definitions for
InitData,User,Chat, and other Telegram objects - Comprehensive error handling with custom exception classes:
TelegramInitDataError- Base exception classAuthDateInvalidError- Invalid or missing auth_dateSignatureInvalidError- Invalid signatureSignatureMissingError- Missing signature/hashExpiredError- Init data has expired
- Functions for working with init data:
validate()- Validate init data (throws exceptions)is_valid()- Check validity (returns boolean)parse()- Parse init data string to structured objectsign()- Sign init data for testing/developmenthash_token()- Generate HMAC key from bot tokensign_data()- Create HMAC-SHA256 signature
- 3rd party validation support:
validate3rd()- Validate using bot ID and custom verification functionis_valid3rd()- Check 3rd party validity (returns boolean)
- FastAPI integration with multiple authentication methods:
TelegramInitDataAuth- Authorization header authenticationTelegramInitDataBearer- Bearer token authenticationcreate_init_data_dependency()- Custom header dependencycreate_optional_init_data_dependency()- Optional validation dependencyget_telegram_auth()- Quick setup utility function
- Comprehensive test suite with 100% code coverage
- Full type hints and mypy compatibility
- Support for Python 3.8+
- MIT license
- Detailed documentation and examples
- Validation: Verify signature and expiration of Telegram Mini App init data
- Parsing: Convert URL-encoded init data to structured Python objects
- Signing: Create signed init data for testing and development
- Type Safety: Full type hints and validation for all data structures
- FastAPI Integration: Ready-to-use middleware and dependencies
- 3rd Party Support: Validate data signed by Telegram directly
- Flexible Configuration: Customizable expiration times and validation options
- Error Handling: Comprehensive exception hierarchy for different failure modes
- Compatible with @telegram-apps/init-data-node Node.js package
- Uses HMAC-SHA256 for signature validation
- Supports all Telegram Mini App init data fields
- Follows Telegram's official validation algorithm
- Zero external dependencies (FastAPI is optional)
- Comprehensive test coverage with pytest
- Code formatting with black and isort
- Type checking with mypy
- Linting with flake8