miniagent


Nameminiagent JSON
Version 0.0.28 PyPI version JSON
download
home_pagehttps://github.com/tanminkwan/local-agent
SummaryMulti-adaptable and lightweight server framework based on Flask
upload_time2023-09-14 02:32:33
maintainer
docs_urlNone
authortanminkwan
requires_python>=3.9
licenseMIT
keywords flask sqlalchemy scheduler zipkin kafka
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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. <p> **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. <p> **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. <p> **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 <p> **ex** : `CUSTOM_MODELS_PATH = "example.model"`
|CUSTOM_APIS_PATH|_str_|Path of REST APIs added by the application <p> **ex** : `CUSTOM_APIS_PATH = "example.api"`
|TIMEZONE|_str_|Timezone to be used in miniagent <p> **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. <p> **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)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tanminkwan/local-agent",
    "name": "miniagent",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "flask,sqlalchemy,scheduler,zipkin,kafka",
    "author": "tanminkwan",
    "author_email": "tanminkwan@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "# Miniagent\n\nMiniagent is a multi-adaptable and lightweight server framework based on **Flask**.\n\n## Installing\n\nInstall and update using **pip**:\n```\n$ pip install -U miniagent\n```\n\n## Advised Virtual Environment Install\n\nVirtual 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.\n\n```\n$ pip install virtualenv\n```\nNext create a virtualenv:\n```\n$ virtualenv venv\nNew python executable in venv/bin/python\nInstalling distribute............done.\n$ . venv/bin/activate\n(venv)$\n```\nNow install miniagent on the virtual env, it will install all the dependencies and these will be isolated from your system\u2019s python packages\n\n```\n(venv)$ pip install miniagent\n```\n## Configuration Variables\n\nConfiguration variables defined in the config.py file\n\n|Variable|Type|Description|Default|\n|--|--|--|--|\n|DEBUG|_bool_|Debug mode y/n|True\n|AGENT_NAME|_str_|It is used to identify a specific service.|main .py file name|\n|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. <p> **ex** : `AGENT_ROLES = \"customer,tester\"`|\n|COMMAND_RECEIVER_ENABLED|_bool_|It indicates whether to use Command Receiver or not.|False|\n|COMMANDER_SERVER_URL|_str_|URL to be polled by Command Receiver|\n|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. <p> **ex** : `COMMANDER_RESPONSE_CONVERTER = \"example.etc.command_converter\"`|\n|MESSAGE_RECEIVER_ENABLED|_bool_|It indicates whether to use Message Receiver(Kafka consumer) or not.|False|\n|KAFKA_BOOTSTRAP_SERVERS|_list(str)_|A list of kafka bootstrap servers to be called by Message Receiver|\n|EXECUTERS_BY_TOPIC|_list(dir)_|Kafka topics to be polled by Message Receiver and Executors to handle processing for each topic. <p> **ex** : `EXECUTERS_BY_TOPIC =[{\"topic\":\"TEST_TOPIC\",    \"executer\":\"example.executer.say_hello.PrintParam\", \"agent_roles\":[\"tester\",\"admin\"]}]`|\n|SQLALCHEMY_DATABASE_URI|_str_|URI of dedicated database of the service|`\"sqlite:///\" + os.path.join(base_dir, \"app.db\")`|\n|CUSTOM_MODELS_PATH|_str_|Path of data models added by the application <p> **ex** : `CUSTOM_MODELS_PATH = \"example.model\"`\n|CUSTOM_APIS_PATH|_str_|Path of REST APIs added by the application <p> **ex** : `CUSTOM_APIS_PATH = \"example.api\"`\n|TIMEZONE|_str_|Timezone to be used in miniagent <p> **ex** : `TIMEZONE = \"Asia/Seoul\"`|\n|SCHEDULER_API_ENABLED|_bool_|It indicates whether to open REST APIs of Job Scheduler or not.|False|\n|EXIT_AFTER_JOBS|_bool_|It indicates whether to terminate the service when all jobs scheduled in Job Scheduler are finished.|False|\n|SCHEDULED_JOBS|_list(dir)_|List of jobs to be scheduled in Job Scheduler|\n|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.|\n|ZIPKIN_ADDRESS|_tuple(str,int)_|Zipkin server address. <p> **ex** : `ZIPKIN_ADDRESS = (\"localhost\",9411)`|\n\n## Sample code download\n\nCreate an sample project after installing miniagent\n\n`$ mini-project tanminkwan/banking-poc /`\n\nThen the source files are downloaded from Github on the current directory. The following is the directory tree.\n```\n\u251c\u2500\u2500 banking  \n\u2502   \u251c\u2500\u2500 __init__.py  \n\u2502   \u251c\u2500\u2500 api  \n\u2502   \u2502   \u251c\u2500\u2500 __init__.py  \n\u2502   \u2502   \u251c\u2500\u2500 bapis.py  \n\u2502   \u251c\u2500\u2500 dbquery  \n\u2502   \u2502   \u2514\u2500\u2500 queries.py  \n\u2502   \u251c\u2500\u2500 executer  \n\u2502   \u2502   \u251c\u2500\u2500 __init__.py  \n\u2502   \u2502   \u251c\u2500\u2500 deposit.py  \n\u2502   \u2502   \u251c\u2500\u2500 event.py  \n\u2502   \u2502   \u2514\u2500\u2500 raffle.py  \n\u2502   \u2514\u2500\u2500 model  \n\u2502       \u251c\u2500\u2500 __init__.py  \n\u2502       \u2514\u2500\u2500 models.py  \n\u251c\u2500\u2500 app.py  \n\u251c\u2500\u2500 config.py  \n\u251c\u2500\u2500 bonnie.py  \n\u251c\u2500\u2500 clyde.py  \n\u251c\u2500\u2500 john_dillinger.py  \n\u251c\u2500\u2500 deposit.py  \n\u251c\u2500\u2500 event.py  \n\u2514\u2500\u2500 raffle.py\n```\n## Run Kafka, Opensearch and Zipkin services\n\nRun Kafka, Opensearch and Zipkin and register the endpoints of them in config.py.\n```\nZIPKIN_DOMAIN_NAME = 'localhost'\nZIPKIN_PORT =  '9411'\nKAFKA_BOOTSTRAP_SERVERS = 'localhost:9092'\nELASTIC_SEARCH_DOMAIN_NAME = 'localhost'\nELASTIC_SEARCH_PORT = '9200'\n```\n## Run the six applications\n\nRun the five applications as below.\n```\n$ nohup python raffle.py &\n$ nohup python deposit.py &\n$ nohup python event.py &\n$ nohup python clyde.py &\n$ nohup python bonnie.py &\n$ nohup python john_dillinger.py &\n```\n## Open Zipkin web site and check the transactions\n\n1. Clyde and Bonnie send requests to Deposit and Event every 30 seconds. \n2. Deposit produces messages and Raffle consumes the messages via Kafka. \n3. Event calls Raffle whenever it receive a request from Clyde and Bonnie. \n4. John Dillinger requests deposit amount by account from Event every 30 seconds. \n5. Event retrieves this information from Opensearch and provides it to John Dillinger. \n\nYou can see all of them on the Zipkin dashboard.(Maybe http://localhost:9411)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Multi-adaptable and lightweight server framework based on Flask",
    "version": "0.0.28",
    "project_urls": {
        "Homepage": "https://github.com/tanminkwan/local-agent"
    },
    "split_keywords": [
        "flask",
        "sqlalchemy",
        "scheduler",
        "zipkin",
        "kafka"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c735981d9a48239cbfe328641a02fcf9fa685d90a6eb811a721f6ee6783f951",
                "md5": "d01acee44852a425ac88c7b4d5779dd9",
                "sha256": "9ef162edf835087a3bc97a9e71296383fc5f95d065d14d2abcc20b6ab7b459a8"
            },
            "downloads": -1,
            "filename": "miniagent-0.0.28-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d01acee44852a425ac88c7b4d5779dd9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 24358,
            "upload_time": "2023-09-14T02:32:33",
            "upload_time_iso_8601": "2023-09-14T02:32:33.091268Z",
            "url": "https://files.pythonhosted.org/packages/7c/73/5981d9a48239cbfe328641a02fcf9fa685d90a6eb811a721f6ee6783f951/miniagent-0.0.28-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 02:32:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tanminkwan",
    "github_project": "local-agent",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "miniagent"
}
        
Elapsed time: 0.12951s