• Stars
    star
    24,890
  • Rank 860 (Top 0.02 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.

Full Stack FastAPI and PostgreSQL - Base Project Generator

Build Status

Generate a backend and frontend stack using Python, including interactive API documentation.

Interactive API documentation

API docs

Alternative API documentation

API docs

Dashboard Login

API docs

Dashboard - Create User

API docs

Features

  • Full Docker integration (Docker based).
  • Docker Swarm Mode deployment.
  • Docker Compose integration and optimization for local development.
  • Production ready Python web server using Uvicorn and Gunicorn.
  • Python FastAPI backend:
    • Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic).
    • Intuitive: Great editor support. Completion everywhere. Less time debugging.
    • Easy: Designed to be easy to use and learn. Less time reading docs.
    • Short: Minimize code duplication. Multiple features from each parameter declaration.
    • Robust: Get production-ready code. With automatic interactive documentation.
    • Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI and JSON Schema.
    • Many other features including automatic validation, serialization, interactive documentation, authentication with OAuth2 JWT tokens, etc.
  • Secure password hashing by default.
  • JWT token authentication.
  • SQLAlchemy models (independent of Flask extensions, so they can be used with Celery workers directly).
  • Basic starting models for users (modify and remove as you need).
  • Alembic migrations.
  • CORS (Cross Origin Resource Sharing).
  • Celery worker that can import and use models and code from the rest of the backend selectively.
  • REST backend tests based on Pytest, integrated with Docker, so you can test the full API interaction, independent on the database. As it runs in Docker, it can build a new data store from scratch each time (so you can use ElasticSearch, MongoDB, CouchDB, or whatever you want, and just test that the API works).
  • Easy Python integration with Jupyter Kernels for remote or in-Docker development with extensions like Atom Hydrogen or Visual Studio Code Jupyter.
  • Vue frontend:
    • Generated with Vue CLI.
    • JWT Authentication handling.
    • Login view.
    • After login, main dashboard view.
    • Main dashboard with user creation and edition.
    • Self user edition.
    • Vuex.
    • Vue-router.
    • Vuetify for beautiful material design components.
    • TypeScript.
    • Docker server based on Nginx (configured to play nicely with Vue-router).
    • Docker multi-stage building, so you don't need to save or commit compiled code.
    • Frontend tests ran at build time (can be disabled too).
    • Made as modular as possible, so it works out of the box, but you can re-generate with Vue CLI or create it as you need, and re-use what you want.
    • It's also easy to remove it if you have an API-only app, check the instructions in the generated README.md.
  • PGAdmin for PostgreSQL database, you can modify it to use PHPMyAdmin and MySQL easily.
  • Flower for Celery jobs monitoring.
  • Load balancing between frontend and backend with Traefik, so you can have both under the same domain, separated by path, but served by different containers.
  • Traefik integration, including Let's Encrypt HTTPS certificates automatic generation.
  • GitLab CI (continuous integration), including frontend and backend testing.

How to use it

Go to the directory where you want to create your project and run:

pip install cookiecutter
cookiecutter https://github.com/tiangolo/full-stack-fastapi-postgresql

Generate passwords

You will be asked to provide passwords and secret keys for several components. Open another terminal and run:

openssl rand -hex 32
# Outputs something like: 99d3b1f01aa639e4a76f4fc281fc834747a543720ba4c8a8648ba755aef9be7f

Copy the contents and use that as password / secret key. And run that again to generate another secure key.

Input variables

The generator (cookiecutter) will ask you for some data, you might want to have at hand before generating the project.

The input variables, with their default values (some auto generated) are:

  • project_name: The name of the project

  • project_slug: The development friendly name of the project. By default, based on the project name

  • domain_main: The domain in where to deploy the project for production (from the branch production), used by the load balancer, backend, etc. By default, based on the project slug.

  • domain_staging: The domain in where to deploy while staging (before production) (from the branch master). By default, based on the main domain.

  • docker_swarm_stack_name_main: The name of the stack while deploying to Docker in Swarm mode for production. By default, based on the domain.

  • docker_swarm_stack_name_staging: The name of the stack while deploying to Docker in Swarm mode for staging. By default, based on the domain.

  • secret_key: Backend server secret key. Use the method above to generate it.

  • first_superuser: The first superuser generated, with it you will be able to create more users, etc. By default, based on the domain.

  • first_superuser_password: First superuser password. Use the method above to generate it.

  • backend_cors_origins: Origins (domains, more or less) that are enabled for CORS (Cross Origin Resource Sharing). This allows a frontend in one domain (e.g. https://dashboard.example.com) to communicate with this backend, that could be living in another domain (e.g. https://api.example.com). It can also be used to allow your local frontend (with a custom hosts domain mapping, as described in the project's README.md) that could be living in http://dev.example.com:8080 to communicate with the backend at https://stag.example.com. Notice the http vs https and the dev. prefix for local development vs the "staging" stag. prefix. By default, it includes origins for production, staging and development, with ports commonly used during local development by several popular frontend frameworks (Vue with :8080, React, Angular).

  • smtp_port: Port to use to send emails via SMTP. By default 587.

  • smtp_host: Host to use to send emails, it would be given by your email provider, like Mailgun, Sparkpost, etc.

  • smtp_user: The user to use in the SMTP connection. The value will be given by your email provider.

  • smtp_password: The password to be used in the SMTP connection. The value will be given by the email provider.

  • smtp_emails_from_email: The email account to use as the sender in the notification emails, it would be something like [email protected].

  • postgres_password: Postgres database password. Use the method above to generate it. (You could easily modify it to use MySQL, MariaDB, etc).

  • pgadmin_default_user: PGAdmin default user, to log-in to the PGAdmin interface.

  • pgadmin_default_user_password: PGAdmin default user password. Generate it with the method above.

  • traefik_constraint_tag: The tag to be used by the internal Traefik load balancer (for example, to divide requests between backend and frontend) for production. Used to separate this stack from any other stack you might have. This should identify each stack in each environment (production, staging, etc).

  • traefik_constraint_tag_staging: The Traefik tag to be used while on staging.

  • traefik_public_constraint_tag: The tag that should be used by stack services that should communicate with the public.

  • flower_auth: Basic HTTP authentication for flower, in the formuser:password. By default: "admin:changethis".

  • sentry_dsn: Key URL (DSN) of Sentry, for live error reporting. You can use the open source version or a free account. E.g.: https://1234abcd:[email protected]/30.

  • docker_image_prefix: Prefix to use for Docker image names. If you are using GitLab Docker registry it would be based on your code repository. E.g.: git.example.com/development-team/my-awesome-project/.

  • docker_image_backend: Docker image name for the backend. By default, it will be based on your Docker image prefix, e.g.: git.example.com/development-team/my-awesome-project/backend. And depending on your environment, a different tag will be appended ( prod, stag, branch ). So, the final image names used will be like: git.example.com/development-team/my-awesome-project/backend:prod.

  • docker_image_celeryworker: Docker image for the celery worker. By default, based on your Docker image prefix.

  • docker_image_frontend: Docker image for the frontend. By default, based on your Docker image prefix.

How to deploy

This stack can be adjusted and used with several deployment options that are compatible with Docker Compose, but it is designed to be used in a cluster controlled with pure Docker in Swarm Mode with a Traefik main load balancer proxy handling automatic HTTPS certificates, using the ideas from DockerSwarm.rocks.

Please refer to DockerSwarm.rocks to see how to deploy such a cluster in 20 minutes.

More details

After using this generator, your new project (the directory created) will contain an extensive README.md with instructions for development, deployment, etc. You can pre-read the project README.md template here too.

Sibling project generators

Release Notes

Latest Changes

  • Update issue-manager. PR #211.
  • Add GitHub Sponsors button. PR #201.
  • Add consistent errors for env vars not set. PR #200.
  • Upgrade Traefik to version 2, keeping in sync with DockerSwarm.rocks. PR #199.
  • Add docs about reporting test coverage in HTML. PR #161.
  • Run tests with TestClient. PR #160.
  • Refactor backend:
    • Simplify configs for tools and format to better support editor integration.
    • Add mypy configurations and plugins.
    • Add types to all the codebase.
    • Update types for SQLAlchemy models with plugin.
    • Update and refactor CRUD utils.
    • Refactor DB sessions to use dependencies with yield.
    • Refactor dependencies, security, CRUD, models, schemas, etc. To simplify code and improve autocompletion.
    • Change from PyJWT to Python-JOSE as it supports additional use cases.
    • Fix JWT tokens using user email/ID as the subject in sub.
    • PR #158.
  • Add docs about removing the frontend, for an API-only app. PR #156.
  • Simplify scripts and development, update docs and configs. PR #155.
  • Simplify docker-compose.*.yml files, refactor deployment to reduce config files. PR #153.
  • Simplify env var files, merge to a single .env file. PR #151.

0.5.0

  • Make the Traefik public network a fixed default of traefik-public as done in DockerSwarm.rocks, to simplify development and iteration of the project generator. PR #150.
  • Update to PostgreSQL 12. PR #148. by @RCheese.
  • Use Poetry for package management. Initial PR #144 by @RCheese.
  • Fix Windows line endings for shell scripts after project generation with Cookiecutter hooks. PR #149.
  • Upgrade Vue CLI to version 4. PR #120 by @br3ndonland.
  • Remove duplicate login tag. PR #135 by @Nonameentered.
  • Fix showing email in dashboard when there's no user's full name. PR #129 by @rlonka.
  • Format code with Black and Flake8. PR #121 by @br3ndonland.
  • Simplify SQLAlchemy Base class. PR #117 by @airibarne.
  • Update CRUD utils for users, handling password hashing. PR #106 by @mocsar.
  • Use . instead of source for interoperability. PR #98 by @gucharbon.
  • Use Pydantic's BaseSettings for settings/configs and env vars. PR #87 by @StephenBrown2.
  • Remove package-lock.json to let everyone lock their own versions (depending on OS, etc).
  • Simplify Traefik service labels PR #139.
  • Add email validation. PR #40 by @kedod.
  • Fix typo in README. PR #83 by @ashears.
  • Fix typo in README. PR #80 by @abjoker.
  • Fix function name read_item and response code. PR #74 by @jcaguirre89.
  • Fix typo in comment. PR #70 by @daniel-butler.
  • Fix Flower Docker configuration. PR #37 by @dmontagu.
  • Add new CRUD utils based on DB and Pydantic models. Initial PR #23 by @ebreton.
  • Add normal user testing Pytest fixture. PR #20 by @ebreton.

0.4.0

  • Fix security on resetting a password. Receive token as body, not query. PR #34.

  • Fix security on resetting a password. Receive it as body, not query. PR #33 by @dmontagu.

  • Fix SQLAlchemy class lookup on initialization. PR #29 by @ebreton.

  • Fix SQLAlchemy operation errors on database restart. PR #32 by @ebreton.

  • Fix locations of scripts in generated README. PR #19 by @ebreton.

  • Forward arguments from script to pytest inside container. PR #17 by @ebreton.

  • Update development scripts.

  • Read Alembic configs from env vars. PR #9 by @ebreton.

  • Create DB Item objects from all Pydantic model's fields.

  • Update Jupyter Lab installation and util script/environment variable for local development.

0.3.0

  • PR #14:

    • Update CRUD utils to use types better.
    • Simplify Pydantic model names, from UserInCreate to UserCreate, etc.
    • Upgrade packages.
    • Add new generic "Items" models, crud utils, endpoints, and tests. To facilitate re-using them to create new functionality. As they are simple and generic (not like Users), it's easier to copy-paste and adapt them to each use case.
    • Update endpoints/path operations to simplify code and use new utilities, prefix and tags in include_router.
    • Update testing utils.
    • Update linting rules, relax vulture to reduce false positives.
    • Update migrations to include new Items.
    • Update project README.md with tips about how to start with backend.
  • Upgrade Python to 3.7 as Celery is now compatible too. PR #10 by @ebreton.

0.2.2

0.2.1

  • Fix documentation for path operation to get user by ID. PR #4 by @mpclarkson in FastAPI.

  • Set /start-reload.sh as a command override for development by default.

  • Update generated README.

0.2.0

PR #2:

  • Simplify and update backend Dockerfiles.
  • Refactor and simplify backend code, improve naming, imports, modules and "namespaces".
  • Improve and simplify Vuex integration with TypeScript accessors.
  • Standardize frontend components layout, buttons order, etc.
  • Add local development scripts (to develop this project generator itself).
  • Add logs to startup modules to detect errors early.
  • Improve FastAPI dependency utilities, to simplify and reduce code (to require a superuser).

0.1.2

  • Fix path operation to update self-user, set parameters as body payload.

0.1.1

Several bug fixes since initial publication, including:

  • Order of path operations for users.
  • Frontend sending login data in the correct format.
  • Add https://localhost variants to CORS.

License

This project is licensed under the terms of the MIT license.

More Repositories

1

fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production
Python
73,897
star
2

typer

Typer, build great CLIs. Easy to code. Based on Python type hints.
Python
14,943
star
3

sqlmodel

SQL databases in Python, designed for simplicity, compatibility, and robustness.
Python
13,694
star
4

uwsgi-nginx-flask-docker

Docker image with uWSGI and Nginx for Flask applications in Python running in a single container.
Python
2,986
star
5

uvicorn-gunicorn-fastapi-docker

Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python with performance auto-tuning.
Python
2,699
star
6

asyncer

Asyncer, async and await, focused on developer experience.
Python
1,517
star
7

pydantic-sqlalchemy

Tools to convert SQLAlchemy models to Pydantic models
Python
1,173
star
8

nginx-rtmp-docker

Docker image with Nginx using the nginx-rtmp-module module for live multimedia (video) streaming.
Dockerfile
1,110
star
9

dockerswarm.rocks

Docker Swarm mode rocks! Ideas, tools and recipes. Get a production-ready, distributed, HTTPS served, cluster in minutes, not weeks.
Python
1,093
star
10

uwsgi-nginx-docker

Docker image with uWSGI and Nginx for applications in Python (as Flask) in a single container.
Python
646
star
11

uvicorn-gunicorn-docker

Docker image with Uvicorn managed by Gunicorn for high-performance web applications in Python with performance auto-tuning.
Python
628
star
12

full-stack

Full stack, modern web application generator. Using Flask, PostgreSQL DB, Docker, Swagger, automatic HTTPS and more.
Python
523
star
13

meinheld-gunicorn-flask-docker

Docker image with Meinheld and Gunicorn for Flask applications in Python.
Python
486
star
14

full-stack-fastapi-couchbase

Full stack, modern web application generator. Using FastAPI, Couchbase as database, Docker, automatic HTTPS and more.
Python
440
star
15

typer-cli

Run Typer scripts with completion, without having to create a package, using Typer CLI.
Python
367
star
16

poetry-version-plugin

Poetry plugin for dynamically extracting the package version from a __version__ variable or a Git tag.
Python
361
star
17

fastapi-cli

Run and manage FastAPI apps from the command line with FastAPI CLI. 🚀
Python
287
star
18

blog-posts

Blog posts and related code by Sebastián Ramírez (@tiangolo)
Python
273
star
19

uvicorn-gunicorn-starlette-docker

Docker image with Uvicorn managed by Gunicorn for high-performance Starlette web applications in Python with performance auto-tuning.
Python
182
star
20

latest-changes

A GitHub Action to add latest changes after each PR merged automatically
Python
172
star
21

babun-docker

Use Docker Toolbox with Babun (Cygwin) in Windows
Shell
170
star
22

meinheld-gunicorn-docker

Docker image with Meinheld managed by Gunicorn for high-performance WSGI (Flask, Django, etc) web applications in Python with performance auto-tuning.
Python
165
star
23

docker-with-compose

Docker image with Docker Compose installed for CI.
Shell
158
star
24

node-frontend

Instrutctions to buid a frontend Docker image built with Node.js and then served with Nginx. Previously a Docker image.
Dockerfile
137
star
25

flask-frontend-docker

Minimal project generator with a Flask backend, a modern frontend (Vue, React or Angular), a Traefik load balancer with HTTPS, all based on Docker.
Vue
130
star
26

python-machine-learning-docker

Docker image with Python 3.6 and 3.7 using Conda, with CUDA variants. To serve as base image for Machine Learning projects.
Dockerfile
84
star
27

uvicorn-gunicorn-machine-learning-docker

Docker image for high-performance Machine Learning web applications. With Uvicorn managed by Gunicorn in Python 3.7 and 3.6, using Conda, with CUDA and TensorFlow variants.
Python
67
star
28

issue-manager

Automatically close issues that have a label, after a custom delay, if no one replies back.
Python
62
star
29

full-stack-flask-couchbase

Full stack, modern web application generator. Using Flask, Couchbase as database, Docker, Swagger, automatic HTTPS and more.
Python
59
star
30

label-approved

Label a Pull Request after a number of approvals
Python
34
star
31

full-stack-flask-couchdb

Full stack, modern web application generator. Using Flask, CouchDB as database, Docker, Swagger, automatic HTTPS and more.
Python
31
star
32

tiangolo

16
star
33

github-actions-sandbox

Not useful for you. It's just a sandbox GitHub repo for me to try out stuff and develop GitHub Actions.
Python
16
star
34

tiangolo.com

Python
16
star
35

docker-auto-labels

Generate each Docker constraint label in random nodes in the cluster.
Python
15
star
36

angular-docker-multi-stage-example

Angular in Docker with Nginx, supporting environments, built with multi-stage Docker builds
15
star
37

ngx-http-client

Angular (4.3+) HttpClientModule with parameter encodings compatible with back ends (Node.js, Python, PHP, etc)
TypeScript
11
star
38

compose-to-rancher

Convert Docker Compose V2 to Rancher compatible Docker Compose V1
Python
10
star
39

markdown-include-variants

Markdown extension to expand directives to include source example files to also include their variants. Only useful to tiangolo's projets. Don't use it. 😅
Python
9
star
40

wunderlist2csv

Convert from Wunderlist backup json file to a CSV file importable by TaskCoach
Python
6
star
41

anaconda_cluster_install

Automatically Install Anaconda Python in a cluster of machines, for a specified user.
Shell
5
star
42

bitbucket_issues_to_redmine_csv

Python
3
star