Skip to main content

A compact, flexible, and standards-abiding IRC library for python3.

Project description

pydle

Python IRC library.

pydle is a compact, flexible and standards-abiding IRC library for Python 3.10+.

Features

  • Well-organized: Thanks to the modularized feature system, it's not hard to find what you're looking for in the well-organised source code.
  • Standards-abiding: Based on RFC1459 with some small extension tweaks, with full support of optional extension standards:
  • Asynchronous: IRC is an asynchronous protocol and so should be a library that implements it. Coroutines are used to process events from the server asynchronously.
  • Modularised and extensible: Features on top of RFC1459 are implemented as separate modules for a user to pick and choose, and write their own. Broad features are written to be as extensible as possible.
  • Liberally licensed: The 3-clause BSD license ensures you can use it everywhere.

Basic Usage

pip install pydle

From there, you can import pydle and subclass pydle.Client for your own functionality.

To enable SSL support, install the sasl extra. pip install pydle[sasl]

Setting a nickname and starting a connection over TLS:

import pydle

# Simple echo bot.
class MyOwnBot(pydle.Client):
    async def on_connect(self):
         await self.join('#bottest')

    async def on_message(self, target, source, message):
         # don't respond to our own messages, as this leads to a positive feedback loop
         if source != self.nickname:
            await self.message(target, message)

client = MyOwnBot('MyBot', realname='My Bot')
client.run('irc.rizon.net', tls=True, tls_verify=False)

But wait, I want to handle multiple clients!

No worries! Use pydle.ClientPool like such:

pool = pydle.ClientPool()
for i in range(10):
    client = MyOwnBot('MyBot' + str(i))
    pool.connect(client, 'irc.rizon.net', 6697, tls=True, tls_verify=False)

# This will make sure all clients are treated in a fair way priority-wise.
pool.handle_forever()

Furthermore, since pydle is simply asyncio-based, you can run the client in your own event loop, like this:

import asyncio

client = MyOwnBot('MyBot')
asyncio.run(client.connect('irc.rizon.net', tls=True, tls_verify=False))

Customization

If you want to customize bot features, you can subclass pydle.BasicClient and one or more features from pydle.features or your own feature classes, like such:

# Only support RFC1459 (+small features), CTCP and our own ACME extension to IRC.
class MyFeaturedBot(pydle.features.ctcp.CTCPSupport, acme.ACMESupport, rfc1459.RFC1459Support):
    pass

To create your own features, just subclass from pydle.BasicClient and start adding callbacks for IRC messages:

# Support custom ACME extension.
class ACMESupport(pydle.BasicClient):
    async def on_raw_999(self, source, params):
        """ ACME's custom 999 numeric tells us to change our nickname. """
        nickname = params[0]
        await self.set_nickname(nickname)

FAQ

Q: When constructing my own client class from several base classes, I get the following error: TypeError: Cannot create a consistent method resolution order (MRO) for bases X, Y, Z. What causes this and how can I solve it?

Pydle's use of class inheritance as a feature model may cause method resolution order conflicts if a feature inherits from a different feature, while a class inherits from both the original feature and the inheriting feature. To solve such problem, pydle offers a featurize function that will automatically put all classes in the right order and create an appropriate base class:

# Purposely mis-ordered base classes, as SASLSupport inherits from CapabilityNegotiationSupport, but everything works fine.
MyBase = pydle.featurize(pydle.features.CapabilityNegotiationSupport, pydle.features.SASLSupport)
class Client(MyBase):
    pass

Q: How do I...?

Stop! Read the documentation first. If you're still in need of support, please raise a new issue in this repository! Also, we are on IRC! We hang at #pydle on irc.libera.chat. If someone is around, they'll most likely gladly help you.

License

Pydle is licensed under the 3-clause BSD license. See LICENSE.md for details.

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

pydle-1.1.0.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

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

pydle-1.1.0-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydle-1.1.0.tar.gz
Algorithm Hash digest
SHA256 019eabd94060c2e46f1a88f53571390bba4865f5b61ab2f3e98d637d649e40d1
MD5 afc8a86c89c36bac7a82c3bc92ace7a2
BLAKE2b-256 71b3f52fac7b3e2492bfa064d41e1763a7692e4e37eb210b4293239c6e56a81c

See more details on using hashes here.

Provenance

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

Publisher: publish.yaml on shizmob/pydle

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

File details

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

File metadata

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

File hashes

Hashes for pydle-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60b30d987b67da3453cf35d27048e59ef3d09704d26c5a3199f50175b9f22dbe
MD5 8bc0800015c2f9323fffec8dbb819e71
BLAKE2b-256 088acd1a9b2f5e2e7e26c122ebdbc74f27b0b6767febc40032ead31b9a72a582

See more details on using hashes here.

Provenance

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

Publisher: publish.yaml on shizmob/pydle

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