Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pinhook: python irc bot framework

pinhook

Python IRC bot framework. Write plugins as typed async functions. pinhook handles the connection, IRCv3, rate limits, access control and reloading.

Python versions PyPI License With love from tilde.town

Install

pinhook needs Python 3.11 or newer.

pip install pinhook

Create a bot

pinhook new bot gamebot
cd gamebot

This makes config.yaml, plugins/ with an example plugin, tests/ with its test, and the recipes/, data/ and logs/ folders.

Configure it

Edit config.yaml:

nickname: 'gamebot'
server: 'irc.libera.chat'
port: 6697
ssl_required: true
channels:
  - '#gamebot-test'
ops:
  - '$a:youraccount'
bot_dir: '.'

$a:youraccount makes your services account an op, so nobody else gets op powers by taking your nick. Quote channel names: YAML reads an unquoted # as the start of a comment.

Write a plugin

Save this as plugins/dice.py:

import random

from pinhook import command


@command('roll', help='roll dice, like roll 2 20')
async def roll(ctx, count: int = 1, sides: int = 6):
    rolls = [random.randint(1, sides) for _ in range(count)]
    await ctx.reply(f'{ctx.nick} rolled {sum(rolls)} {rolls}')

Arguments come from the message, converted to their annotated types. !roll 2 20 runs roll with count=2 and sides=20. !roll two gets the usage line back: usage: roll [count=1] [sides=6] (count must be a whole number).

Run it

pinhook check config.yaml
pinhook run config.yaml

check validates the config, plugins and recipes without connecting. run connects and joins #gamebot-test. Say !roll 2 20 there. Say !reload to load plugin changes without restarting.

Test it

Save this as tests/test_dice.py, then run pytest:

from pinhook.testing import TestBot


def test_roll():
    bot = TestBot(plugin_dir='plugins')
    assert bot.say('!roll 3 1', nick='ana') == ['ana rolled 3 [1, 1, 1]']

TestBot runs the real bot on a fake network, with no server and no waiting on rate limits.

Restrict a command

Mark the command restricted:

@command('weather', restricted=True)

Give someone access from chat, as an op:

!allow !weather carol
!access !weather

pinhook saves carol's services account, or their user and host, not their nick. Access levels covers groups, denies and setting levels in the config.

Add a command without code

Save this as recipes/gamenight.yaml:

version: 1
name: gamenight
help: pick tonight's game and who goes first
steps:
  - command: 'quote random games'
    save: game
  - reply: 'Tonight: {game}. {members|random} goes first'

!gamenight runs the steps in order, as the person who asked. Ops add one-line reply recipes from chat: !recipe add hug {nick} hugs {arg|default:everyone}.

Run on Twitch

Save this as twitch.yaml:

platform: twitch
nickname: 'gamebot'
channels:
  - '#yourchannel'
token: '${TWITCH_TOKEN}'
bot_dir: '.'

Save the bot account's OAuth token, then run the bot:

pinhook connect twitch twitch.yaml
pinhook run twitch.yaml

connect keeps the token in secrets.env, readable only by you. Twitch covers Twitch's rate limits, badges as access groups, and the private messages and notices Twitch doesn't deliver.

Deploy it

docker run -d -v ./config.yaml:/bot/config.yaml:ro -v ./plugins:/bot/plugins:ro \
  -v gamebot-data:/bot/data ghcr.io/archangelic/pinhook:2

The image logs to stdout and serves a health endpoint on port 8080. Deployment has compose, systemd and Kubernetes examples.

Add an LLM agent

vermilion is a separate package that turns a pinhook bot into an LLM agent, with the bot's own commands as its tools. pinhook has no LLM code of its own.

Upgrade from 1.x

Plugins written with pinhook.plugin run on 2.0 through a compatibility layer. Migrating from 1.x lists what changed for plugins, Bot subclasses and config files.

Docs

Bots using pinhook

License

MIT

Metadata

Release files for pinhook 2.0.0rc1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pinhook 2.0.0rc1
File Size Uploaded Provenance Actions
pinhook-2.0.0rc1.tar.gz 163.7 kB With provenance Details for pinhook-2.0.0rc1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pinhook 2.0.0rc1
File Interpreter ABI Platform Actions
pinhook-2.0.0rc1-py3-none-any.whl Python 3 none any Details for pinhook-2.0.0rc1-py3-none-any.whl

Total release size: 264.9 kB

Release files / pinhook-2.0.0rc1.tar.gz

Download URL pinhook-2.0.0rc1.tar.gz
Size 163.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dfe36334d09a9191244b6e767e7aa569b80a3bf394be696da3a332335ea93efd
BLAKE2b-256 checksum
How to use checksums
75ac67bfb6c9528de4dbb7ddbcefff100d5ce92d6e3bf2ec0bf50a56fa40979c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / pinhook-2.0.0rc1-py3-none-any.whl

Download URL pinhook-2.0.0rc1-py3-none-any.whl
Size 101.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ac93fec74bd83bf7c055cfb2cd69c45d8b2eb5b8226d6a055e7997524bd5b9b
BLAKE2b-256 checksum
How to use checksums
b3253697998a732838156aff6d6ef474a65b262c479f4e59b4ae1fe0a4256b49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for pinhook 2.0.0rc1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pinhook-2.0.0rc1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page