2. girc.client.ServerConnection — Single Server Connection

class girc.client.ServerConnection

This class handles a connection to a single IRC server. It’s created by your girc.Reactor using girc.Reactor.create_server(), and usually accessed from events.

2.1. Connection

These functions let you set connection information and actually connect to a network!

ServerConnection.set_user_info(nick, user='*', real='*')

Sets user info for this server, to be used before connection.

  • nick (str) – Nickname to use.
  • user (str) – Username to use.
  • real (str) – Realname to use.

Sets connect password for this server, to be used before connection.

Parameters:password (str) – Password to connect with.
ServerConnection.join_channels(*channels, wait_seconds=0)

This example joins the channels #example and #cool:

server.join_channels('#example', '#cool')
ServerConnection.connect(*args, auto_reconnect=False, **kwargs)

Connects to the given server.

Parameters:auto_reconnect (bool) – Automatically reconnect on disconnection.

Other arguments to this function are as usually supplied to asyncio.BaseEventLoop.create_connection().

This method should be called once the necessary user info is set using girc.client.ServerConnection.set_user_info()

2.2. Authentication

These should usually be used before girc.client.ServerConnection.connect() is called, as we will automatically try to authenticate once connected. These specify different ways for us to authenticate with the network.

ServerConnection.sasl_plain(name, password, identity=None)

Authenticate to a server using SASL plain, or does so on connection.

  • name (str) – Name to auth with.
  • password (str) – Password to auth with.
  • identity (str) – Identity to auth with (defaults to name).

2.3. IRC casemapping

One of the important features of girc.client.ServerConnection objects is the ability to easily create strings, lists, and dictionaries that follow the IRC server’s casemapping. This is done using the following functions:


Return a string that uses this server’s IRC casemapping.

This string’s equality with other strings, lower(), and upper() takes this server’s casemapping into account. This should be used for things such as nicks and channel names, where comparing strings using the correct casemapping can be very important.


Return a list that uses this server’s IRC casemapping.

All strings in this list are lowercased using the server’s casemapping before inserting them into the list, and the in operator takes casemapping into account.


Return a dict that uses this server’s IRC casemapping.

All keys in this dictionary are stored and compared using this server’s casemapping.

2.4. Sending messages and actions

These are the main ways you’ll interact with the server directly. It lets you send IRC messages directly to the server using a general sending function, as well as convenience methods for specific messages:

ServerConnection.send(verb, params=None, source=None, tags=None)

Send a generic IRC message to the server.

A message is created using the various parts of the message, then gets assembled and sent to the server.

  • verb (str) – Verb, such as PRIVMSG.
  • params (list of str) – Message parameters, defaults to no params.
  • source (str) – Source of the message, defaults to no source.
  • tags (dict) – Tags to send with the message.
ServerConnection.action(target, message, formatted=True, tags=None)

Send an action to the given target.

ServerConnection.msg(target, message, formatted=True, tags=None)

Send a privmsg to the given target.

ServerConnection.notice(target, message, formatted=True, tags=None)

Send a notice to the given target.

ServerConnection.ctcp(target, ctcp_verb, argument=None)

Send a CTCP request to the given target.

ServerConnection.ctcp_reply(target, ctcp_verb, argument=None)

Send a CTCP reply to the given target.

ServerConnection.join_channel(channel, key=None, tags=None)

Join the given channel.

ServerConnection.part_channel(channel, reason=None, tags=None)

Part the given channel.

ServerConnection.mode(target, mode_string=None, tags=None)

Sends new modes to or requests existing modes from the given target.