• Stars
    star
    153
  • Rank 241,914 (Top 5 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An IRCv3-compliant Python 3 IRC library.

pydle

Python IRC library.

pydle is a compact, flexible and standards-abiding IRC library for Python 3.6 through 3.9.

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')
loop = asyncio.get_event_loop()
asyncio.ensure_future(client.connect('irc.rizon.net', tls=True, tls_verify=False), loop=loop)
loop.run_forever()

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, join us 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.

More Repositories

1

rpatool

A tool to work with Ren'Py archives.
Python
528
star
2

arcade-docs

Open arcade documentation repository
98
star
3

unimgc

HDD Raw Copy Tool IMGC format tools
C
57
star
4

smol

Shoddy minsize-oriented linker
Python
54
star
5

renpy2linux

Convert a Windows Ren'Py-based game into a Linux-compatible one.
Shell
27
star
6

res1gn

Simple pure-software System ES1 exploit
Shell
18
star
7

liner

Linux demoscene starter kit
Makefile
17
star
8

img4

various low-level Apple data structure tools
Python
14
star
9

restruct

Declarative binary file format parser and emitter library
Python
9
star
10

gfxi

PC-98 graphics library.
C
9
star
11

grsecurity-research

Shell
8
star
12

nene

Broadcast your currently watching shows to Discord!
JavaScript
7
star
13

binja-depanalyzer

Binary Ninja plugin to analyze dependencies in greater depth
Python
6
star
14

libgface

A library to easily include gface support in your application. Requires a gface license.
Python
5
star
15

reversion

Fix boobytrapped macOS system libraries
C
4
star
16

destruct

Declarative binary and text format parsing.
Python
4
star
17

mpv-ipc.js

Javascript IPC client for mpv
JavaScript
4
star
18

clippy

Easy Python clipboard management.
Python
3
star
19

dyld

Upstream dyld source hacked to compile with non-internal SDKs
C
3
star
20

seven-proxies

good luck finding me, I'm behind 7 proxied system DLLs
Shell
3
star
21

micromanage

sigma loop's AFK streamer and IRC bot.
Python
3
star
22

flashkit-mdc

Fork of git://notaz.gp2x.de/~notaz/flashkit-mdc.git with Windows support
C
3
star
23

upaste

Plain file based Python pastebin.
Python
3
star
24

focon-util

Utility to talk to some industrial devices from Focon Electronics Systems A/S
Python
3
star
25

rpy-to-pptx

Ren'Py to Powerpoint converter
Python
2
star
26

vm-utils

QEMU VM management scripts
Shell
2
star
27

arcade-docs-media

Media storage for arcade-docs repository
2
star
28

ida-tools

¯\_(ツ)_/¯
Python
2
star
29

finite

Fine init environment.
C
1
star
30

atwork

Easy progress UI library for Python
Python
1
star
31

tqsh

A vn engine in bash.
Shell
1
star
32

noissuu

Python
1
star