Metadata-Version: 2.4
Name: microagent
Version: 1.9.1rc1
Summary: Tool for agent ecosystem
Author-email: Dmitriy Vlasov <scailer@yandex.ru>
License-Expression: MIT
Project-URL: Homepage, https://github.com/scailer/microagent
Project-URL: Documentation, https://microagent.readthedocs.io/en/stable/
Project-URL: Repository, https://github.com/scailer/microagent.git
Project-URL: Changelog, https://github.com/scailer/microagent/blob/master/CHANGELOG.rst
Keywords: async,pubsub,queue,agent,periodic,cron
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Plugins
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Framework :: AsyncIO
Requires-Python: >=3.10
Description-Content-Type: text/x-rst
License-File: LICENSE.md
Provides-Extra: redis
Requires-Dist: redis[hiredis]>5; extra == "redis"
Provides-Extra: amqp
Requires-Dist: aiormq==6.9.*; extra == "amqp"
Provides-Extra: kafka
Requires-Dist: aiokafka==0.13.*; extra == "kafka"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-runner; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: redis[hiredis]>5; extra == "dev"
Requires-Dist: aiormq==6.9.*; extra == "dev"
Requires-Dist: aiokafka==0.13.*; extra == "dev"
Dynamic: license-file

MicroAgent
==========

.. image:: https://img.shields.io/pypi/v/microagent.svg
   :target: https://pypi.python.org/pypi/microagent

.. image:: https://img.shields.io/pypi/pyversions/microagent.svg
  :target: https://pypi.python.org/pypi/microagent

.. image:: https://img.shields.io/pypi/l/microagent.svg
  :target: https://pypi.python.org/pypi/microagent

.. image:: https://img.shields.io/pypi/status/microagent.svg
  :target: https://pypi.python.org/pypi/microagent

.. image:: https://img.shields.io/pypi/dm/microagent.svg
  :target: https://pypi.python.org/pypi/microagent

.. image:: https://readthedocs.org/projects/microagent/badge/?version=latest&style=flat
  :target: https://microagent.readthedocs.io/

.. image:: https://github.com/scailer/microagent/workflows/Tests/badge.svg
   :target: https://github.com/scailer/microagent/actions


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_.


.. code-block:: python

    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]'


.. _redis: https://pypi.org/project/redis/
.. _aiormq: https://pypi.org/project/aiormq/
.. _kafka: https://pypi.org/project/aiokafka/
.. _documentation: https://microagent.readthedocs.io/
