Skip to content

fndmiranda/saas-api

Repository files navigation

Python SaaS application boilerplate (asynchronous)

This project simplifies the creation of a Python SaaS api with the FastAPI framework, SQLAlchemy and Pipenv to create and manage a virtualenv.

  • FastAPI framework
  • SQLAlchemy (asynchronous) SQL toolkit and Object Relational Mapper
    • PostgreSQL
    • MySQL
    • Oracle
    • Microsoft SQL Server
    • SQLite
  • Alembic database migration tool
  • Authentication with OAuth2
  • Account
    • User Account Crud
    • Email password recovery
    • Registration email verification
  • Notification
    • Strategy for notifications
  • Store
    • Permissions control for owner
    • Store segment
  • Address
    • Address with a so-called "generic foreign key" to accounts and stores

Prepare environment

Install Pyenv for Python version management.

Pyenv installation instructions can be found in Pyenv page

Install Python 3.10.

$ pyenv install 3.10

Install Pipenv.

$ pip install --user pipenv

More detailed about Pipenv installation instructions can be found in the Pipenv page.

Create a new virtualenv using Python 3.10.

$ pipenv --python 3.10

Spawns a shell within the virtualenv.

$ pipenv shell

Install dependencies

Execute the following commands to install dependencies:

$ make requirements-dev

in production

$ make requirements

Configure the application environment

Copy and edit the .env file as needed.

$ cp .env.example .env

Run migrations

Execute the following command to create a migration:

$ alembic revision -m "Create catalog_products table"

The migrations will be created in the alembic/versions folder.

Execute the following command to upgrade to last revision:

$ alembic upgrade head

Execute the following command to downgrade version:

$ alembic downgrade -1

Execute the following command to display the current revision for a database.

$ alembic current

Execute the following command to list the history of migrations:

$ alembic history

Run application

Execute the following command to run the application in a development environment:

$ make runserver-dev

Execute the following command to run the application with gunicorn:

$ make runserver

Display registered routes.

Execute the following command to list all registered routes:

$ make show-routes

Pagination with dynamic filter and sorting.

Pass the filter field in query string, as in the example:

[{"field":"foo", "op":"ilike", "value":"%bar%"}]

Operators options are:

is_null, is_not_null, eq, ne, gt, lt, ge, le, like, ilike, not_ilike, in, not_in, any, not_any

Pass the sort field in query string, as in the example:

[{"field":"foo", "direction":"asc"}]

Api documentation

The base address of RESTful API is http://localhost:8000 and Swagger documentation is http://localhost:8000/docs

Outdated packages

Execute the following command to list outdated packages:

$ make outdated

Celery

Execute the following command to run celery task queues:

$ make runcelery

Execute the following command to run flower: Flower is a web based tool for monitoring and administrating Celery clusters

$ make runflower

Testing

Unit tests

Execute the following command to run all tests:

$ make test

Execute the following command to run test with name match, example:

$ make test-matching test=test_store_view_should_get_segments

Execute the following command to run celery task queues in tenting mode:

$ make runcelery-test

Execute the following command to run test with coverage reports, example:

$ make coverage

Lint

Execute the following command to check lint:

$ make check-lint

Execute the following command to try fix lint:

$ make lint

Security

Execute the following command to check security vulnerabilities in packages:

$ make check-safety

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

About

Python SaaS application boilerplate (async)

Resources

License

Stars

Watchers

Forks

Packages

No packages published