This repository aims to be an easy to extend template for building a Python API using Flask and running it with only Python or using Docker.
Before you begin, ensure you have met the following requirements:
- You have a Windows/Linux/Mac machine with the latest version of Docker installed.
- You have a Windows/Linux/Mac machine running Python 3.6+.
- You have installed the latest versions of
pip
andvirtualenv
orconda
(Anaconda).
For general purposes, why not installing prerequisites for both cases?
If you want to install the dependencies and work locally using only Python, you can simply follow this steps. If you want to directly work using Docker, jump to the "Install/Run with Docker" section.
Clone the project repository:
git clone https://github.com/RodolfoFerro/docker-flask-api.git
cd docker-flask-api
To create and activate the virtual environment, follow these steps:
Using conda
:
$ conda create -n docker-flask python=3.7
# Activate the virtual environment:
$ conda activate docker-flask
# To deactivate:
(docker-flask)$ conda deactivate
Using virtualenv
:
# In this case I'm supposing that your latest python3 version is +3.6
$ virtualenv docker-flask --python=python3
# Activate the virtual environment:
$ source docker-flask/bin/activate
# To deactivate:
(docker-flask)$ deactivate
To install the requirements using pip
, once the virtual environment is active:
(docker-flask)$ pip install -r requirements.txt
Finally, if you want to run the app locally, simply run:
$ python app.py
Now you should be able to test the API at http://0.0.0.0:5000/.
If you want to install the dependencies and work using Docker, you can simply follow this steps. If you want to simply work locally using only Python, jump back to the "Install/Run with only Python" section.
Clone the project repository:
git clone https://github.com/RodolfoFerro/docker-flask-api.git
cd docker-flask-api
To build the Docker image, simply run:
$ docker build -t docker-flask-api .
To run the Docker image, run the following:
$ docker run -it -p 5000:5000 -v $(pwd):/app docker-flask-api
Now you should be able to test the API at http://localhost:5000/.
To stop the Docker container:
$ docker ps
$ docker stop <container-id>
To contribute to <project_name>, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <feature_branch_name>
. - Make your changes and commit them:
git commit -m '<commit_message>'
- Push to the original branch:
git push origin <project_name>/<location>
- Create a Pull Request.
Additionally you can see the GitHub documentation on creating a Pull Request.
If you want to contact me you can reach me at [email protected]. There, or through any other of my social profiles your can find at: https://rodolfoferro.glitch.me/
This project uses an MIT License.