Skip to main content

MicroAgent

https://img.shields.io/pypi/v/microagent.svg https://img.shields.io/pypi/pyversions/microagent.svg https://img.shields.io/pypi/l/microagent.svg https://img.shields.io/pypi/status/microagent.svg https://img.shields.io/pypi/dm/microagent.svg https://readthedocs.org/projects/microagent/badge/?version=latest&style=flat https://github.com/scailer/microagent/workflows/Tests/badge.svg

The goal of this project is to facilitate the creation of microservices interacting via a signal bus and/or queue broker.

The philosophy of this project is to present a microservice as a software agent that directly interacts only with queues and the event bus, and not with other microservices.

Tool is intended for developing:

  • distributed apps with event-driven architecture

  • distributed apps with data-driven architecture

  • multi-processors apps

Tool provide features:

  • running a periodical tasks (interval or as CRON)

  • specification of signals (events), their sending and receiving via the bus (redis)

  • description of queues, sending and receiving messages via the queue broker (aiormq, kafka, redis)

  • limited RPC via signal bus

  • launching sub-services (in the same process)

  • launching a group of microagents (each in a separate process)

  • mocks for bus and broker

See MicroAgent documentation.

from microagent import (MicroAgent, Queue, Signal, configure,
                        consumer, cron, on, periodic, receiver)
from microagent.tools.redis import RedisBroker, RedisSignalBus

configure('file://signals.json')

class Agent(MicroAgent):

    @on('pre_start')
    async def setup(self):
        pass  # init connections to DB, REDIS, SMTP and other services

    @periodic(period=5)
    async def refresh_cache(self):
        pass  # do something periodicly

    @cron('0 */4 * * *')
    async def send_report(self):
        pass  # do something by schedule

    # subscribe to signals (events)
    @receiver(Signal.user_updated, Signal.user_deleted)
    async def send_notification(self, **kwargs):
        # send signal (event) to bus
        await self.bus.check_something.send(sender='agent', **kwargs)

    # message consumer from queue
    @consumer(Queue.mailer)
    async def send_emails(self, **kwargs):
        # send message to queue
        await self.broker.statistic_collector.send(kwargs)


async def main():
    bus = RedisSignalBus('redis://localhost/7')
    broker = RedisBroker('redis://localhost/7')

    # usage bus and broker separate from agent
    await bus.started.send('user_agent')
    await broker.mailer.send(data)

    agent = Agent(bus=bus, broker=broker)
    await agent.start()

Installing

With redis backend provide signal bus and list-based queues:

pip install 'microagent[redis]'

With aiormq backend provide queues over AMQP (RabbitMQ):

pip install 'microagent[amqp]'

With kafka backend provide queues over Kafka (experemental):

pip install 'microagent[kafka]'

Metadata

Release files for microagent 1.9.1

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

Source distribution (sdist)

Source distribution for microagent 1.9.1
File Size Uploaded Provenance Actions
microagent-1.9.1.tar.gz 41.8 kB Without provenance Details for microagent-1.9.1.tar.gz

Built distribution (wheel)

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

Total release size: 77.8 kB

Release files / microagent-1.9.1.tar.gz

Download URL microagent-1.9.1.tar.gz
Size 41.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e40557616e0d52a9a60141505655d6127417c265930a68d2e81fa81ef2ade9bc
BLAKE2b-256 checksum
How to use checksums
616296433be7fcd628d161149143fad88e9b12c0dc3c713aed7b62209c96f6cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.10

Release files / microagent-1.9.1-py3-none-any.whl

Download URL microagent-1.9.1-py3-none-any.whl
Size 36.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
647fb8d3adeb117a0a9fe3cd78206afea09052eef9c669598c2ad06bd5b51733
BLAKE2b-256 checksum
How to use checksums
ead97142eca098a861d61f359f849e489b202cf61391744ed0d7c5a422012beb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.10

Security for microagent 1.9.1

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.

Release history Release notifications | RSS feed

This release

1.9.1 This release

2 release files No provenance

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