Presence Stanza#

class slixmpp.stanza.Presence(*args, recv=False, **kwargs)[source]#

XMPP’s <presence> stanza allows entities to know the status of other clients and components. Since it is currently the only multi-cast stanza in XMPP, many extensions add more information to <presence> stanzas to broadcast to every entry in the roster, such as capabilities, music choices, or locations (XEP-0115: Entity Capabilities and XEP-0163: Personal Eventing Protocol).

Since <presence> stanzas are broadcast when an XMPP entity changes its status, the bulk of the traffic in an XMPP network will be from <presence> stanzas. Therefore, do not include more information than necessary in a status message or within a <presence> stanza in order to help keep the network running smoothly.

Example <presence> stanzas:

<presence />

<presence from="user@example.com">
  <show>away</show>
  <status>Getting lunch.</status>
  <priority>5</priority>
</presence>

<presence type="unavailable" />

<presence to="user@otherhost.com" type="subscribe" />
Stanza Interface:
  • priority: A value used by servers to determine message routing.

  • show: The type of status, such as away or available for chat.

  • status: Custom, human readable status message.

Attributes:
  • types: One of: available, unavailable, error, probe, subscribe, subscribed, unsubscribe, and unsubscribed.

  • showtypes: One of: away, chat, dnd, and xa.

del_type()[source]#

Remove both the type attribute and the <show> element.

get_priority()[source]#

Return the value of the <presence> element as an integer.

Return type:

int

get_type()[source]#

Return the value of the <presence> stanza’s type attribute, or the value of the <show> element if valid.

Return type:

str

interfaces: ClassVar[Set[str]] = {'from', 'id', 'priority', 'show', 'status', 'to', 'type'}#

The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the plugin_attrib value of any registered stanza plugins.

lang_interfaces: ClassVar[Set[str]] = {'status'}#

New in version 1.1.2.

name: ClassVar[str] = 'presence'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'jabber:client'#

The default XMPP client namespace

plugin_attrib: ClassVar[str] = 'presence'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
reply(clear=True)[source]#

Create a new reply <presence/> stanza from self.

Overrides StanzaBase.reply.

Parameters:

clear (bool) – Indicates if the stanza contents should be removed before replying. Defaults to True.

set_priority(value)[source]#

Set the entity’s priority value. Some server use priority to determine message routing behavior.

Bot clients should typically use a priority of 0 if the same JID is used elsewhere by a human-interacting client.

Parameters:

value (int) – An integer value greater than or equal to 0.

set_show(show)[source]#

Set the value of the <show> element.

Parameters:

show (str) – Must be one of: away, chat, dnd, or xa.

set_type(value)[source]#

Set the type attribute’s value, and the <show> element if applicable.

Parameters:

value (str) – Must be in either self.types or self.showtypes.

sub_interfaces: ClassVar[Set[str]] = {'priority', 'show', 'status'}#

A subset of interfaces which maps interfaces to direct subelements of the underlying XML object. Using this set, the text of these subelements may be set, retrieved, or removed without needing to define custom methods.