easy-flask
Automatic generate a flask server project by command
Start
Install
pip3 install easy-flask-restful
Make a flask server project at current dir:
easy-flask -n demo_server
# or
easy-flask --new=demo_server
# start server in debug mode
cd demo_server
python3 app.py
# or
sh control.sh start|restart|stop
Introduce
By this tool you don`t need care how to make a flask server project.
What you need to do is write api-file in easy format inside dir api.
This project will automatically load uri by api-file, and pack json response with same format.
Project structure
.
├── api
│ ├── __init__.py
│ └── demo
│ ├── __init__.py
│ └── demo_api.py
├── conf
│ ├── __init__.py
│ ├── config.ini
├── internal
│ ├── __init__.py
│ ├── error.py
│ └── utils.py
├── app.py
├── start.py
├── control.sh
└── logs
└── app.log
api - write api files here.
internal.error - define error info here.
app.py - start app by this file, you can rename it.
conf - config for application
control.sh - run app with command by gunicorn
Write Api File
For example:
from flask import g
from internal import Resource
from utils.parser import Type, Required, Default, Min, Max
class DemoApi(Resource):
uri = ['/api/demo']
def get(self):
pattern = {
'num': {Type: int, Min: 10, Max: 100},
'print': {Type: str, Required: True},
'default': {Type: str, Default: 'demo'}
}
data, err = self.parse_request_data(pattern=pattern)
if err:
g.logger.warning(err)
return err
g.logger.info('success')
return {'result': data}
uri - required by all api file
g.logger is loaded before each request for making different log_id.
self.parse_request_data can help you to parse params, it will return ParamsError when param invalid.
Normal response:
{
"errno": 0,
"data": {
"result": {
"num": 100,
"print": "aaaa",
"default": "demo"
}
},
"msg": "success",
"log_id": "f40c889d1b5744c7a87a9045aea8595c"
}
Error response:
return errno and msg according to error.py.
{
"errno": 2,
"msg": "params error:num check max invalid",
"log_id": "7c53531b93a4406e9d3050bae5b99968"
}
Suggest
A real project must have complex logic and interactions with DB or other service. By this tool, you just can get a simple framework. So I give some suggestions here for writing better code.
logicdir (or other name) for writing complex logic, keep simple in api file.- if you need db operation, use
flask-sqlalchemy, and mkdirdto. clientdir for interact with other service, and makeBaseClientclass(inherited by other client), because you never want to write same code for many times.
Metadata
Release files for easy-flask-restful 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easy-flask-restful-1.1.5.tar.gz | 11.4 kB | Without provenance | Details for easy-flask-restful-1.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easy_flask_restful-1.1.5-py3-none-any.whl | Python 3 | none | any | Details for easy_flask_restful-1.1.5-py3-none-any.whl |
Total release size: 26.4 kB
Release files / easy-flask-restful-1.1.5.tar.gz
| Download URL | easy-flask-restful-1.1.5.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
221e79110dead09accc8cc5a16a40999a68a6c649ce4f883f16bd7d0bdae9162
|
|
BLAKE2b-256 checksum How to use checksums |
b81c8dab2eb2bdf28d295ee231253823c278dda4e9eab080778a488fa2a50d74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / easy_flask_restful-1.1.5-py3-none-any.whl
| Download URL | easy_flask_restful-1.1.5-py3-none-any.whl |
|---|---|
| Size | 15.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
978562fe83b2ef1fc8bb3981442f8ed017afc1576faa8af5f9b71aa6dc01f8bf
|
|
BLAKE2b-256 checksum How to use checksums |
19cee87cd01c6308e51e74e79c24c2a475bb76843e7916843322cd4ddc35cd71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for easy-flask-restful 1.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.