GithubHelp home page GithubHelp logo

rgant / saas-api-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 232 KB

Boilerplate setup for SaaS JSONAPI in Python using Flask & SQLAlchemy

License: GNU General Public License v3.0

Python 100.00%

saas-api-boilerplate's Introduction

saas-api-boilerplate

Boilerplate setup for SaaS JSONAPI in Python using Flask & SQLAlchemy

Development Setup

Document how I like to setup a Python API Project.

Sublime Text Project

The .sublime-project file should be checked into version control. Add *.sublime-workspace to .gitignore.

Exclude some cache files from the project by excluding some folder from the sublime-project settings: "folder_exclude_patterns": [".cache", ".mypy_cache", ".pytest_cache", "__pycache__"]

Create a Virtual Environment

SublimeLinter has integrated support for pipenv now so we can fully use pipenv's virtualenv creation.

brew install pyenv pipenv
cd "${PROJECT_DIR}"
pipenv --three

Errors like zipimport.ZipImportError: can't decompress data; zlib not available can be resolved by installing xcode tools: xcode-select --install

Dependencies

Using pipenv the project and development dependencies are tracked in Pipfile and Pipfile.lock. The requirements files for pip have been migrated and moved.

Since the Pipfile loses comments on each pipenv install this list documents the reason for certain dependencies:

  1. bcrypt # Password Hashing for Login
  2. # Flask-REST-JSONAPI # JSONAPI in Flask (seems abandoned or just slow to develop, we can do better.)
  3. Flask # Flask web server
  4. future # Python3 Compatibility (import builtins)
  5. gunicorn # Server for deployed app
  6. marshmallow-jsonapi # Handle the JSONAPI Envelope for API Schemas
  7. marshmallow-sqlalchemy # Map DB Models to API Schemas
  8. mypy # Not a development requirement because we may need to import from mypy
  9. psycopg2 # PostgreSQL library
  10. PyMySQL # PDO for MySQL appropriate for Google Cloud SQL DB
  11. SQLAlchemy # ORM
  12. SQLAlchemy-Continuum # Audit log/versioning

Install Requirements

Install the same requirements as locked by pipenv: pipenv sync --dev

For PostgreSQL:

brew install postgresql
sed -i '' -e "s/timezone = 'US\\/Eastern'/timezone = 'UTC'/" /usr/local//var/postgres/postgresql.conf
pg_ctl --pgdata=/usr/local/var/postgres --log=/dev/null start # start postgresql
createuser api --createdb
createdb "${PROJECT_NAME}_dev" -U api

For MySQL:

brew install mariadb
echo -e "[mysqld]\\ndefault-time-zone='+00:00'" > /usr/local/etc/my.cnf.d/default-time-zone.cnf
mysql.server start
mysql -u root -e 'CREATE DATABASE `'"${PROJECT_NAME}_dev"'` /*!40100 DEFAULT CHARACTER SET utf8 */'
Update Requirements
pipenv update --outdated --dev # Look for updates allowed by Pipfile
pipenv update --dev # Actually install updates to dependencies

Code Checks

Because we are using pipenv all the python commands need to be run using pipenv run. The three commands below are configured in the Pipfile scripts.

Linting the code: pipenv run lint

Type checking: pipenv run mypy

Run tests: pipenv run test

I don't like pipenv shell and I haven't setup an automatic activation of the virtualenv so for now we need to remember to use pipenv run.

Directory Structure

  • common
    • Module catchall for shared code (log and utilities)
  • models
    • Resource models, don't use flask-sqlalchemy so the models can be used by scripts outside of flask context.

References & Examples

saas-api-boilerplate's People

Contributors

rgant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

shekarsiri

saas-api-boilerplate's Issues

Code under another license?

The code in this repo, especially the part that integrates marshmallow-jsonapi and marshmallow-sqlalchmey would be very handy to be able to use, but since this repo has a GPL-3 license, it can't be used in anything but GPL-3 compatible projects.

Any chance you'd be willing to release that portion of the code under a more permissive license?

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.