Skip to main content

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


Download files

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

Source Distribution

pydantic_ai_telegram-0.1.2.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

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

pydantic_ai_telegram-0.1.2-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_ai_telegram-0.1.2.tar.gz.

File metadata

  • Download URL: pydantic_ai_telegram-0.1.2.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pydantic_ai_telegram-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7a348de16f27dc04203a0dc2c17e6948c7b1485b65c798ef74765f6eeca21f7f
MD5 e480d49b3f58e20bee4667c393e173cd
BLAKE2b-256 9d773f5d689bad04ac2192b9fb9632b41057520df12c3fcbc6743fdf5645fdc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_ai_telegram-0.1.2.tar.gz:

Publisher: publish.yml on wydii/pydantic-ai-telegram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_ai_telegram-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_ai_telegram-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cd485d6ecbe458671be1eafb8f56f85acfabf47467b1e10857504edabab1d382
MD5 49327289189bd091a17d01865f7ae6ef
BLAKE2b-256 28247b6cd31eceae22150909c6217aa660aa1def11eaa1e80b180057ca32cb9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_ai_telegram-0.1.2-py3-none-any.whl:

Publisher: publish.yml on wydii/pydantic-ai-telegram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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