zhiyongma / fastproject

project template for FastAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Chinese Documentation: https://www.cnblogs.com/mazhiyong/

Source Code: https://github.com/zhiyongma/fastproject


Requirements

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

Example

Local Run

$ uvicorn local:app --reload

Server Run

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

Production config

  • -e: FASTAPI_ENV=production.
  • mysql: configure file config.py .
  • gunicorn: configure file gunicorn.py .
  • service: configure file gunicorn_fast.service .

remarks: the pidfile in gunicorn_fast.service and gunicorn.py should point to the same one file.

API test

1、user register

FastAPI

2、user login

FastAPI

3、user info

FastAPI

License

This project is licensed under the terms of the MIT license.

About

project template for FastAPI

License:MIT License


Languages

Language:Python 94.8%Language:TSQL 5.2%