Skip to main content

TGCoreSDK | Enterprise Telegram SDK framework with fluent builder API, platform tools, and AI integrations.

Project description

TGCore SDK

Enterprise Telegram Bot Framework • Secure • Scalable • Zero-Trust Ready

Maintained PRs Security Architecture FastAPI MongoDB Async Webhook tgcore

pre-commit Python PyPI Downloads Python

License

Security-focused Telegram Bot Framework.

✨ Features

  • 🧩 Fluent builder API
  • 🧲 Keyboard builder
  • 🪄 AI integrations
  • 📥 Platform downloader
  • ⚡ Async native ("async/await")
  • 🔐 Secure API key authentication
  • 🤖 Multi-bot token support
  • 🔁 Token rotation ready
  • 🧩 Builder pattern + simple calls
  • 📦 Auto-generated methods from OpenAPI schema
  • 📚 Auto docstring generation
  • 🏗 Enterprise-ready architecture

📦 Installation

pip install tgcore

Or install locally:

pip install -e .


🔑 Authentication

Create client instance:

from tgcore import Client

client = Client("fw_live_xxx")

await client.telegram.send_message(
    chat_id="@channel",
    text="hello"
)

👾 Usage

Platform Tools

resp = await tg.platform.facebook\
    .download(url="https://facebook.com/...")\
    .send()

New fluent chain API

Parameters can be chained (builder-style) without having to write long functions like send_message(...).

  • Platform Downloader (7-day free trial)
  • /api/web/facebook/download
  • /api/web/tiktok/download
  • /api/web/pinterest/download

Example of using fluent chain API:

# version: 1.0.43+
async def full_code():
    _ = await tg.fetch_post(
        "/api/web/facebook/download",
        url="https://www.facebook.com/groups/788889186033999/permalink/1325624742360438/?app=fbl",
        check_errors=True
    )
    await tg.raw\
    .sendVideo()\
    .chat_id(chat_id)\
    .video(_.data.video[0].url)\
    .reply_markup(
        tg.kb().copy_text(
            "this SDK builder style",
            "use a framework"
        )
        .build()
    )\
    .skip()

Example: await tg.raw.sendMessage().chat_id(chat_id).text("tgcore").skip()

That's the concept of builder + fluent chain API.

sendMessage

# Latest version 1.0.16+
# Support Pyrogram/Kurigram (KeyboardBuilder)

from tgcore import Client, KeyboardBuilder

tg = Client()

async def send():
    await (
        tg.raw
        .sendMessage(
            chat_id=m.chat.id,
            text="Testing",
            reply_markup=(
                KeyboardBuilder()
                .url("This Url", "https://github.com/TeamKillerX/tgcore")
                .style("This color", "danger", callback_data="#abc")
                .build()
            )
        )
        .execute()
    )

New button

# old version: 1.0.14
from tgcore import Client, KeyboardBuilder

tg = Client()

async def use_pyrogram(m):
    await tg.telegram.send_message(
        chat_id=str(m.chat.id),
        text="This Button",
        reply_markup=(
            KeyboardBuilder()
            .row("GitHub", url="https://github.com")
            .row("Docs", url="https://www.learnpython.org/")
            .row("Pypi", url="https://pypi.org/project/tgcore/")
            .build()
        )

Simple Call

await client.telegram.send_message(
    chat_id="@channel",
    text="Hello world"
)

Builder Pattern

await (
    client.telegram
        .send_photo_call(chat_id="@channel", photo="https://img.jpg")
        .execute()
)

Rest API & TgCore Bot

from tgcore import Client, KeyboardBuilder

tg = Client()

async def pinterest_images(q: str):
    kw = await tg._post(
        "/api/web/pinterest",
        payload={"query": q}
    )
    like_ts = tg.to_obj(kw)
    if not like_ts.ok or not like_ts.data:
        return None
    return like_ts.data.pins[1].media.images.orig.url

async def send_photo():
    newurl = await pinterest_images("Real coding")
    resp = await tg.raw.sendPhoto(
        chat_id=-100123456789,
        photo=newurl,
        reply_markup=(
            KeyboardBuilder()
            .url("View Pinterest", newurl)
            .url("Tgcore on PyPI", "https://pypi.org/project/tgcore/")
            .row()
            .url("Tgcore on NPMJS", "https://www.npmjs.com/package/@xtsea/tgcore-ts")
            .build()
        )
    ).execute()
    return tg.to_obj(resp).ok

🔄 Token Rotation Support

The server supports storing encrypted tokens using AES-256-GCM. The SDK automatically uses the active token version.

🔒 Security Model

TgCoreSDK never exposes bot tokens to clients.

Flow:

Client → API Gateway → Decrypt → Telegram API

Benefits:

  • prevents token leaks
  • safe frontend usage
  • safe monitoring dashboards
  • supports IP restrictions

Why TGCore?

Unlike traditional Telegram SDKs, TGCore is built as a secure middleware layer that prevents token leaks, enforces API-key auth, and supports enterprise-grade scaling.

Designed for production, not demos.

Compared to Native Telegram API

Feature Telegram API TGCore
Token Exposure Yes No
Auth Layer None API Key + Secret
Proxy Support Manual Built-in
Multi Bot Limited Yes
Webhook Security Basic Zero-Trust

🧾 License

Licensed under Apache License 2.0

You may:

  • use commercially
  • modify
  • distribute
  • sublicense

🤝 Contributing

Pull requests welcome. For major changes, open an issue first to discuss what you would like to change.


🔥 Status

Production Ready


👑 Author

Built with ❤️ by Randy W

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

tgcore-1.0.58.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

tgcore-1.0.58-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file tgcore-1.0.58.tar.gz.

File metadata

  • Download URL: tgcore-1.0.58.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgcore-1.0.58.tar.gz
Algorithm Hash digest
SHA256 cc4d881e167ce71676fea21ccf666564bee65d372690e15993f3f7a533758590
MD5 81d6f0fea946f9406f787a7364ffd05b
BLAKE2b-256 63ae60dcfb7c1aa442adbeca01218a48208eeb9799b7937feb0c2eea10b3a4ec

See more details on using hashes here.

File details

Details for the file tgcore-1.0.58-py3-none-any.whl.

File metadata

  • Download URL: tgcore-1.0.58-py3-none-any.whl
  • Upload date:
  • Size: 32.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgcore-1.0.58-py3-none-any.whl
Algorithm Hash digest
SHA256 58f9971cf56b0d807306b029629b14296fa9eea143b3fc0c4863adde2d0b6f93
MD5 d11165d598831d50e5c44912510c55eb
BLAKE2b-256 6e88ba9f06ab1763b1a3198eca986f65e6966aed1998f10478b60a98c5a49df8

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