Settings
Core Settings are in TOML
format. Because TOML is easy to read for humans and computers.
TOML
Since TOML
is Python
's new best friend. Feels like a good fit for the core settings of the project.
Settings Workflow
Settings
- Load
pyproject.toml
- Load
spoc.toml
- Load
settings.py
- Load
Environment Variables
flowchart TB;
A[pyproject.toml] --> E{Project Settings};
B[spoc.toml] --> E{Project Settings};
C[settings.py] --> E;
D[environment.toml] --> E;
Settings Locations
root/ --> <Directory> - Project's Root.
|
|-- config/ --> <Directory> - Configurations.
| |
| |-- .env/ --> <Directory> - Environments.
| | |-- development.toml --> <File> - Development Settings.
| | |-- production.toml --> <File> - Production Settings.
| | `-- staging.toml --> <File> - Staging Settings.
| |
| |-- settings.py --> <File> - Pythonic Settings.
| `-- spoc.toml --> <File> - Spoc Settings.
|
|-- pyproject.toml --> <File> - PyProject Settings.
`-- etc...
pyproject (TOML)
[project]
name = "fastberry" # (1)
version = "0.1.4" # (2)
description = "GraphQL Made Easy." # (3)
# etc ... (4)
- Name — The name of the project.
- Version — The version of the project.
- Description — Short description of your project.
- Other — Extra configurations of your project.
PyProject
fastberry.config["pyproject"]
is where your PyProject Variables are loaded.
SPOC (TOML)
[spoc] # (1)
mode = "custom" # development, production, staging, custom
custom_mode = "development" # (16)
docs = "config/docs.md" # (17)
generates = "graphql" # (18)
[spoc.api] # (2)
graphql_path = "/graphql" # (10)
max_depth = 4 # (11)
items_per_page = 50 # (12)
allowed_hosts = ["http://localhost", "http://localhost:8080"]
[spoc.apps] # (3)
production = ["app_one", "app_two"] # (13)
development = [] # (14)
staging = [] # (15)
[spoc.extras] # (4)
middleware = ["fastberry.extras.middleware "] # (5)
extensions = ["fastberry.extras.extensions"] # (6)
permissions = ["fastberry.extras.permissions"] # (7)
on_startup = ["fastberry.extras.on_startup"] # (8)
on_shutdown = ["fastberry.extras.on_shutdown"] # (9)
- API — Core Settings.
- API — Querying & More Configs.
- Installed — Apps.
- Installed — Middleware, Extension & Permissions.
- Middleware — For adding behavior that is applied across your entire (FastAPI) application.
- Extensions — For adding behavior that is applied across your entire (GraphQL) application.
- Permissions — For adding Permissions to your (GraphQL) application.
- On-Startup — For adding behavior that is applied before the server start.
- On-Shutdown — For adding behavior that is applied after the server shutdown.
- Endpoint — GraphQL's URL endpoint.
- Depth — Search depth in the GraphQL's tree.
- Pagination — Number of rows per page.
- Production — Production Ready Apps (
Production
). - Development — Development Only Apps (
Production
+Development
). - Staging — Testing Only Apps (
Production
+Staging
). - Custom — Custom mode will load
Apps
from the pythonicsettings.py
plus the currentmode
. - Docs — Path for the documentation.
- Generates — Folder where the schema and frontend related files and folders will be generated.
SPOC
fastberry.config["spoc"]
is where your SPOC Variables are loaded.
Environment Variables (TOML)
[env]
DEBUG = "yes"
SECRET_KEY = "fastapi-insecure-09d25e094faa6ca2556c"
Variables
fastberry.config["env"]
is where your Environment Variables are loaded.
Custom (Python)
# -*- coding: utf-8 -*-
"""
{ Settings }
"""
import pathlib
# Base Directory
BASE_DIR = pathlib.Path(__file__).parents[1]
# Installed Apps
INSTALLED_APPS = ["good_app", "app_two"]
# Database(s)
DATABASES = {
"sql" : {"default": "sqlite:///example.db"},
"mongo": {"default": "mongodb://localhost:27017/example"},
}
PyProject
fastberry.config["pyproject"]
is where your PyProject Variables are loaded.
Breakdown of the Middlewares, Extensions and Permissions
MIDDLEWARE (Starlette)
List of active Middlewares.
You can create your own middleware
by using the base module.
The BaseMiddleware
included is just a wrapper/rename for BaseHTTPMiddleware from Starlette
EXTENSIONS (Strawberry)
List of active Extensions.
You can create your own extension
by using the base module.
The BaseExtension
included is just a wrapper/rename for Extension from Strawberry
PERMISSIONS (Strawberry)
List of active Permissions.
You can create your own permissions
by using the base module.
The BasePermission
included is just a wrapper for BasePermission from Strawberry