A Python library for integrating Pydantic AI agents with Telegram bots
Project description
Pydantic AI Telegram
Wrap any Pydantic AI agent with Telegram in one line of code.
Why? Pydantic AI makes building AI agents simple. This library lets you expose them via Telegram instantly — perfect for personal assistants, prototypes, or internal tools - Image, documents and voice memos are supported natively.
Installation
pip install pydantic-ai-telegram
With local voice transcription (requires ffmpeg):
pip install pydantic-ai-telegram[whisper]
Quick Start
Option 1: CLI Configuration
Run the interactive setup:
pydantic-ai-telegram-config
This creates a .env file with your configuration.
Option 2: Manual Configuration
Create a .env file:
# Required
TELEGRAM_BOT_TOKEN=your_token_from_botfather
# Optional - Access control
TELEGRAM_ALLOWED_CHAT_IDS=123456789,987654321
TELEGRAM_ALLOWED_USERNAMES=alice,bob
# Optional - Voice transcription (local whisper)
TRANSCRIPTION_SERVICE=local
WHISPER_MODEL=turbo
# Optional - OpenAI (for agent or transcription)
OPENAI_API_KEY=sk-...
# Optional - Conversation history limit
MAX_HISTORY_MESSAGES=50
Minimal Example
import os
from dotenv import load_dotenv
from pydantic_ai import Agent
from pydantic_ai_telegram import TelegramAgent
load_dotenv()
# Your Pydantic AI agent
agent = Agent(
"openai:gpt-4o-mini",
system_prompt="You are a helpful assistant.",
)
# Wrap it with Telegram
bot = TelegramAgent(
bot_token=os.getenv("TELEGRAM_BOT_TOKEN"),
agent=agent,
)
bot.run()
That's it. Your agent is now accessible via Telegram.
Voice Transcription
Local transcription uses OpenAI Whisper running on your machine:
from pydantic_ai_telegram import TelegramAgent, LocalWhisperTranscription
transcription = LocalWhisperTranscription(model_name="turbo")
bot = TelegramAgent(
bot_token=os.getenv("TELEGRAM_BOT_TOKEN"),
agent=agent,
transcription_service=transcription,
)
Note: Cloud transcription (OpenAI API) is planned for a future release.
License
MIT
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 pydantic_ai_telegram-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_ai_telegram-0.1.0.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fb0df4451357f420f3fe1e21ef1fbb2c4ad28c3a467c85264b5905c761151d0
|
|
| MD5 |
a5b422a32d1b67ed680fcc00ec552b26
|
|
| BLAKE2b-256 |
abf183b05b2d90a5e733add92787f6b8f0a33818670e938b6b2fd51605d4be4c
|
Provenance
The following attestation bundles were made for pydantic_ai_telegram-0.1.0.tar.gz:
Publisher:
publish.yml on wydii/pydantic-ai-telegram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_telegram-0.1.0.tar.gz -
Subject digest:
9fb0df4451357f420f3fe1e21ef1fbb2c4ad28c3a467c85264b5905c761151d0 - Sigstore transparency entry: 729391993
- Sigstore integration time:
-
Permalink:
wydii/pydantic-ai-telegram@9b2c61a5df80600c5cfa988aa866060b090e4dbd -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/wydii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b2c61a5df80600c5cfa988aa866060b090e4dbd -
Trigger Event:
release
-
Statement type:
File details
Details for the file pydantic_ai_telegram-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_telegram-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25fb66a88cd7d57b6c9a4e440d84542e70e0053df9e4bb97ca51f98db8ea52d1
|
|
| MD5 |
e916ddec61d80c75c4c7e7f89ba2afc6
|
|
| BLAKE2b-256 |
f59705a59eb2a7b8e39f860cebde924a684b67ade6dd95748e8e529fe51f371e
|
Provenance
The following attestation bundles were made for pydantic_ai_telegram-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on wydii/pydantic-ai-telegram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_telegram-0.1.0-py3-none-any.whl -
Subject digest:
25fb66a88cd7d57b6c9a4e440d84542e70e0053df9e4bb97ca51f98db8ea52d1 - Sigstore transparency entry: 729391995
- Sigstore integration time:
-
Permalink:
wydii/pydantic-ai-telegram@9b2c61a5df80600c5cfa988aa866060b090e4dbd -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/wydii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b2c61a5df80600c5cfa988aa866060b090e4dbd -
Trigger Event:
release
-
Statement type: