My template base to build Flask RESTful APIs using Flask RESTPlus, JWT Extended and PyMongo.
You can just clone this repo and start to create/customize your own RESTful API using this code as your template base :)
pip3 install -r requirements.txt
export MONGO_URI="mongodb://<your_mongo_host>:27017/<your_database>"
export JWT_SECRET_KEY="<randomic_key>"
python3 entrypoint.py
docker build -t flask-app --target develop .
docker run -d \
-p 5000:5000 \
-e MONGO_URI="mongodb://<your_mongo_host>:<your_mongo_port>/<your_mongo_database>" \
-e JWT_SECRET_KEY="<your_randomic_key>" \
flask-app
After the application goes up, open your browser on localhost:5000/api/v1/docs
to see the self-documented interactive API.
The project structure is based on the official Scaling your project doc with some adaptations (e.g v1
folder to agroup versioned resources).
.
├── app
│ ├── helpers
│ │ ├── __init__.py
│ │ ├── parsers.py
│ │ └── password.py
│ ├── __init__.py
│ └── v1
│ ├── __init__.py
│ └── blueprints
│ ├── auth
│ │ ├── __init__.py
│ │ ├── routes.py
│ │ └── serializers.py
│ ├── __init__.py
│ └── users
│ ├── __init__.py
│ ├── services.py
│ ├── serializers.py
│ └── routes.py
├── config.py
├── Dockerfile
├── LICENSE
├── README.md
├── requirements.txt
├── entrypoint.py
└── entrypoint.sh
app
- All the RESTful API implementation is here.app/helpers
- Useful function/class helpers for all modules.app/v1
- Resource agroupment for allv1
Namespaces.app/v1/blueprints
- Allv1
resources are implemented here.
app/__init__.py
- The Flask Application factory (create_app()
) and it's configuration are done here. Your Blueprints are registered here.app/v1/__init__.py
- The Flask RESTPlus API is created here with the versioned Blueprint (e.gv1
). Your Namespaces are registered here.config.py
- Config file for envs, global config vars and so on.Dockerfile
- Dockerfile used to build a Docker image (using Docker Multistage Build)LICENSE
- MIT License, i.e. you are free to do whatever is needed with the given code with no limits..dockerignore
- Lists files and directories which should be ignored while Docker build process..gitignore
- Lists files and directories which should not be added to git repository.requirements.txt
- All project dependencies.entrypoint.py
- The application entrypoint.entrypoint.sh
- Starting script before application
This project is licensed under the MIT License - see the LICENSE file for details.