Skip to main content

Python SDK for TeleWidget — Telegram Mini App widgets

Project description

tgwidget

Python SDK for TeleWidget — beautiful Telegram Mini App widgets for bots.

Install

pip install tgwidget

Usage

Generate widget URL

from tgwidget import TgWidget

# Date picker
url = TgWidget("your_bot").date(mode="datetime", format="unix-s").url()

# Color picker
url = TgWidget("your_bot").color(format="hex").url()

# Schedule
url = TgWidget("your_bot").schedule().url()

# With styling
url = (
    TgWidget("your_bot")
    .date(mode="date")
    .style(color_scheme="dark", accent="#FF6600", adopt_tg_palette=True)
    .url()
)

Parse results

When a user completes the widget, the result comes back via deep link t.me/your_bot?start=VALUE. Parse the value:

from tgwidget import parse_date, parse_color, parse_schedule

# Date result
result = parse_date("2025-03-15", mode="date")
# DateResult(date='2025-03-15', time=None, ...)

# Date range with unix timestamps
result = parse_date("1710460800_1718236800", mode="date-range", format="unix-s")
# DateResult(timestamp=1710460800, timestamp_end=1718236800, date='2025-03-15', ...)

# Color result
result = parse_color("FF6600", format="hex")
# ColorResult(raw='FF6600', hex='#FF6600')

# Schedule result (56-char bunch format)
result = parse_schedule("09001800090018000000000009001800090018000000000000000000")
# [ScheduleDay(enabled=True, start='09:00', end='18:00'), ...]

API

TgWidget(bot_username)

Create a widget builder.

  • .date(mode, format, order) — Date/time picker
  • .color(format) — Color picker
  • .schedule() — Weekly schedule
  • .style(color_scheme, accent, tint, liquid_glass, adapt_tg_theme, adopt_tg_palette) — Styling
  • .url(base_url) — Generate the final URL
  • .payload() — Get the raw payload dict

Parsers

  • parse_date(value, mode, format, order)DateResult
  • parse_color(value, format)ColorResult
  • parse_schedule(value)list[ScheduleDay]

Project details


Download files

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

Source Distribution

tgwidget-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

tgwidget-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file tgwidget-0.1.0.tar.gz.

File metadata

  • Download URL: tgwidget-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for tgwidget-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b016435377ec0f032144ac81af00e225d7fd840900820b4c3c34fd6d794fac04
MD5 797e97f031b880ff1776e41da768887f
BLAKE2b-256 8cb681021a3f0dbb7714c193e3a400b036e7bfc40f68058101320da9df087f01

See more details on using hashes here.

File details

Details for the file tgwidget-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tgwidget-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for tgwidget-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c9cb0511f2cf0cba979cc5895791d4bda76aecb3a25b0ef4cccc84c97e55669
MD5 554a04b6ac1ca74ae9e27082bf7a0280
BLAKE2b-256 5e3851ae38a2e94b07a4f4d773a7e097bfb1777240ee044b2fd7bfdb962b8fd4

See more details on using hashes here.

Supported by

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