IRC (Internet Relay Chat) protocol library for Python
Full-featured Python IRC library for Python.
License is indicated in the project metadata (typically one or more of the Trove classifiers). For more details, see this explanation.
This library provides a low-level implementation of the IRC protocol for Python. It provides an event-driven IRC client framework. It has a fairly thorough support for the basic IRC protocol, CTCP, and DCC connections.
In order to understand how to make an IRC client, it’s best to read up first on the IRC specifications.
IRC requires Python versions specified in the download pages and definitely supports Python 3.
You have several options to install the IRC project.
The main features of the IRC client framework are:
Unfortunately, this library isn’t as well-documented as I would like it to be. I think the best way to get started is to read and understand the example program irccat, which is included in the distribution.
The following modules might be of interest:
The library itself. Read the code along with comments and docstrings to get a grip of what it does. Use it at your own risk and read the source, Luke!
An IRC bot implementation.
A basic IRC server implementation. Suitable for testing, but not intended as a production service.
Invoke the server with python -m irc.server.
Example scripts in the scripts directory:
A simple example of how to use the IRC client. irccat reads text from stdin and writes it to a specified user or channel on an IRC server.
The same as above, but using the SimpleIRCClient class.
Another simple example. servermap connects to an IRC server, finds out what other IRC servers there are in the net and prints a tree-like map of their interconnections.
An example bot that uses the SingleServerIRCBot class from irc.bot. The bot enters a channel and listens for commands in private messages or channel traffic. It also accepts DCC invitations and echos back sent DCC chat messages.
Receives a file over DCC.
Sends a file over DCC.
NOTE: If you’re running one of the examples on a unix command line, you need to escape the # symbol in the channel. For example, use \\#test or "#test" instead of #test.
The library includes a default event Scheduler as irc.schedule.DefaultScheduler, but this scheduler can be replaced with any other scheduler. For example, to use the schedule package, include it in your dependencies and install it into the IRC library as so:
- class ScheduleScheduler(irc.schedule.IScheduler):
- def execute_every(self, period, func):
- def execute_at(self, when, func):
- def execute_after(self, delay, func):
- raise NotImplementedError(“Not supported”)
- def run_pending(self):
irc.client.Reactor.scheduler_class = ScheduleScheduler
By default, the IRC library attempts to decode all incoming streams as UTF-8, even though the IRC spec stipulates that no specific encoding can be expected. Since assuming UTF-8 is not reasonable in the general case, the IRC library provides options to customize decoding of input by customizing the ServerConnection class. The buffer_class attribute on the ServerConnection determines which class is used for buffering lines from the input stream, using the buffer module in jaraco.stream. By default it is buffer.DecodingLineBuffer, but may be re-assigned with another class, following the interface of buffer.LineBuffer. The buffer_class attribute may be assigned for all instances of ServerConnection by overriding the class attribute.
from jaraco.stream import buffer irc.client.ServerConnection.buffer_class = buffer.LenientDecodingLineBuffer
The LenientDecodingLineBuffer attempts UTF-8 but falls back to latin-1, which will avoid UnicodeDecodeError in all cases (but may produce unexpected behavior if an IRC user is using another encoding).
The buffer may be overridden on a per-instance basis (as long as it’s overridden before the connection is established):
server = irc.client.IRC().server() server.buffer_class = buffer.LenientDecodingLineBuffer server.connect()
Alternatively, some clients may still want to decode the input using a different encoding. To decode all input as latin-1 (which decodes any input), use the following:
irc.client.ServerConnection.buffer_class.encoding = 'latin-1'
Or decode to UTF-8, but use a replacement character for unrecognized byte sequences:
irc.client.ServerConnection.buffer_class.errors = 'replace'
Or, to simply ignore all input that cannot be decoded:
class IgnoreErrorsBuffer(buffer.DecodingLineBuffer): def handle_exception(self): pass irc.client.ServerConnection.buffer_class = IgnoreErrorsBuffer
On Python 2, it was possible to use the buffer.LineBuffer itself, which will pass the raw bytes. On Python 3, the library requires text for message processing, so a decoding buffer must be used. Therefore, use of the LineBuffer is considered deprecated and not supported on Python 3. Clients should use one of the above techniques for decoding input to text.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|irc-16.0-py2.py3-none-any.whl (74.4 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||Jun 24, 2017|
|irc-16.0.tar.gz (81.8 kB) Copy SHA256 Checksum SHA256||–||Source||Jun 24, 2017|