Skip to main content

Miniagent

Miniagent is a multi-adaptable and lightweight server framework based on Flask.

Installing

Install and update using pip:

$ pip install -U miniagent

Advised Virtual Environment Install

Virtual env is highly advisable because the more projects you have, the more likely it is that you will be working with different versions of Python itself, or at least different versions of Python libraries.

$ pip install virtualenv

Next create a virtualenv:

$ virtualenv venv
New python executable in venv/bin/python
Installing distribute............done.
$ . venv/bin/activate
(venv)$

Now install miniagent on the virtual env, it will install all the dependencies and these will be isolated from your system’s python packages

(venv)$ pip install miniagent

Configuration Variables

Configuration variables defined in the config.py file

Variable Type Description Default
DEBUG bool Debug mode y/n True
AGENT_NAME str It is used to identify a specific service. main .py file name
AGENT_ROLES list or str REST api, message receiver, and scheduler job resources defined in miniagent can grant authority only to specific roles. This variable is useful when implementing services of multiple roles with one application.

ex : AGENT_ROLES = "customer,tester"

COMMAND_RECEIVER_ENABLED bool It indicates whether to use Command Receiver or not. False
COMMANDER_SERVER_URL str URL to be polled by Command Receiver
COMMANDER_RESPONSE_CONVERTER str Path of function that processes the response received by Command Receiver so that Executor can process it. If it is not defined, the response is sent to Executor without being processed.

ex : COMMANDER_RESPONSE_CONVERTER = "example.etc.command_converter"

MESSAGE_RECEIVER_ENABLED bool It indicates whether to use Message Receiver(Kafka consumer) or not. False
KAFKA_BOOTSTRAP_SERVERS list(str) A list of kafka bootstrap servers to be called by Message Receiver
EXECUTERS_BY_TOPIC list(dir) Kafka topics to be polled by Message Receiver and Executors to handle processing for each topic.

ex : EXECUTERS_BY_TOPIC =[{"topic":"TEST_TOPIC", "executer":"example.executer.say_hello.PrintParam", "agent_roles":["tester","admin"]}]

SQLALCHEMY_DATABASE_URI str URI of dedicated database of the service "sqlite:///" + os.path.join(base_dir, "app.db")
CUSTOM_MODELS_PATH str Path of data models added by the application

ex : CUSTOM_MODELS_PATH = "example.model"

CUSTOM_APIS_PATH str Path of REST APIs added by the application

ex : CUSTOM_APIS_PATH = "example.api"

TIMEZONE str Timezone to be used in miniagent

ex : TIMEZONE = "Asia/Seoul"

SCHEDULER_API_ENABLED bool It indicates whether to open REST APIs of Job Scheduler or not. False
EXIT_AFTER_JOBS bool It indicates whether to terminate the service when all jobs scheduled in Job Scheduler are finished. False
SCHEDULED_JOBS list(dir) List of jobs to be scheduled in Job Scheduler
DEFAULT_ADAPTEES dir If the application uses a 3rd party solution, register the 3rd party solution library as an adaptee and develop an adapter so that the executor can use it. That variable defines the mapping of adapters and adaptees.
ZIPKIN_ADDRESS tuple(str,int) Zipkin server address.

ex : ZIPKIN_ADDRESS = ("localhost",9411)

Sample code download

Create an sample project after installing miniagent

$ mini-project tanminkwan/banking-poc /

Then the source files are downloaded from Github on the current directory. The following is the directory tree.

├── banking  
│   ├── __init__.py  
│   ├── api  
│   │   ├── __init__.py  
│   │   ├── bapis.py  
│   ├── dbquery  
│   │   └── queries.py  
│   ├── executer  
│   │   ├── __init__.py  
│   │   ├── deposit.py  
│   │   ├── event.py  
│   │   └── raffle.py  
│   └── model  
│       ├── __init__.py  
│       └── models.py  
├── app.py  
├── config.py  
├── bonnie.py  
├── clyde.py  
├── john_dillinger.py  
├── deposit.py  
├── event.py  
└── raffle.py

Run Kafka, Opensearch and Zipkin services

Run Kafka, Opensearch and Zipkin and register the endpoints of them in config.py.

ZIPKIN_DOMAIN_NAME = 'localhost'
ZIPKIN_PORT =  '9411'
KAFKA_BOOTSTRAP_SERVERS = 'localhost:9092'
ELASTIC_SEARCH_DOMAIN_NAME = 'localhost'
ELASTIC_SEARCH_PORT = '9200'

Run the six applications

Run the five applications as below.

$ nohup python raffle.py &
$ nohup python deposit.py &
$ nohup python event.py &
$ nohup python clyde.py &
$ nohup python bonnie.py &
$ nohup python john_dillinger.py &

Open Zipkin web site and check the transactions

  1. Clyde and Bonnie send requests to Deposit and Event every 30 seconds.
  2. Deposit produces messages and Raffle consumes the messages via Kafka.
  3. Event calls Raffle whenever it receive a request from Clyde and Bonnie.
  4. John Dillinger requests deposit amount by account from Event every 30 seconds.
  5. Event retrieves this information from Opensearch and provides it to John Dillinger.

You can see all of them on the Zipkin dashboard.(Maybe http://localhost:9411)

Metadata

Release files for miniagent 0.0.28

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

Built distribution (wheel)

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

Release files / miniagent-0.0.28-py3-none-any.whl

Download URL miniagent-0.0.28-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ef162edf835087a3bc97a9e71296383fc5f95d065d14d2abcc20b6ab7b459a8
BLAKE2b-256 checksum
How to use checksums
7c735981d9a48239cbfe328641a02fcf9fa685d90a6eb811a721f6ee6783f951
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.28 This release

1 release file

0.0.27

1 release file

0.0.26

1 release file

0.0.25

1 release file

0.0.24

1 release file

0.0.23

1 release file

0.0.22

1 release file

0.0.21

1 release file

0.0.20

1 release file

0.0.19

1 release file

0.0.18

1 release file

0.0.17

1 release file

0.0.16

1 release file

0.0.15

1 release file

0.0.14

1 release file

0.0.13

1 release file

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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