Skip to main content

🦀🐍 Telegram WebApp Auth Library

This library is a simple way to authenticate users in your web application using Telegram.

Example

For a complete example, check out the Example Bot repository.

Installation

Using pip

pip install teleapp-auth

Using Poetry

poetry add teleapp-auth

Using pipenv

pipenv install teleapp-auth

Using uv

uv pip install teleapp-auth

Usage

from fastapi import Request, FastAPI
from teleapp_auth import get_secret_key, parse_webapp_data, validate_webapp_data


app = FastAPI()
secret_key = get_secret_key("BOT_TOKEN")


@app.post("/check_data")
async def check_data(request: Request) -> bool:
    request_json = await request.json()
    auth_data = request_json.get("auth_data")  # Telegram auth data from the request
    webapp_data = parse_webapp_data(auth_data)  # Parse the auth data to the WebAppInitData object

    # Example of the parsed data:
    # WebAppInitData {
    #   query_id: "AAEt6-JYAAAAAC3r4lj2oADQ",
    #   user: WebAppUser {
    #       id: 1,
    #       is_bot: None,
    #       first_name: "Test",
    #       last_name: "",
    #       username: "test",
    #       language_code: "ru",
    #       is_premium: None,
    #       added_to_attachment_menu: None,
    #       allows_write_to_pm: true,
    #       photo_url: None
    #   },
    #  receiver: None,
    #  chat: None,
    #  chat_type: None,
    #  chat_instance: None,
    #  start_param: None,
    #  can_send_after: None,
    #  auth_date: 1726572911,
    #  hash: "f87a5a37a5b487700a35cb1e3d2e92afa67e4b67066c9f1fa2c34986c2350b6e
    # }
    

    return validate_webapp_data(webapp_data, secret_key)  # True if the data is valid, False otherwise

FAQ

1. What is the purpose of this library?

This library simplifies the process of authenticating users in your web application using Telegram WebApp authentication.

2. Can I get the user's profile photo with this library?

The photo_url field in the authentication data contains a URL to the user's profile photo. However, it is only available for Mini Apps launched from the attachment menu. Currently, integration with the attachment menu is only accessible to major advertisers on the Telegram Ad Platform. All bots can still test this feature in the test server environment by contacting Botfather on the test server.

3. Does this library automatically handle sending authentication data to my server?

No, you need to handle the process of sending the authentication data to your server. You can find an example of how to do this in the page.html file within the examples directory.

4. How do I validate the authentication data?

Use the validate_webapp_data function from the library to verify the authenticity of the data. This function compares the data with a secret key derived from your bot's token.

5. Can I use this library with any Python web framework?

Yes, the library is framework-agnostic, though examples are provided with FastAPI and Blacksheep. You can adapt it to other frameworks with minimal effort.

Metadata

Release files for teleapp-auth 1.0.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 teleapp-auth 1.0.1
File Size Uploaded
teleapp_auth-1.0.1.tar.gz 12.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for teleapp-auth 1.0.1
File
teleapp_auth-1.0.1-cp312-none-win_amd64.whl CPython 3.12 none Windows x86-64 Details
teleapp_auth-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
teleapp_auth-1.0.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
teleapp_auth-1.0.1-cp311-none-win_amd64.whl CPython 3.11 none Windows x86-64 Details
teleapp_auth-1.0.1-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
teleapp_auth-1.0.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
teleapp_auth-1.0.1-cp310-none-win_amd64.whl CPython 3.10 none Windows x86-64 Details
teleapp_auth-1.0.1-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
teleapp_auth-1.0.1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
teleapp_auth-1.0.1-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
teleapp_auth-1.0.1-cp39-cp39-manylinux_2_34_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.34+ x86-64 Details
teleapp_auth-1.0.1-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details

Total release size: 2.5 MB

Release files / teleapp_auth-1.0.1.tar.gz

Download URL teleapp_auth-1.0.1.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0439a569789f97cf93f1893bfe8a6b95d1b60abf452fe010e5bbc0ccedf80ef2
BLAKE2b-256 checksum
How to use checksums
a070d629b273ce74b57b0f566c6890be080cf6ae0881b8a3deb58ea1afaf64a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp312-none-win_amd64.whl

Download URL teleapp_auth-1.0.1-cp312-none-win_amd64.whl
Size 157.9 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
b6242fce914d834fd422ed9b42cd6ee159300b27dd8330d3c6dbb5a12a1ddab3
BLAKE2b-256 checksum
How to use checksums
a1d676da320cf1963aa29e77596647169d7a03c6d50503df0641dcc2b6a5a265
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL teleapp_auth-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl
Size 251.8 kB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
0a6ab50e0bd4fee7855b90c2d4af6d535290bef2ec6b625ff19f13dcea95779d
BLAKE2b-256 checksum
How to use checksums
c0bd0df24afe5e4d7d7aaeffc863540634e1a1a6d9f3ba21d55c53766e86f697
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL teleapp_auth-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Size 219.1 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f4a511bbf4464002ff033beeadaca8053e4ec962db2a7a3a25be6aa9d405e8f0
BLAKE2b-256 checksum
How to use checksums
4b89c015548bfbe1923b82023f5c9f920b323e9a2784bb6bb5886194ed95f4a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp311-none-win_amd64.whl

Download URL teleapp_auth-1.0.1-cp311-none-win_amd64.whl
Size 158.7 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
515528f57a60f36357938ab9e5e624e861c86da1a61f265456b432f474682064
BLAKE2b-256 checksum
How to use checksums
79ee9becf9c04099dcf55f3b914555ff54541aafb03b6c9c46d0eb3eb99b3ce3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL teleapp_auth-1.0.1-cp311-cp311-manylinux_2_34_x86_64.whl
Size 252.5 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
6e159f1d2cba2bb9be9e8f320b4bbeac37d63bc4a19fb0852313becd4af741da
BLAKE2b-256 checksum
How to use checksums
8f575e21e37a14c1b55265de5abf3b66e799017f937a9ccddd38f37e63f99d0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL teleapp_auth-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
Size 219.8 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9f96ba9fd70eb4bac889a232f246641d24c66694d87079864a55a7940f8c7430
BLAKE2b-256 checksum
How to use checksums
b543ee36ec6ed1f6fd5bef8d18bcc559cf8f2e4d8f1f96a37ebce06273a24a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp310-none-win_amd64.whl

Download URL teleapp_auth-1.0.1-cp310-none-win_amd64.whl
Size 158.8 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
bdf41c8034deda88b8954eed3d463f6c501d3b933d6c87c7001776548d018b52
BLAKE2b-256 checksum
How to use checksums
dbb4264f96bc149d953c582d41a67a579f445000def8938a44795dc2350762ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL teleapp_auth-1.0.1-cp310-cp310-manylinux_2_34_x86_64.whl
Size 252.7 kB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
556be146b5e930eb428aeb6f2ec8d3b26e9e70b97df362e466ddcde4698af0ea
BLAKE2b-256 checksum
How to use checksums
3980f4e543b208ad4e27f4e907519f87b2433bdd4ed24ce6510fd5749bca3c3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp310-cp310-macosx_11_0_arm64.whl

Download URL teleapp_auth-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
Size 219.9 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
da3a03d482eb9375a501f075a96c5b61dbae2879cc7cf6b34377d2981f3b69bd
BLAKE2b-256 checksum
How to use checksums
4103a195cb6d243b5c37907bd7e5ebd6f8de362af7eca97512a250efada84daf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp39-none-win_amd64.whl

Download URL teleapp_auth-1.0.1-cp39-none-win_amd64.whl
Size 159.4 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
c9d438ff48a0f6c303126fdb18ea41fe20432f7088fdb459eda71a44ab3aa8d5
BLAKE2b-256 checksum
How to use checksums
fe18840d025033277ac2b20a4bec60d98ad98fd464486e9c3eb7e6a4956b3035
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp39-cp39-manylinux_2_34_x86_64.whl

Download URL teleapp_auth-1.0.1-cp39-cp39-manylinux_2_34_x86_64.whl
Size 253.1 kB
Tags CPython 3.9 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
34d8d78d881839466b18dfeba5e659bdf3fc6fb2d8729e95fc7f5f38dc11a6ae
BLAKE2b-256 checksum
How to use checksums
32407d761934006d1ea4966a5b17eb7727390a8f3f8623edd02cbd0335b02788
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / teleapp_auth-1.0.1-cp39-cp39-macosx_11_0_arm64.whl

Download URL teleapp_auth-1.0.1-cp39-cp39-macosx_11_0_arm64.whl
Size 220.3 kB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6ca8726bab27620bb2438ac89d74402b9ec040671653eb0f9fe16ab7072bdbd0
BLAKE2b-256 checksum
How to use checksums
61e2c79dab7c657a0bae64908a2039881a2dabacc6bb6e66ec484b59a946cf27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

1.0.1 This release

13 release files

1.0.0

13 release files

0.1.0

13 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