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.0.tar.gz (26.4 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.0-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

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

Hashes for pydantic_ai_telegram-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9fb0df4451357f420f3fe1e21ef1fbb2c4ad28c3a467c85264b5905c761151d0
MD5 a5b422a32d1b67ed680fcc00ec552b26
BLAKE2b-256 abf183b05b2d90a5e733add92787f6b8f0a33818670e938b6b2fd51605d4be4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_ai_telegram-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_ai_telegram-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25fb66a88cd7d57b6c9a4e440d84542e70e0053df9e4bb97ca51f98db8ea52d1
MD5 e916ddec61d80c75c4c7e7f89ba2afc6
BLAKE2b-256 f59705a59eb2a7b8e39f860cebde924a684b67ade6dd95748e8e529fe51f371e

See more details on using hashes here.

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

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