Skip to main content

Tool for agent ecosystem

Project description

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.

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(signals.user_updated, signals.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(queues.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(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]'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

microagent-1.8.0.tar.gz (55.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

microagent-1.8.0-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file microagent-1.8.0.tar.gz.

File metadata

  • Download URL: microagent-1.8.0.tar.gz
  • Upload date:
  • Size: 55.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for microagent-1.8.0.tar.gz
Algorithm Hash digest
SHA256 e457220bb5f7f93b4077186d0c3984c4e66b8043f740d94b76017564c62fe535
MD5 67110ac021d9a68e8e40e5f7b35c67ca
BLAKE2b-256 e403d65c7faa0a25481a0d33e0c2d1ede12b84b030f715fe0a7b37daa1a851da

See more details on using hashes here.

File details

Details for the file microagent-1.8.0-py3-none-any.whl.

File metadata

  • Download URL: microagent-1.8.0-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for microagent-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee56c251096c74bf27eb7bf104d813a61355434573eedd6e19525406bc0ee4e6
MD5 dc068de08ba4408eb49ceb4aff7940de
BLAKE2b-256 d45504b40bd1ec4908f928639468004837794b4ebeb568911dcd422164b9ab49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page