Package: irc
Full-featured Python IRC library for Python.Project homeDocsHistoryOverviewThis 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 theIRC specifications.Client FeaturesThe main features of the IRC client framework are:Abstraction of the IRC protocol.Handles multiple simultaneous IRC server connections.Handles server PONGing transparently.Messages to the IRC server are done by calling methods on an IRC
connection object.Messages from an IRC server triggers events, which can be caught
by event handlers.Multiple options for reading from and writing to an IRC server:
you can use sockets in an internalselect()loop OR use
Python3’s asyncio event loopFunctions can be registered to execute at specified times by the
event-loop.Decodes CTCP tagging correctly (hopefully); I haven’t seen any
other IRC client implementation that handles the CTCP
specification subtleties.A kind of simple, single-server, object-oriented IRC client class
that dispatches events to instance methods is included.DCC connection support.Current limitations:The IRC protocol shines through the abstraction a bit too much.Data is not written asynchronously to the server (and DCC peers),
i.e. thewrite()may block if the TCP buffers are stuffed.Like most projects, documentation is lacking …DCC is not currently implemented in the asyncio-based versionUnfortunately, 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 programirccat, which is included in the
distribution.The following modules might be of interest:irc.clientThe 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!irc.client_aioAll the functionality of the above library, but utilizing
Python 3’s native asyncio library for the core event loop.
Interface/API is otherwise functionally identical to the classes
inirc.clientirc.botAn IRC bot implementation.irc.serverA basic IRC server implementation. Suitable for testing, but not
intended as a production service.Invoke the server withpython-mirc.server.ExamplesExample scripts in the scripts directory:irccatA simple example of how to use the IRC client.irccatreads
text from stdin and writes it to a specified user or channel on
an IRC server.irccat2The same as above, but using theSimpleIRCClientclass.aio_irccatSame as above, but uses the asyncio-based event loop inAioReactorinstead of theselect()basedReactor.aio_irccat2Same as above, but using theAioSimpleIRCClientclassservermapAnother simple example.servermapconnects to an IRC server,
finds out what other IRC servers there are in the net and prints
a tree-like map of their interconnections.testbotAn example bot that uses theSingleServerIRCBotclass fromirc.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.dccreceiveReceives a file over DCC.dccsendSends 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\\#testor"#test"instead of#test.Scheduling EventsThe library includes a default event Scheduler asirc.schedule.DefaultScheduler,
but this scheduler can be replaced with any other scheduler. For example,
to use theschedulepackage,
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):schedule.every(period).do(func)def execute_at(self, when, func):schedule.at(when).do(func)def execute_after(self, delay, func):raise NotImplementedError(“Not supported”)def run_pending(self):schedule.run_pending()irc.client.Reactor.scheduler_class = ScheduleSchedulerDecoding InputBy 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 theServerConnectionclass. Thebuffer_classattribute on theServerConnectiondetermines which class is used for buffering lines from the
input stream, using thebuffermodule injaraco.stream. By default it isbuffer.DecodingLineBuffer, but may be
re-assigned with another class, following the interface ofbuffer.LineBuffer.
Thebuffer_classattribute may be assigned for all instances ofServerConnectionby overriding the class attribute.For example:fromjaraco.streamimportbufferirc.client.ServerConnection.buffer_class=buffer.LenientDecodingLineBufferTheLenientDecodingLineBufferattempts UTF-8 but falls back to latin-1, which
will avoidUnicodeDecodeErrorin 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.Reactor().server()server.buffer_class=buffer.LenientDecodingLineBufferserver.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:classIgnoreErrorsBuffer(buffer.DecodingLineBuffer):defhandle_exception(self):passirc.client.ServerConnection.buffer_class=IgnoreErrorsBufferThe library requires text for message
processing, so a decoding buffer must be used. Clients
must use one of the above techniques for decoding input to text.Notes and Contact InfoEnjoy.Maintainer:
Jason R. Coombs <jaraco@jaraco.com>Original Author:
Joel Rosdahl <joel@rosdahl.net>Copyright © 1999-2002 Joel Rosdahl
Copyright © 2011-2016 Jason R. Coombs
Copyright © 2009 Ferry BoenderFor EnterpriseAvailable as part of the Tidelift Subscription.This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.Learn more.