PGPCbot

PGPCbot is a Python library for writing bots for PGP Chat, a messenger whose private chats are end-to-end encrypted with OpenPGP. It covers the whole Bot API, and it handles the encryption for you.

On PyPI (pip install PGPCbot) and on GitHub, where the issues are.

from pgpcbot import Bot

bot = Bot()  # reads the token from PGPCHAT_BOT_TOKEN


@bot.command("start", description="Say hello")
async def start(message):
    await message.reply("Hello! Send me anything and I will repeat it.")


@bot.on_message()
async def echo(message):
    await message.reply(f"You said: {message.text}")


bot.run()

If the bot has a published OpenPGP key, its private chats are end-to-end encrypted. The code above does not change: messages reach your handlers already decrypted, and replies are encrypted for the people who should read them.

What you get

  • The whole Bot API: every operation, with typed models, as async calls (AsyncClient) and as blocking calls (Client).

  • A bot framework: handlers for messages, commands, button presses, edits, deletions and membership changes; filters; routers; middleware; error handlers (Events, filters and middleware).

  • Automatic OpenPGP: decryption, signature checks, encryption and signing, key generation and rotation (OpenPGP step by step, Cryptography).

  • Reliable delivery: long polling and webhooks that never confirm an update before it is safe, and a SQLite queue that survives restarts (Long polling, Webhooks, Storage and failed updates).

  • Safe retries and rate limits: every send has a sendId, so a retry never writes a message twice; the client waits on 429 and paces itself like the server does (Rate limits).

  • Async and sync with the same features: Bot and SyncBot, AsyncClient and Client (Async and sync).

Where to start

  1. Install the library.

  2. Write your first bot.

  3. Read the guides when you need them.

  4. Before you go to production: Cryptography, Running in production and Security.

The API reference is generated from the docstrings in the code, so the same text is also available offline: help(pgpcbot.Bot) in Python, or python -m pydoc pgpcbot.Bot in a terminal.