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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_webapp_auth-3.2.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_webapp_auth-3.2.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file telegram_webapp_auth-3.2.1.tar.gz.

File metadata

  • Download URL: telegram_webapp_auth-3.2.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for telegram_webapp_auth-3.2.1.tar.gz
Algorithm Hash digest
SHA256 65ad6b1eaa99c3e3e8d8464681050817182b9547f3e1c17e18173b21f0be4e72
MD5 8b5701f67fb91194d4179f0f339add6b
BLAKE2b-256 aa3370c3add81e092b9d7ac04d7a2d01ca4ad257c0a09b99e7024870c5a7201b

See more details on using hashes here.

File details

Details for the file telegram_webapp_auth-3.2.1-py3-none-any.whl.

File metadata

  • Download URL: telegram_webapp_auth-3.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for telegram_webapp_auth-3.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eae3fc27ee08def7c1d044ccf4da234df99fa14b88e4e327aea19b98ba664f02
MD5 e8ad89550b7b5d0103643df83ec32729
BLAKE2b-256 3d2e7f718aaf3fcd8e3d8ebb13cee9595db0b48c43c97ef0d022b739e6b9b4e4

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.2.1 This release

2 files

3.2.0

2 files

3.1.0

2 files

3.0.7

2 files

3.0.6

2 files

3.0.5

2 files

3.0.4

2 files

3.0.3

2 files

3.0.2

2 files

3.0.0

2 files

2.0.1

2 files

2.0.0

2 files

1.0.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page