Skip to main content

Async IRC library for Python 3.14+

Project description

ircio

An asynchronous IRC client library for Python 3.14+, built on top of asyncio.

Features

  • Fully async — all I/O is non-blocking via asyncio.StreamReader/StreamWriter
  • IRCv3 message tags — parsed and serialised transparently
  • TLS — plain ssl=True for system CA verification, or pass a custom ssl.SSLContext for client certificates and private networks
  • SASL authentication
    • PLAIN — username and password (RFC 4616)
    • EXTERNAL — identity delegated to the TLS certificate
    • ECDSA-NIST256P-CHALLENGE — challenge–response using an ECDSA key on the NIST P-256 curve (used by Libera.Chat and other networks)
  • Event dispatcher — register async handlers per command, with wildcard ("*") support
  • Structured concurrency — handlers are dispatched via asyncio.TaskGroup

Requirements

  • Python ≥ 3.14
  • uv (recommended) or any PEP 517-compatible build tool

Optional, for ECDSA-NIST256P-CHALLENGE:

pip install "ircio[ecdsa]"

Quick start

import asyncio
from ircio import Client

client = Client(
    "irc.libera.chat",
    6697,
    nick="mybot",
    user="mybot",
    realname="My Bot",
    ssl=True,
)

@client.on("PRIVMSG")
async def on_privmsg(msg):
    target = msg.params[0]
    text   = msg.params[1]
    print(f"[{target}] {msg.prefix}: {text}")

async def main():
    await client.connect()
    await client.join("#python")
    await client.run()

asyncio.run(main())

SASL authentication

PLAIN

from ircio import Client, SASLPlain

client = Client(
    "irc.libera.chat", 6697,
    nick="mybot", user="mybot", realname="My Bot",
    ssl=True,
    sasl=SASLPlain("mybot", "s3cr3t"),
)

ECDSA-NIST256P-CHALLENGE

Register your public key with NickServ, then authenticate using the corresponding private key:

from ircio import Client, SASLEcdsaNist256pChallenge

sasl = SASLEcdsaNist256pChallenge.from_pem_file("mybot", "~/.irc/key.pem")

client = Client(
    "irc.libera.chat", 6697,
    nick="mybot", user="mybot", realname="My Bot",
    ssl=True,
    sasl=sasl,
)

Generate a key with OpenSSL:

openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out ~/.irc/key.pem
openssl pkey -in ~/.irc/key.pem -pubout

Provide the public key to NickServ: /msg NickServ SET PUBKEY <base64-pubkey>.

EXTERNAL (client certificate)

import ssl
from ircio import Client, SASLExternal

ctx = ssl.create_default_context()
ctx.load_cert_chain("cert.pem", "key.pem")

client = Client(
    "irc.libera.chat", 6697,
    nick="mybot", user="mybot", realname="My Bot",
    ssl=ctx,
    sasl=SASLExternal(),
)

Low-level API

Connection and Dispatcher are exposed for use cases that require finer control:

from ircio import Connection, Dispatcher, Message

async def main():
    async with Connection("irc.libera.chat", 6697, ssl=True) as conn:
        await conn.send(Message("NICK", ["mybot"]))
        await conn.send(Message("USER", ["mybot", "0", "*", "My Bot"]))
        while True:
            msg = await conn.readline()
            print(msg)

Development

uv sync
uv run pytest
uv run ruff check src/ tests/
uv run ruff format src/ tests/

Pre-commit hooks (ruff linter + formatter) are installed automatically on first commit after:

uv run pre-commit install

Licence

MIT — see LICENSE.

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

ircio-1.1.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

ircio-1.1.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file ircio-1.1.0.tar.gz.

File metadata

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

File hashes

Hashes for ircio-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7ef117a94f3071d90ff70f509d75a253b2020466a4d4c08789fb44f0837f1ee4
MD5 33c8300e185da554ab364b2635b7e309
BLAKE2b-256 df95c4efca01b6680bea359d202cb5450fbec6d820991a04e9c294c79297ad87

See more details on using hashes here.

Provenance

The following attestation bundles were made for ircio-1.1.0.tar.gz:

Publisher: release.yml on pbiernacki/ircio

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

File details

Details for the file ircio-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: ircio-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ircio-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe8a4a5dc0618970a359aa31e953fe0a6fa662d390bc6aa5f4a225f933c7d02c
MD5 e96781ea43dacd0b4f802d3a9367ead2
BLAKE2b-256 15c7ba7e8a2cda3770188b8e0605b646a79092b0d7b4936f1a20c4fee8a0fe45

See more details on using hashes here.

Provenance

The following attestation bundles were made for ircio-1.1.0-py3-none-any.whl:

Publisher: release.yml on pbiernacki/ircio

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