A skeleton Flask API only application to quickstart development.
- Uses Flask Blueprints for module separation
- Support for PostgreSQL connection
- Database migrations with Alembic
- Fully dockerized and deployment ready
- ORM-ready with SQLAlchemy
- Various (optional) helper classes with common useful functionality
- CORS protected
- Integrates with Flask-RESTful and Marshmallow
- Sentry Integration
- Documentation generated with Flask-APISpec
- Celery worker queue support.
Dockerfile
is ready for deployment.
It is recommended to reverse proxy through nginx.
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.
-
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
-
Clone the repository to your directory
(flask-starter-venv) $ [email protected]:choyiny/flask-api-starter.git
-
Install the required dependencies
(flask-starter-venv) $ cd flask-api-starter (flask-starter-venv) $ pip install -r requirements.txt
-
Edit
config.py.bak
with the proper credentials and move it toconfig.py
. -
Run Migrations
(flask-starter-venv) $ PYTHONPATH=. alembic upgrade head
Remember to fill any necessary fields in config.py
.
- Make sure you are in your virtualenv that you setup
$ source flask-starter-venv/bin/activate
- Start server
(flask-starter-venv) $ flask run
- Start Celery worker
(flask-starter-venv) $ celery worker -A worker.celery --loglevel=info
Alembic is used to manage database migrations. Existing migrations are version controlled so to generate migrations after making changes to any models,
- Ensure models are imported in
flask-api-starter/extensions.py
. - Generate the migrations
(flask-starter-venv) $ flask db migrate -m "migration message."
- Edit the migrations if necessary.
- Migrate the database.
(flask-starter-venv) $ flask db upgrade
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
.
Resetting database
(flask-starter-venv) $ python manage.py resetdb
Seeding the database
(flask-starter-venv) $ python manage.py seedfile seed