benavlabs /
FastAPI-boilerplate
An extendable async API using FastAPI, Pydantic V2, SQLAlchemy 2.0, PostgreSQL and Redis.
91/100 healthLoading repository data…
benavlabs / repository
An extendable async API using FastAPI, SQLModel, PostgreSQL and Redis.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
[!IMPORTANT] This SQLModel boilerplate is no longer actively maintained. For a maintained FastAPI starter, use the Fastro FastAPI-boilerplate (free, SQLAlchemy) or FastroAI - the complete FastAPI SaaS template (auth, payments, AI, a frontend).
FastAPI boilerplate creates an extendable async API using FastAPI, SQLModel and PostgreSQL:
FastAPI: modern Python web framework for building APIsSQLModel: SQL databases in Python, designed for simplicity, compatibility, and robustness.PostgreSQL: The World's Most Advanced Open Source Relational DatabaseRedis: Source Available, in-memory data store used by millions as a cache, message broker and more.ARQ Job queues and RPC in python with asyncio and redis.Docker Compose With a single command, create and start all the services from your configuration.NGINX High-performance low resource consumption web server used for Reverse Proxy and Load Balancing.Start by using the template, and naming the repository to what you want.
Then clone your created repository (I'm using the base for the example)
git clone https://github.com/igormagalhaesr/SQLModel-boilerplate
[!TIP] If you are in a hurry, you may use one of the following templates (containing a
.env,docker-compose.ymlandDockerfile):
[!WARNING] Do not forget to place
docker-compose.ymlandDockerfilein therootfolder, while.envshould be in thesrcfolder.
Then create a .env file inside src directory:
touch .env
Inside of .env, create the following app settings variables:
# ------------- app settings -------------
APP_NAME="Your app name here"
APP_DESCRIPTION="Your app description here"
APP_VERSION="0.1"
CONTACT_NAME="Your name"
CONTACT_EMAIL="Your email"
LICENSE_NAME="The license you picked"
For the database (if you don't have a database yet, click here), create:
# ------------- database -------------
POSTGRES_USER="your_postgres_user"
POSTGRES_PASSWORD="your_password"
POSTGRES_SERVER="your_server" # default "localhost", if using docker compose you should use "db"
POSTGRES_PORT=5432 # default "5432", if using docker compose you should use "5432"
POSTGRES_DB="your_db"
For database administration using PGAdmin create the following variables in the .env file
# ------------- pgadmin -------------
PGADMIN_DEFAULT_EMAIL="your_email_address"
PGADMIN_DEFAULT_PASSWORD="your_password"
PGADMIN_LISTEN_PORT=80
To connect to the database, log into the PGAdmin console with the values specified in PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD.
Once in the main PGAdmin screen, click Add Server:

db (if using containers)POSTGRES_PORTpostgresPOSTGRES_USERPOSTGRES_PASSWORDFor crypt: Start by running
openssl rand -hex 32
And then create in .env:
# ------------- crypt -------------
SECRET_KEY= # result of openssl rand -hex 32
ALGORITHM= # pick an algorithm, default HS256
ACCESS_TOKEN_EXPIRE_MINUTES= # minutes until token expires, default 30
REFRESH_TOKEN_EXPIRE_DAYS= # days until token expires, default 7
Then for the first admin user:
# ------------- admin -------------
ADMIN_NAME="your_name"
ADMIN_EMAIL="your_email"
ADMIN_USERNAME="your_username"
ADMIN_PASSWORD="your_password"
For redis caching:
# ------------- redis cache-------------
REDIS_CACHE_HOST="your_host" # default "localhost", if using docker compose you should use "redis"
REDIS_CACHE_PORT=6379 # default "6379", if using docker compose you should use "6379"
And for client-side caching:
# ------------- redis client-side cache -------------
CLIENT_CACHE_MAX_AGE=30 # default "30"
For ARQ Job Queues:
# ------------- redis queue -------------
REDIS_QUEUE_HOST="your_host" # default "localhost", if using docker compose you should use "redis"
REDIS_QUEUE_PORT=6379 # default "6379", if using docker compose you should use "6379"
[!WARNING] You may use the same redis for both caching and queue while developing, but the recommendation is using two separate containers for production.
To create the first tier:
# ------------- first tier -------------
TIER_NAME="free"
For the rate limiter:
# ------------- redis rate limit -------------
REDIS_RATE_LIMIT_HOST="localhost" # default="localhost", if using docker compose you should use "redis"
REDIS_RATE_LIMIT_PORT=6379 # default=6379, if using docker compose you should use "6379"
# ------------- default rate limit settings -------------
DEFAULT_RATE_LIMIT_LIMIT=10 # default=10
DEFAULT_RATE_LIMIT_PERIOD=3600 # default=3600
For tests (optional to run):
# ------------- test -------------
TEST_NAME="Tester User"
TEST_EMAIL="test@tester.com"
TEST_USERNAME="testeruser"
TEST_PASSWORD="Str1ng$t"
And Finally the environment:
# ------------- environment -------------
ENVIRONMENT="local"
ENVIRONMENT can be one of local, staging and production, defaults to local, and changes the behavior of api docs endpoints:
/docs, /redoc and /openapi.json available/docs, /redoc and /openapi.json available for superusers/docs, /redoc and /openapi.json not availableTo do it using docker compose, ensure you have docker and docker compose installed, then: While in the base project directory (FastAPI-boilerplate here), run:
docker compose up
You should have a web container, postgres container, a worker container and a redis container running.
Then head to http://127.0.0.1:8000/docs.
Install poetry:
pip install poetry
If you used docker compose, your setup is done. You just need to ensure that when you run (while in the base folder):
docker compose up
You get the following outputs (in addition to many other outputs):
fastapi-boilerplate-worker-1 | ... redis_version=x.x.x mem_usage=999K clients_connected=1 db_keys=0
...
fastapi-boilerplate-db-1 | ... [1] LOG: database system is ready to accept connections
...
fastapi-boilerplate-web-1 | INFO: Application startup complete.
So you may skip to 5. Extending.
Selected from shared topics, language and repository description—not editorial ratings.
benavlabs /
An extendable async API using FastAPI, Pydantic V2, SQLAlchemy 2.0, PostgreSQL and Redis.
91/100 health