Skip to main content

RFC1459 and IRCv3 protocol tokeniser

Project description


Build Status


there's far too many IRC client implementations out in the world that do not tokenise data correctly and thus fall victim to things like colons either being where you don't expect them or not being where you expect them.



$ pip3 install irctokens


>>> import irctokens
>>> line = irctokens.tokenise(
...     "@id=123 :jess!~jess@hostname PRIVMSG #chat :hello there!")
>>> line.tags
{'id': '123'}
>>> line.source
>>> line.hostmask
Hostmask(nickname='jess', username='~jess', hostname='hostname')
>>> line.command
>>> line.params
['#chat', 'hello there!']


>>>"USER", ["user", "0", "*", "real name"]).format()
'USER user 0 * :real name'


below is an example of a fully socket-wise safe IRC client connection that will connect and join a channel. both protocol sending and receiving are handled by irctokens.

import irctokens, socket

NICK = "nickname"
CHAN = "#channel"

d = irctokens.StatefulDecoder()
e = irctokens.StatefulEncoder()
s = socket.socket()
s.connect(("", 6667))

def _send(line):
    print(f"> {line.format()}")
    while e.pending():

_send("USER", ["username", "0", "*", "real name"]))
_send("NICK", [NICK]))

while True:
    lines = d.push(s.recv(1024))
    if lines == None:
        print("! disconnected")

    for line in lines:
        print(f"< {line.format()}")
        if line.command == "PING":
            to_send ="PONG", [line.params[0]])

        elif line.command == "001":
            to_send ="JOIN", [CHAN])


Come say hi at #irctokens on

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

irctokens-2.0.2.tar.gz (7.0 kB view hashes)

Uploaded Source

Built Distribution

irctokens-2.0.2-py3-none-any.whl (10.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page