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/dd/microagent.svg https://codecov.io/gh/scailer/microagent/branch/master/graph/badge.svg https://travis-ci.com/scailer/microagent.svg?branch=master https://readthedocs.org/projects/microagent/badge/?version=latest&style=flat

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 (aioamqp, 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 aioamqp 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.7.3.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

microagent-1.7.3-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: microagent-1.7.3.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for microagent-1.7.3.tar.gz
Algorithm Hash digest
SHA256 deee0c979478c5abeefea9f514bc6f14ca51f89a725b8f31233fcb31ef37e298
MD5 6fcee548c4799adca3db11db96c0f5c6
BLAKE2b-256 ad08207c154d0ea77a0204803af9102b2c51158ff6694b14630702066a4b43ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: microagent-1.7.3-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for microagent-1.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 42c73823ae2e6be0b9c2ae71fc764acc78fcb6b2ce0ef0eb03d7affc57ec4678
MD5 8283541119c1bb30fc5c055a4e896db8
BLAKE2b-256 31a6cafe2a93f52549ed262a01ddd2396e5d211e90220e2ee8147620114129a3

See more details on using hashes here.

Supported by

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