TGCoreSDK | A fluent DSL framework for Telegram, APIs, and AI workflows.
Project description
TGCore SDK
A fluent DSL framework for composing Telegram, APIs, and AI workflows.
Turn messy APIs into clean, composable chains.
Like Flutter for backend logic.
# Chain your backend, not JSON
msg = tg.msg.core("Hello")
res = await tg.ai.groq()\
.model("moonshotai/kimi-k2-instruct")\
.messages([msg])\
.send()
print(res.text())
Framework TgCore |
TeamKillerX Docs IO |
TgCore API Docs |
Original Telegram API Docs
Security-focused Telegram Bot Framework.
- Getting Started
- Installation
- What makes TGCore different
- Chain & DSL
- AI Chain
- Traditional API
- TGCore Fluent Builder
- payload DSL (domain-specific language)
- Clean architecture
- Authentication
- Usage
- New fluent chain API
- sendMessage
- Simple Call
- Builder Pattern
- Rest API & TGCore Bot
- Why TGCore?
- Compared to Native Telegram API
- License
- Contributing
- Status
- Author
What makes TGCore different
- Secure and scalable architecture
- Async-first design
- Fluent API builder pattern
- Supports Telegram bots, APIs, and AI workflows
- Designed for complex system composition
📦 Installation
pip install tgcore
Or install locally:
pip install -e .
Getting started
from tgcore import Client
tg = Client(api_key="YOUR_API_KEY")
await tg.raw.sendMessage()\
.chat_id(123456789)\
.text("Hello from TGCore")\
.send()
Chain & DSL
await tg.use.default\
.route("games", "chain")\
.user(
tg.where(
name="Randy Architect",
age="145",
hobi="all"
)
)\
.database(
tg.where(
mongodb=True,
redis=True,
sqlite=True
)
)\
.pretty()
AI Chain
msg = tg.msg.core("Hello")
res = await tg.ai.groq()\
.model("kimi-k2")\
.messages([msg])\
.send()
print(res.text())
Traditional API
send_message(
chat_id,
text,
parse_mode,
disable_notification,
reply_markup,
protect_content
)
TGCore Fluent Builder
send_message()\
.chat_id(id)\
.text("hello")\
.send()
payload DSL (domain-specific language)
JSON is the output, not the source of truth The architecture should absorb API changes
result = await tg.use.default\
.route("gemini", "gemini-2.5-flash")\
.contents(
[
tg.where(
parts=[tg.where(text="lu siapa?")]
)
]
)\
.system_instruction(
tg.where(
parts=[tg.where(text="kamu adalah TgCore komedi lucu")]
)
)\
.generationConfig(
tg.where(
temperature=1.0,
topP=0.8,
topK=10
)
)\
.send()
return result.text()
Clean architecture
- Architecture: clean
- Code: perfect
- Async: working
tg = Client(api_key="something", base_url="https://your_domain.com")
result = await tg.use.default\
.endpoint("/v1/chat/completions")\
.model("model")\
.messages([...])\
.stream(False)\
.send()
print(result)
🔑 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(...).
Example of using fluent chain API:
# version: 1.0.43+, 1.0.68+
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+, 1.0.68+
# 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
# Version: 1.0.68+
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tgcore-1.0.78.tar.gz.
File metadata
- Download URL: tgcore-1.0.78.tar.gz
- Upload date:
- Size: 26.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
832ce9509d3d22f916f00b1982da2a04f51cea136556b237c876889ac9b906dd
|
|
| MD5 |
002e370d0cc13ada8d82a1489992c042
|
|
| BLAKE2b-256 |
6544e430b13d63123ea6c6f6bf4fab039e90755f74fb3e3e1de5dd9759e242ea
|
File details
Details for the file tgcore-1.0.78-py3-none-any.whl.
File metadata
- Download URL: tgcore-1.0.78-py3-none-any.whl
- Upload date:
- Size: 38.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd8a973e39663e61e1905bff8eb81fc8d6aac51643ec1660d132e68d986d838d
|
|
| MD5 |
603bafcd09e4b790a388631ea342df43
|
|
| BLAKE2b-256 |
e1ac5e59e6eeb8fa30494f48d41dece5682917bc6d61361988916cd8bea769f1
|