# FlaskApi-Template **Repository Path**: vencen/FlaskApi-Template ## Basic Information - **Project Name**: FlaskApi-Template - **Description**: 使用Flask RESTX框架开发的API模板,带Swagger界面、鉴权模块。 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 3 - **Created**: 2021-07-13 - **Last Updated**: 2022-08-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## FlaskAPI ### 介绍 Flask-Restx-API开发模板 ### 软件架构 - 使用Flask RESTX(以前叫Flask RESTPlus)框架开发的API模板 - 模型算法模块-API快速集成 - 基于[flask-restx-boilerplate](https://github.com/X1Zeth2X/flask-restx-boilerplate )项目做的优化 * Full featured framework for fast, easy, and Swagger Documentation API with [Flask-RESTX](https://flask-restx.readthedocs.io/en/latest/) * JSON Web Token Authentication with [Flask-JWT-Extended](https://flask-jwt-extended.readthedocs.io/en/stable/) * Database ORM with [Flask-SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/2.x/) * Database Migrations using [Flask-Migrate](https://github.com/miguelgrinberg/flask-migrate) * Object serialization/deserialization with [Flask-Marshmallow](https://flask-marshmallow.readthedocs.io/en/latest/) * Data validations with Marshmallow [Marshmallow](https://marshmallow.readthedocs.io/en/stable/quickstart.html#validation) * Unit Testing. ### 模板目录 > app目录 ``` ├─app │ ├─api │ │ ├─model │ │ │ └─模型算法文件 │ │ ├─user │ │ │ └─用户模块 │ │ └─__init__.py路由蓝图设计 │ ├─auth │ │ └─鉴权模块 │ ├─models │ │ └─数据库模块 └─tests └─测试模块 ``` ### 安装教程 ```sh # Clone the repo $ git clone https://gitee.com/vencen/FlaskApi-Template.git # 创建虚拟环境,安装依赖包 $ conda create -n venv python=3.8 #on windows $ activate venv #on linux $ source activate venv $ pip install -r requirements.txt ``` ### 使用说明 1. 创建`.env`文件 ``` # .env file example FLASK_APP=api FLASK_CONFIG=development # Read more at https://github.com/theskumar/python-dotenv ``` 2. 启动虚拟环境 ```sh # 启动虚拟环境 #on windows $ activate venv #on linux $ source activate venv ``` 3. 建立数据库、启动api ```sh $ flask db init $ flask db migrate $ flask db upgrade # 启动api $ flask run ``` 4. API模板测试 > By default the `/` route is used by the `auth` blueprint. > The rest of the resources are found in `/api` (This is the docs route by default, this can be changed easily). 5. Swagger界面 - http://127.0.0.1:5000/ ![avatar](/resources/swagger0.png) - http://127.0.0.1:5000/api/ ![avatar](/resources/swagger.png) 6. [模型算法模块-API快速集成-事件分类Demo](https://gitee.com/vencen/FlaskApi-Template/tree/FlaskApi-NLP/app/api/nlp) - dict 字典管理 api任务 - GET ​/dict 查看自定义词典 - POST /dict 增加新词,包含词性 - DELETE /dict 删除新词 - event 事件分类 api任务 - GET ​/event 查看事件分词 - POST ​/event 进行事件分词、关键词提取、事件类别识别 6. [模型算法模块-API快速集成-人脸识别Demo](https://gitee.com/vencen/FlaskApi-Template/tree/FlaskApi-CV/app/api/cv) - face 人脸识别 api任务 - GET ​/face 查看任务 - POST ​/face 进行人脸检测、识别 ### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request