Skip to main content

SPADE

SPADE PubSub

Publish-subscribe communication for SPADE agents, with the XMPP Publish-Subscribe extension (XEP-0060).

PyPI Python versions MIT License Downloads Continuous Integration Coverage Documentation


Agents publish items in nodes of an XMPP PubSub service, and the agents subscribed to a node are notified of every new item. Publishers and subscribers do not need to know each other: a decoupled, one-to-many communication for your multi-agent systems.

📖 Documentation: stable · develop

Features

  • Nodes: create and delete nodes, list the nodes of a service and their subscribers, and purge their items.
  • Items: publish text or any XML element, read the items stored in a node, and retract them.
  • Notifications: register a callback, and your agent is notified as soon as an item is published or retracted.
  • Standard XMPP (XEP-0060): it works with the XMPP server built into SPADE and with servers such as Prosody, ejabberd or Openfire.

Installation

pip install spade_pubsub

or, with uv:

uv add spade_pubsub

SPADE PubSub requires Python 3.11 or later and SPADE 4.2 or later.

Example

Add PubSubMixin to the base classes of your agent (before Agent), and use self.pubsub:

import asyncio

import spade
from spade.agent import Agent

from spade_pubsub import PubSubMixin

PUBSUB = "pubsub.localhost"  # the PubSub service of the XMPP server


class PublisherAgent(PubSubMixin, Agent):
    async def setup(self):
        await self.pubsub.create(PUBSUB, "news")


class SubscriberAgent(PubSubMixin, Agent):
    def on_news(self, message):
        item = message["pubsub_event"]["items"]["item"]
        print(f"News: {item['payload'].text}")

    async def setup(self):
        self.pubsub.set_on_item_published(self.on_news)
        await self.pubsub.subscribe(PUBSUB, "news")


async def main():
    publisher = PublisherAgent("publisher@localhost", "secret")
    subscriber = SubscriberAgent("subscriber@localhost", "secret")
    await publisher.start()
    await subscriber.start()

    await publisher.pubsub.publish(PUBSUB, "news", "SPADE PubSub 0.4 released")
    await asyncio.sleep(1)  # the notification is on its way

    await publisher.pubsub.delete(PUBSUB, "news")
    await subscriber.stop()
    await publisher.stop()


if __name__ == "__main__":
    spade.run(main(), embedded_xmpp_server=True)  # with the XMPP server of SPADE

See the quick start and the guides.

Contributing

Contributions are welcome: see CONTRIBUTING.md and the history of changes.

License and credits

SPADE PubSub is free software under the MIT license, developed at the VRAIN institute of the Universitat Politècnica de València. See AUTHORS.md.

Metadata

Release files for spade_pubsub 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spade_pubsub 0.4.0
File Size Uploaded Provenance Actions
spade_pubsub-0.4.0.tar.gz 303.7 kB Without provenance Details for spade_pubsub-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spade_pubsub 0.4.0
File Interpreter ABI Platform Actions
spade_pubsub-0.4.0-py3-none-any.whl Python 3 none any Details for spade_pubsub-0.4.0-py3-none-any.whl

Total release size: 311.2 kB

Release files / spade_pubsub-0.4.0.tar.gz

Download URL spade_pubsub-0.4.0.tar.gz
Size 303.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b6f1bd4605221895394a07d308069c14a399ec76eeafe57eb48cacef7716d3a1
BLAKE2b-256 checksum
How to use checksums
60b1da3c8cf1b72abcdf48a863d21c6245b498cb3b7172024b309402bc143e66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.15

Release files / spade_pubsub-0.4.0-py3-none-any.whl

Download URL spade_pubsub-0.4.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9798ddda7bcc7b7af471dca20fc2df989d781a5c4dfc810eadc56f921517e04
BLAKE2b-256 checksum
How to use checksums
76830bb587571fbcb44f2c31bd35bc6e72a2e30489e7d39aa12faa1b0dde4f9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.15

Security for spade_pubsub 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page