Skip to content

markdouthwaite/minimal-flask-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minimal-flask-api

This template repository provides a minimal configuration for a 'production-ready' Flask API project. It includes a basic project structure and 'seed' files for functional and non-function testing, a basic application structure (including error-handling blueprint), and a few assorted 'getting started' files too.

The template has been set up for use with Python >= 3.7 and Docker.

Running locally

To run the basic server, you'll need to install a few requirements. To do this, run:

pip install -r requirements/common.txt

This will install only the dependencies required to run the server. To boot up the default server, you can run:

bash bin/run.sh

This will start a Gunicorn server that wraps the Flask app defined in src/app.py. Note that this is one of the recommended ways of deploying a Flask app 'in production'. The server shipped with Flask is intended for development purposes only.

You should now be able to send:

curl localhost:5000/health

And receive the response OK and status code 200.

Running with docker

Unsurprisingly, you'll need Docker installed to run this project with Docker. To build a containerised version of the API, run:

docker build . -t flask-app

To launch the containerised app, run:

docker run -p 5000:5000 flask-app

You should see your server boot up, and should be accessible as before.

Developing with the template

To develop the template for your own project, you'll need to make sure to create your own repository from this template and then install the project's development dependencies. You can do this with:

pip install -r requirements/develop.txt

This'll install some style formatting and testing tools (including pytest and locust).

About

A template for 'production ready' Flask APIs with Flask & Gunicorn. Includes template test and error-handling files.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published