Skip to content
Back to top
View this page

# BaseXMPP

class slixmpp.basexmpp.BaseXMPP(jid='', default_ns='jabber:client', **kwargs)

  The BaseXMPP class adapts the generic XMLStream class for use with XMPP. It also provides a plugin mechanism to easily extend and add support for new XMPP features.

  Parameters:

    default_ns – Ensure that the correct default XML namespace is used during initialization.

  Iq(*args, **kwargs)

    Create an Iq stanza associated with this stream.

    Return type:

      `Iq`

  Message(*args, **kwargs)

    Create a Message stanza associated with this stream.

    Return type:

      `Message`

  Presence(*args, **kwargs)

    Create a Presence stanza associated with this stream.

    Return type:

      `Presence`

  api

    The API registry is a way to process callbacks based on JID+node combinations. Each callback in the registry is marked with:

    > - An API name, e.g. xep_0030

    > - The name of an action, e.g. get_info

    > - The JID that will be affected

    > - The node that will be affected

    API handlers with no JID or node will act as global handlers, while those with a JID and no node will service all nodes for a JID, and handlers with both a JID and node will be used only for that specific combination. The handler that provides the most specificity will be used.

  property auto_authorize: bool | None

    Auto accept or deny subscription requests.

    If `True`, auto accept subscription requests. If `False`, auto deny subscription requests. If `None`, don’t automatically respond.

  property auto_subscribe: bool

    Auto send requests for mutual subscriptions.

    If `True`, auto send mutual subscription requests.

  boundjid

    The JabberID (JID) used by this connection, as set after session binding. This may even be a different bare JID than what was requested.

  client_roster

    The single roster for the bound JID. This is the equivalent of:

        self.roster[self.boundjid.bare]

  exception(exception)

    Process any uncaught exceptions, notably `IqError` and `IqTimeout` exceptions.

    Parameters:

      exception – An unhandled `Exception` object.

  property fulljid: str

    Attribute accessor for full jid

  get(key, default=None)

    Return a plugin given its name, if it has been registered.

  is_component

    The distinction between clients and components can be important, primarily for choosing how to handle the `'to'` and `'from'` JIDs of stanzas.

  property jid: str

    Attribute accessor for bare jid

  make_iq(id=None, ifrom=None, ito=None, itype=None, iquery=None)

    Create a new `Iq` stanza with a given Id and from JID.

    Parameters:

      - id (`str` | `None`) – An ideally unique ID value for this stanza thread.

      - ifrom (`str` | `JID` | `None`) – The from `JID` to use for this stanza.

      - ito (`str` | `JID` | `None`) – The destination `JID` for this stanza.

      - itype (`Literal`[`'error'`, `'get'`, `'set'`, `'result'`] | `None`) – The `Iq`’s type, one of: `'get'`, `'set'`, `'result'`, or `'error'`.

      - iquery (`str` | `None`) – Optional namespace for adding a query element.

    Return type:

      `Iq`

  make_iq_error(id, type='cancel', condition='feature-not-implemented', text=None, ito=None, ifrom=None, iq=None)

    Create an `Iq` stanza of type `'error'`.

    Parameters:

      - id – An ideally unique ID value. May use `new_id()`.

      - type – The type of the error, such as `'cancel'` or `'modify'`. Defaults to `'cancel'`.

      - condition – The error condition. Defaults to `'feature-not-implemented'`.

      - text – A message describing the cause of the error.

      - ito – The destination `JID` for this stanza.

      - ifrom – The `'from'` `JID` to use for this stanza.

      - iq – Optionally use an existing stanza instead of generating a new one.

  make_iq_get(queryxmlns=None, ito=None, ifrom=None, iq=None)

    Create an `Iq` stanza of type `'get'`.

    Optionally, a query element may be added.

    Parameters:

      - queryxmlns (`str` | `None`) – The namespace of the query to use.

      - ito (`str` | `JID` | `None`) – The destination `JID` for this stanza.

      - ifrom (`str` | `JID` | `None`) – The `'from'` `JID` to use for this stanza.

      - iq (`Iq` | `None`) – Optionally use an existing stanza instead of generating a new one.

    Return type:

      `Iq`

  make_iq_query(iq=None, xmlns='', ito=None, ifrom=None)

    Create or modify an `Iq` stanza to use the given query namespace.

    Parameters:

      - iq (`Iq` | `None`) – Optionally use an existing stanza instead of generating a new one.

      - xmlns (`str`) – The query’s namespace.

      - ito (`str` | `JID` | `None`) – The destination `JID` for this stanza.

      - ifrom (`str` | `JID` | `None`) – The `'from'` `JID` to use for this stanza.

    Return type:

      `Iq`

  make_iq_result(id=None, ito=None, ifrom=None, iq=None)

    Create an `Iq` stanza of type `'result'` with the given ID value.

    Parameters:

      - id (`str` | `None`) – An ideally unique ID value. May use `new_id()`.

      - ito (`str` | `JID` | `None`) – The destination `JID` for this stanza.

      - ifrom (`str` | `JID` | `None`) – The `'from'` `JID` to use for this stanza.

      - iq (`Iq` | `None`) – Optionally use an existing stanza instead of generating a new one.

    Return type:

      `Iq`

  make_iq_set(sub=None, ito=None, ifrom=None, iq=None)

    Create an `Iq` stanza of type `'set'`.

    Optionally, a substanza may be given to use as the stanza’s payload.

    Parameters:

      - sub (`ElementBase` | `Element` | `None`) – Either an `ElementBase` stanza object or an `Element` XML object to use as the `Iq`’s payload.

      - ito (`str` | `JID` | `None`) – The destination `JID` for this stanza.

      - ifrom (`str` | `JID` | `None`) – The `'from'` `JID` to use for this stanza.

      - iq (`Iq` | `None`) – Optionally use an existing stanza instead of generating a new one.

    Return type:

      `Iq`

  make_message(mto, mbody=None, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None)

    Create and initialize a new `Message` stanza.

    Parameters:

      - mto (`str` | `JID`) – The recipient of the message.

      - mbody (`str` | `None`) – The main contents of the message.

      - msubject (`str` | `None`) – Optional subject for the message.

      - mtype (`Literal`[`'chat'`, `'error'`, `'groupchat'`, `'headline'`, `'normal'`] | `None`) – The message’s type, such as `'chat'` or `'groupchat'`.

      - mhtml (`str` | `None`) – Optional HTML body content in the form of a string.

      - mfrom (`str` | `JID` | `None`) – The sender of the message. if sending from a client, be aware that some servers require that the full JID of the sender be used.

      - mnick (`str` | `None`) – Optional nickname of the sender.

    Return type:

      `Message`

  make_presence(pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None, pnick=None)

    Create and initialize a new `Presence` stanza.

    Parameters:

      - pshow (`str` | `None`) – The presence’s show value.

      - pstatus (`str` | `None`) – The presence’s status message.

      - ppriority (`int` | `None`) – This connection’s priority.

      - pto (`str` | `JID` | `None`) – The recipient of a directed presence.

      - ptype (`Literal`[`'error'`, `'probe'`, `'subscribe'`, `'subscribed'`, `'unavailable'`, `'unsubscribe'`, `'unsubscribed'`] | `None`) – The type of presence, such as `'subscribe'`.

      - pfrom (`str` | `JID` | `None`) – The sender of the presence.

      - pnick (`str` | `None`) – Optional nickname of the presence’s sender.

    Return type:

      `Presence`

  make_query_roster(iq=None)

    Create a roster query element.

    Parameters:

      iq (`Iq` | `None`) – Optionally use an existing stanza instead of generating a new one.

    Return type:

      `Element`

  max_redirects

    The maximum number of consecutive see-other-host redirections that will be followed before quitting.

  plugin: PluginsDict

    A dictionary mapping plugin names to plugins.

  plugin_config

    Configuration options for whitelisted plugins. If a plugin is registered without any configuration, and there is an entry here, it will be used.

  plugin_whitelist

    A list of plugins that will be loaded if `register_plugins()` is called.

  register_plugin(plugin, pconfig=None, module=None)

    Register and configure a plugin for use in this stream.

    Parameters:

      - plugin (`str`) – The name of the plugin class. Plugin names must be unique.

      - pconfig (`dict` | `None`) – A dictionary of configuration data for the plugin. Defaults to an empty dictionary.

      - module – Optional reference to the module containing the plugin class if using custom plugins.

  register_plugins()

    Register and initialize all built-in plugins.

    Optionally, the list of plugins loaded may be limited to those contained in `plugin_whitelist`.

    Plugin configurations stored in `plugin_config` will be used.

  requested_jid

    The JabberID (JID) requested for this connection.

  property resource: str

    Attribute accessor for jid resource

  roster

    The main roster object. This roster supports multiple owner JIDs, as in the case for components. For clients which only have a single JID, see `client_roster`.

  send_message(mto, mbody=None, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None)

    Create, initialize, and send a new `Message` stanza.

    Parameters:

      - mto (`JID`) – The recipient of the message.

      - mbody (`str` | `None`) – The main contents of the message.

      - msubject (`str` | `None`) – Optional subject for the message.

      - mtype (`Literal`[`'chat'`, `'error'`, `'groupchat'`, `'headline'`, `'normal'`] | `None`) – The message’s type, such as `'chat'` or `'groupchat'`.

      - mhtml (`str` | `None`) – Optional HTML body content in the form of a string.

      - mfrom (`str` | `JID` | `None`) – The sender of the message. if sending from a client, be aware that some servers require that the full JID of the sender be used.

      - mnick (`str` | `None`) – Optional nickname of the sender.

  send_presence(pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None, pnick=None)

    Create, initialize, and send a new `Presence` stanza.

    Parameters:

      - pshow (`str` | `None`) – The presence’s show value.

      - pstatus (`str` | `None`) – The presence’s status message.

      - ppriority (`int` | `None`) – This connection’s priority.

      - pto (`str` | `JID` | `None`) – The recipient of a directed presence.

      - ptype (`Literal`[`'error'`, `'probe'`, `'subscribe'`, `'subscribed'`, `'unavailable'`, `'unsubscribe'`, `'unsubscribed'`] | `None`) – The type of presence, such as `'subscribe'`.

      - pfrom (`str` | `JID` | `None`) – The sender of the presence.

      - pnick (`str` | `None`) – Optional nickname of the presence’s sender.

  send_presence_subscription(pto, pfrom=None, ptype='subscribe', pnick=None)

    Create, initialize, and send a new `Presence` stanza of type `'subscribe'`.

    Parameters:

      - pto (`str` | `JID`) – The recipient of a directed presence.

      - pfrom (`str` | `JID` | `None`) – The sender of the presence.

      - ptype (`Literal`[`'error'`, `'probe'`, `'subscribe'`, `'subscribed'`, `'unavailable'`, `'unsubscribe'`, `'unsubscribed'`]) – The type of presence, such as `'subscribe'`.

      - pnick (`str` | `None`) – Optional nickname of the presence’s sender.

  sentpresence

    Flag indicating that the initial presence broadcast has been sent. Until this happens, some servers may not behave as expected when sending stanzas.

  property server: str

    Attribute accessor for jid host

  set_jid(jid)

    Rip a JID apart and claim it as our own.

  stanza

    A reference to `slixmpp.stanza` to make accessing stanza classes easier.

  start_stream_handler(xml)

    Save the stream ID once the streams have been established.

    Parameters:

      xml – The incoming stream’s root element.

  stream_id

    An identifier for the stream as given by the server.

  use_message_ids

    Messages may optionally be tagged with ID values. Setting `use_message_ids` to True will assign all outgoing messages an ID. Some plugin features require enabling this option.

  use_origin_id

    XEP-0359 <origin-id/> tag that gets added to <message/> stanzas.

  use_presence_ids

    Presence updates may optionally be tagged with ID values. Setting `use_message_ids` to True will assign all outgoing messages an ID.

  property username: str

    Attribute accessor for jid usernode