Chinese Documentation: https://www.cnblogs.com/mazhiyong/
Source Code: https://github.com/zhiyongma/fastproject
Python 3.6+
You should install the requirments below first.
$ pip install fastapi
$ pip install pymysql
$ pip install sqlalchemy
$ pip install pyjwt
$ pip install bcrypt
$ pip install passlib
$ pip install python-multipart
Then you should create your mysql database. Sample sql in the deploy directory.
You can configure the database connection in config.py.
You will also need an ASGI server, for production such as Uvicorn or Hypercorn.
$ pip install uvicorn
For production deployment, you should also install Gunicorn.
$ pip install gunicorn
$ uvicorn local:app --reload
Run the server with gunicorn.
$ gunicorn -c /data/fastest/gunicorn.py -e FASTAPI_ENV=production run:app
-c
: gunicorn config.-e
: environment parameter.
Run the server with service.
See the file gunicorn_fast.service in deploy directory. You should put it in /usr/lib/systemd/system for linux os.
$ systemctl start/stop/restart/enable gunicorn_fast.service
-e
:FASTAPI_ENV=production
.mysql
: configure fileconfig.py
.gunicorn
: configure filegunicorn.py
.service
: configure filegunicorn_fast.service
.
remarks: the pidfile
in gunicorn_fast.service
and gunicorn.py
should point to the same one file.
This project is licensed under the terms of the MIT license.