ZAPI is Simple Fast Python MVC Framework, based on tornado, and peewee database orm.
- MVC framework, models, views, controllers
- Dynamic routing: routing reflects to controllers, with prefix methods
- Task Integration: tasks with models. See
Tasks
- Testing Framework: Unitesting framework.
.
└── ZAPI/
├── controllers/
│ ├── indexcontroller.py
│ └── democontroller.py
├── interceptors/
│ └── dbinterceptor.py
├── services/
│ ├── dbservice.py
│ ├── redisservice.py
│ └── mqservice.py
├── tasks/
│ ├── demotask.py
│ └── testtask.py
├── tests/
│ └── demotest.py
├── views/
│ ├── index.html
│ └── assets/
│ ├── js/
│ │ └── index.js
│ └── css/
│ └── index.css
├── logs/
│ └── ...
├── libs/
│ └── basecontroller.py
├── runtask.sh
├── runtest.sh
├── config.json
├── main.py
└── server.py
For Example,
usercontroller.py
under foldercontrollers
.
└── ZAPI/
└── controllers/
└── usercontroller.py
from libs.mybasecontroller import MyBaseController
class UserController(BaseController):
def get_list(self):
self.make_result({
'list': [1,2,3,4]
})
By default, browser: http://127.0.0.1:3001/api/v1/user/list
Note: the
api/v1
is apiprefix
. it can be configured inconfig.json
Note: the port3001
could be configured inconfig.json
Models are located in folder with suffix model
For example, for postgresql
models, the folder is pgmodel
, and MySQL
is mqmodel
.
from peewee import IntegerField, CharField
from system.libs.basemodel import BaseModel
class MqUser(BaseModel):
id = IntegerField(primary_key=True)
username = CharField(max_length=255)
password = CharField(max_length=255)
description = CharField(max_length=255)
class Meta:
db_table = 'user'
Views are mapped into folders /views
python3 server.py
ZApi enables user to run task integrated with framework features
Tasks are located in folder /tasks
For example:
Task file /tasks/demotask.py
File Content:
from system.libs.basetask import BaseTask
class DemoTask(BaseTask):
def run(self):
print('this is a demo task')
./runtask.sh demo
{
"prefix": "api/v1",
"server": {
"port": 3100
},
"env": "db_evn_name",
"dbsource": {
"db_evn_name": {
"type": "mysql",
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"db": "aibox"
}
}
}
MIT