Skip to content

Flask Restful API template - development environment for Flask Restful API development based on docker

Notifications You must be signed in to change notification settings

trydirect/flask-formula

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

108 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build Status Docker Stars Docker Pulls Docker Automated Docker Build Gitter chat

Flask Restful API template

Flask Restful API backend template - project generator/development environment. Can be used by Python developers for quick start on building Restful API on Flask.

Stack includes

  • rabbitmq
  • redis
  • elasticsearch
  • logstash
  • postgresql
  • nginx
  • supervisord
  • kibana
  • apidoc

Extra python libs and validator classes included.

Note

Before installing this project, please, make sure you have installed docker and docker-compose

To install docker execute:

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sh get-docker.sh
$ pip install docker-compose

Installation

Clone this project into your work directory:

$ git clone "https://github.com/trydirect/flask-formula.git"

Then build it with the following command:

$ cd flask-formula
$ ./setup.sh

Add localdomain to your hosts file Linux, OSX:

echo  "127.0.0.1 localdomain kibana.localdomain" | sudo tee -a /etc/hosts

Now, let's check it out

$ curl -i localhost/api/v1/hello
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Fri, 24 May 2019 15:33:02 GMT
Content-Type: application/json
Content-Length: 14
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With, Content-Type, X-Custom-Header
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE

"Hello World"

Default kibana creds:

  • login: admin
  • password: admin
URL App
http://localhost Api doc
http://localhost/api/v1/hello Api hello endpoint
http://kibana.localdomain Kibana dashboard

Features

  • Full Docker integration
  • Docker Compose integration and optimization for local development
  • Production ready Python web server using Nginx and uWSGI
  • Python Flask backend:
  • Nginx plus HTTPS certificate generation with Let's Encrypt

The final project structure will look like this:

~/flask_formula$ tree
.
β”œβ”€β”€ backend
β”‚Β Β  β”œβ”€β”€ app
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ apidoc.json
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ apps
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ hello
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ resource_schemas.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── views.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ rabbitmq
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ resource_schemas.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── views.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── user
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ forms.py
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ models.py
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ resource_schemas.py
β”‚Β Β  β”‚Β Β  β”‚Β Β      └── views.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ acl.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config.py.dist
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ dev.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ nginx.conf
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ docs
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ libs
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ app.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ auth.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ controllers.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ forms.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ models.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ rabbitmq.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ redis_session.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ resource_schemas.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── validators.py
β”‚Β Β  β”œβ”€β”€ manage.py
β”‚Β Β  β”œβ”€β”€ migrations
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ alembic.ini
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ env.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ README
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ script.py.mako
β”‚Β Β  β”‚Β Β  └── versions
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ 9d5e165bc45e_.py
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ ce716beab747_.py
β”‚Β Β  β”œβ”€β”€ README.md
β”‚Β Β  β”œβ”€β”€ run.py
β”‚Β Β  β”œβ”€β”€ wsgi.ini
β”‚Β Β  └── wsgi.py
β”œβ”€β”€ certs
β”‚Β Β  β”œβ”€β”€ letsencrypt
β”‚Β Β  └── ssl
β”‚Β Β      β”œβ”€β”€ cert.pem
β”‚Β Β      └── key.pem
β”œβ”€β”€ config.json
β”œβ”€β”€ configs
β”‚Β Β  β”œβ”€β”€ elasticsearch
β”‚Β Β  β”‚Β Β  └── elasticsearch.yml
β”‚Β Β  β”œβ”€β”€ logstash
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Dockerfile
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ logstash.conf
β”‚Β Β  β”‚Β Β  └── templates
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ filebeat.template.json
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ packetbeat.template.json
β”‚Β Β  β”‚Β Β      └── topbeat.template.json
β”‚Β Β  β”œβ”€β”€ nginx
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ conf.d
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ flask_formula.conf
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ letsencrypt-conf.d
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── flask_formula.conf
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ nginx.conf
β”‚Β Β  β”‚Β Β  └── ssl-conf.d
β”‚Β Β  β”‚Β Β      └── flask_formula.conf
β”‚Β Β  β”œβ”€β”€ postgresql
β”‚Β Β  β”‚Β Β  └── pg_hba.conf
β”‚Β Β  β”œβ”€β”€ supervisord
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ flask_formula.conf
β”‚Β Β  β”‚Β Β  └── nginx.conf
β”‚Β Β  β”œβ”€β”€ systemd
β”‚Β Β  β”‚Β Β  └── flask_formula.service
β”‚Β Β  └── upstart
β”‚Β Β      └── flask_formula.sh
β”œβ”€β”€ cron
β”‚Β Β  └── root
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ docker-firewall.sh
β”œβ”€β”€ elasticsearch
β”‚Β Β  └── data
β”‚Β Β      └── nodes
β”‚Β Β          └── 0
β”‚Β Β              β”œβ”€β”€ node.lock
β”‚Β Β              └── _state
β”‚Β Β                  └── node-157.st
β”œβ”€β”€ flask_app.tar.gz
β”œβ”€β”€ init-user-db.sh
β”œβ”€β”€ nginx
β”‚Β Β  β”œβ”€β”€ conf.d
β”‚Β Β  β”‚Β Β  └── flask_formula.conf
β”‚Β Β  β”œβ”€β”€ letsencrypt-conf-d
β”‚Β Β  β”œβ”€β”€ nginx.conf
β”‚Β Β  └── ssl-conf.d
β”œβ”€β”€ nginx_original
β”‚Β Β  β”œβ”€β”€ conf.d
β”‚Β Β  β”‚Β Β  └── flask_formula.conf
β”‚Β Β  β”œβ”€β”€ letsencrypt-conf.d
β”‚Β Β  β”‚Β Β  └── flask_formula.conf
β”‚Β Β  └── ssl-conf.d
β”‚Β Β      └── flask_formula.conf
β”œβ”€β”€ scripts
└── supervisord
    β”œβ”€β”€ flask_formula.conf
    └── nginx.conf
$ docker-compose ps

Name                  Command                          State          Ports
------------------------------------------------------------------------------------------------------------------------------
db                    docker-entrypoint.sh postgres    Up (healthy)   5432/tcp
elasticsearch         /docker-entrypoint.sh elas ...   Up             9200/tcp, 9300/tcp
flask_formula_pmm_1   docker-entrypoint.sh postgres    Up             5432/tcp
kibana                /docker-entrypoint.sh kibana     Up             0.0.0.0:5601->5601/tcp
logstash              /docker-entrypoint.sh -e         Up             0.0.0.0:5044->5044/tcp
mq                    docker-entrypoint.sh rabbi ...   Up (healthy)   15671/tcp, 0.0.0.0:21072->15672/tcp, 25672/tcp, 4369/tcp, 5671/tcp, 0.0.0.0:2172->5672/tcp,0.0.0.0:32770->5672/tcp
nginx                 /usr/bin/supervisord -c /e ...   Up             0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
redis                 docker-entrypoint.sh redis ...   Up (healthy)   6379/tcp
web                   /usr/bin/supervisord -c /e ...   Up             0.0.0.0:8000->8000/tcp   

Generate Api Doc

$ ./scripts/apidoc.sh

Quick deployment to cloud

Amazon AWS, Digital Ocean, Hetzner and others

Contributing

  1. Fork it (https://github.com/trydirect/flask-formula/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Support Development

Donate

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •