Skip to main content

telegram-webapp-auth

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, and WebAppChat results, 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)

Source distribution for telegram-webapp-auth 3.2.1
File Size Uploaded
telegram_webapp_auth-3.2.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-webapp-auth 3.2.1
File Interpreter ABI Platform
telegram_webapp_auth-3.2.1-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

3.2.1 This release

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page