telegram-webapp-auth
telegram-webapp-auth validates Telegram Mini App initData in Python.
It implements Telegram's official Mini Apps authentication algorithms, supports both bot-token and third-party validation flows, and returns typed dataclasses for users, chats, and init data.
Features
- Bot-token validation with
TelegramAuthenticator.validate() - Third-party Ed25519 validation with
TelegramAuthenticator.validate_third_party() - Optional expiry checks with
expr_in - Typed
WebAppInitData,WebAppUser, andWebAppChatresults, with unknown top-level fields preserved - Python 3.10+ support
- Lightweight runtime dependency set
Installation
pip install telegram-webapp-auth
# or
poetry add telegram-webapp-auth
# or
uv add telegram-webapp-auth
Quick Start
from datetime import timedelta
from telegram_webapp_auth.auth import TelegramAuthenticator
from telegram_webapp_auth.auth import generate_secret_key
from telegram_webapp_auth.errors import ExpiredInitDataError
from telegram_webapp_auth.errors import InvalidInitDataError
secret_key = generate_secret_key("123456:ABC-DEF")
authenticator = TelegramAuthenticator(secret_key)
try:
init_data = authenticator.validate(
init_data=request.headers["Authorization"],
expr_in=timedelta(minutes=5),
)
except ExpiredInitDataError:
raise PermissionError("Telegram init data has expired")
except InvalidInitDataError:
raise PermissionError("Telegram init data is invalid")
telegram_user = init_data.user
Documentation
Read the full documentation at swimmwatch.github.io/telegram-webapp-auth.
Useful starting points:
Maintenance And Security
This project is in maintenance mode and accepts bug fixes. Please report security issues privately; see SECURITY.md.
License
telegram-webapp-auth is licensed under the MIT License.
Metadata
Release files for telegram-webapp-auth 3.2.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 |
|---|---|---|---|---|
| telegram_webapp_auth-3.2.1.tar.gz | 7.2 kB | Without provenance | Details for telegram_webapp_auth-3.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| telegram_webapp_auth-3.2.1-py3-none-any.whl | Python 3 | none | any | Details for telegram_webapp_auth-3.2.1-py3-none-any.whl |
Total release size: 15.4 kB
Release files / telegram_webapp_auth-3.2.1.tar.gz
| Download URL | telegram_webapp_auth-3.2.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65ad6b1eaa99c3e3e8d8464681050817182b9547f3e1c17e18173b21f0be4e72
|
|
BLAKE2b-256 checksum How to use checksums |
aa3370c3add81e092b9d7ac04d7a2d01ca4ad257c0a09b99e7024870c5a7201b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-1018-azure
|
Release files / telegram_webapp_auth-3.2.1-py3-none-any.whl
| Download URL | telegram_webapp_auth-3.2.1-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eae3fc27ee08def7c1d044ccf4da234df99fa14b88e4e327aea19b98ba664f02
|
|
BLAKE2b-256 checksum How to use checksums |
3d2e7f718aaf3fcd8e3d8ebb13cee9595db0b48c43c97ef0d022b739e6b9b4e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-1018-azure
|
Security for telegram-webapp-auth 3.2.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.