Metadata-Version: 2.1
Name: miniagent
Version: 0.0.14
Summary: Multi-adaptable and lightweight server framework based on Flask
Home-page: https://github.com/tanminkwan/local-agent
Author: tanminkwan
Author-email: tanminkwan@gmail.com
License: MIT
Keywords: flask,sqlalchemy,scheduler,zipkin,kafka
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aniso8601 (>=9.0.1)
Requires-Dist: APScheduler (>=3.10.1)
Requires-Dist: blinker (>=1.6.2)
Requires-Dist: certifi (>=2022.12.7)
Requires-Dist: charset-normalizer (>=3.1.0)
Requires-Dist: click (>=8.1.3)
Requires-Dist: Flask (>=2.3.1)
Requires-Dist: Flask-API (>=3.0.post1)
Requires-Dist: Flask-APScheduler (>=1.12.4)
Requires-Dist: Flask-Cors (>=3.0.10)
Requires-Dist: Flask-RESTful (>=0.3.9)
Requires-Dist: Flask-SQLAlchemy (>=3.0.3)
Requires-Dist: greenlet (>=2.0.2)
Requires-Dist: idna (>=3.4)
Requires-Dist: itsdangerous (>=2.1.2)
Requires-Dist: Jinja2 (>=3.1.2)
Requires-Dist: kafka-python (>=2.0.2)
Requires-Dist: MarkupSafe (>=2.1.2)
Requires-Dist: polling2 (>=0.5.0)
Requires-Dist: python-dateutil (>=2.8.2)
Requires-Dist: pytz (>=2023.3)
Requires-Dist: pytz-deprecation-shim (>=0.1.0.post0)
Requires-Dist: requests (>=2.29.0)
Requires-Dist: six (>=1.16.0)
Requires-Dist: SQLAlchemy (>=2.0.11)
Requires-Dist: typing-extensions (>=4.5.0)
Requires-Dist: tzdata (>=2023.3)
Requires-Dist: tzlocal (>=4.3)
Requires-Dist: urllib3 (>=1.26.15)
Requires-Dist: Werkzeug (>=2.3.2)
Requires-Dist: PyGithub (>=1.58.1)
Requires-Dist: py-zipkin (>=1.2.8)
Requires-Dist: opensearch-py (>=2.2.0)

# 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
```

## 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 2 minites. 
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 4 minutes. 
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)
