irc
raw JSON → 20.5.0 verified Fri May 01 auth: no python
IRC (Internet Relay Chat) protocol library for Python. Provides client and server implementations. Current version: 20.5.0. Release cadence: irregular, a few times per year.
pip install irc Common errors
error AttributeError: module 'irc' has no attribute 'client' ↓
cause Trying to import `irc.client` before installing the library or using a very old version where the module didn't exist.
fix
Ensure
pip install irc succeeded and version >=20.0.0. Use from irc import client or from irc.client import .... error TypeError: on_welcome() takes 2 positional arguments but 3 were given ↓
cause Callback signature mismatch: old code expects 2 arguments (self, event) but new API passes 3 (self, connection, event).
fix
Change method signature to
def on_welcome(self, connection, event):. Warnings
breaking In v20.0.0, the `irc.client` module was restructured. `irc.client.IRC` is now `irc.client.IRCClient`. Old imports break. ↓
fix Use `from irc.client import IRCClient` instead of `from irc.client import IRC`.
breaking In v20.0.0, `on_join`, `on_part`, etc. callbacks now receive `connection` and `event` arguments (previously different). ↓
fix Update callback signatures to `def on_join(self, connection, event):`.
gotcha The library uses Python's `select` module by default, which does not support Windows' socket behaviour. On Windows, it may hang or fail. ↓
fix Use an asynchronous event loop (e.g., `irc.client.aio`) or set `irc.client.ServerConnection.buffer_class = irc.buffer.LenientDecodingLineBuffer`.
Imports
- IRCClient wrong
from irc import IRCClientcorrectfrom irc.client import IRCClient - ServerConnection wrong
from irc import ServerConnectioncorrectfrom irc.client import ServerConnection
Quickstart
import irc.client
import os
server = 'irc.libera.chat'
port = 6667
nick = 'MyBot'
class MyClient(irc.client.SimpleIRCClient):
def on_welcome(self, connection, event):
connection.join('#testchannel')
def on_pubmsg(self, connection, event):
print(f"{event.source.nick}: {event.arguments[0]}")
client = MyClient()
client.connect(server, port, nick)
client.start()