Giter Site home page Giter Site logo

aleksanderbodurri / flask-api-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from choyiny/flask-api-starter

0.0 0.0 0.0 39 KB

Boilerplate for Flask Restful applications

License: MIT License

Dockerfile 1.19% Python 93.34% Mako 3.23% Shell 2.24%

flask-api-starter's Introduction

Boilerplate for Flask APIs

A skeleton Flask API only application to quickstart development.

Features

Deployment

Dockerfile is ready for deployment. It is recommended to reverse proxy through nginx.

Development

Setup

Note: This project requires Python 3.7+ installed. For Mac users, ensure you are using the correct version of Python because the OS preinstalls Python 2.7 and default pip and python commands execute in v2.7 rather than v3.x.

  1. Create a virtual environment for the project and activate it. Run pip3 install virtualenv if virtualenv is not installed on Python3.7+

    $ virtualenv flask-starter-venv --python=python
    $ source flask-starter-venv/bin/activate
    
  2. Clone the repository to your directory

    (flask-starter-venv) $ [email protected]:choyiny/flask-api-starter.git
    
  3. Install the required dependencies

    (flask-starter-venv) $ cd flask-api-starter
    (flask-starter-venv) $ pip install -r requirements.txt
    
  4. Edit config.py.bak with the proper credentials and move it to config.py.

  5. Run Migrations

    (flask-starter-venv) $ PYTHONPATH=. alembic upgrade head
    

Run Locally

Remember to fill any necessary fields in config.py.

  1. Make sure you are in your virtualenv that you setup
    $ source flask-starter-venv/bin/activate
    
  2. Start server
    (flask-starter-venv) $ flask run
    
  3. Start Celery worker
    (flask-starter-venv) $ celery worker -A worker.celery --loglevel=info
    

Database Setup

Alembic is used to manage database migrations. Existing migrations are version controlled so to generate migrations after making changes to any models,

  1. Ensure models are imported in flask-api-starter/extensions.py.
  2. Generate the migrations
    (flask-starter-venv) $ flask db migrate -m "migration message."
    
  3. Edit the migrations if necessary.
  4. Migrate the database.
    (flask-starter-venv) $ flask db upgrade
    

Setting up Blueprints

Flask blueprints are like modules. To create a new one, you can copy the example blueprint, and modify the __init__.py to change the prefix url. Ensure that it is also included in app.py.

Managing Utilities

Resetting database

(flask-starter-venv) $ python manage.py resetdb

Seeding the database

(flask-starter-venv) $ python manage.py seedfile seed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.