Pydantic-settings building blocks for the fastfoundry ecosystem.
Project description
fastfoundry-settings
Pydantic-settings building blocks for the fastfoundry ecosystem — opinionated, typed defaults so every FastAPI service configures settings the same way.
Part of the fastfoundry.* namespace (fastfoundry-postgres, fastfoundry-redis, …).
Install
pip install fastfoundry-settings
# or
uv add fastfoundry-settings
Requires Python 3.12+.
Usage
from fastfoundry.settings import BaseAppSettings
class Settings(BaseAppSettings):
service_name: str
debug: bool = False
settings = Settings()
Set values through FF_-prefixed environment variables (or a .env file) — e.g.
FF_SERVICE_NAME=billing, FF_DEBUG=true.
BaseAppSettings ships these defaults (override model_config to change any):
| Setting | Value | Effect |
|---|---|---|
env_prefix |
FF_ |
env vars are read under the FF_ prefix (override per app) |
env_file |
.env |
loads variables from a local .env if present |
env_nested_delimiter |
__ |
FF_DB__HOST populates settings.db.host |
case_sensitive |
False |
FF_DEBUG and ff_debug both match |
extra |
ignore |
unknown env vars don't raise |
Short import alias, if you like:
import fastfoundry.settings as ff
ff.BaseAppSettings
Helper field types
Two Annotated types for common settings shapes:
from fastfoundry.settings import BaseAppSettings, EscapedSecretStr, StringList
class Settings(BaseAppSettings):
# "a,b,c" (or FF_HOSTS=a,b,c) -> ["a", "b", "c"]; a real list passes through.
hosts: StringList = None
# literal \n / \t are restored before wrapping in SecretStr; "" / None -> None.
# handy for a PEM or JWT key supplied on a single line.
private_key: EscapedSecretStr = None
StringList— alist[str] | Nonethat also accepts a single comma-separated string.EscapedSecretStr— aSecretStr | Nonethat restores literal\n/\tto real characters.
AWS Secrets Manager
Install the extra and point a settings class at a secret:
pip install 'fastfoundry-settings[aws]'
from fastfoundry.settings import BaseAppSettings
class Settings(BaseAppSettings):
aws_secret_id = "prod/myservice" # enables the AWS Secrets Manager source
aws_region_name = "eu-central-1" # optional; defaults to botocore's resolution
database_dsn: str | None = None
api_key: str | None = None
settings = Settings() # database_dsn / api_key come from the secret
The secret's SecretString must be a JSON object; keys have the FF_ prefix stripped
(when present) and match fields case-insensitively, and JSON object/array values are
decoded into dicts/lists. The source is the lowest-precedence layer, so an explicit
env var overrides a secret value. If the secret can't be fetched (missing, unreachable,
malformed) the source logs a warning and contributes nothing — settings still build from
env and defaults. Without the aws extra installed, using it raises a clear ImportError.
The AwsSecretsManagerSource class is exported too, for composing it into a custom
settings_customise_sources yourself.
Settings singleton
For apps that build one settings object at start-up and read it anywhere:
from fastfoundry.settings import cfg, config_factory, set_cfg
def main() -> None:
set_cfg(config_factory(Settings)) # build + register once
run_app()
def run_app() -> None:
if cfg().debug: # read the singleton anywhere
...
config_factory(Settings, **kwargs)— build a settings instance.set_cfg(config)— register the process-wide singleton (once; raises if already set).cfg()— return it (raisesRuntimeErrorifset_cfghas not run).
Not thread-safe; register during single-threaded start-up.
Logging
loguru is the default logger. Configure it once at start-up:
from fastfoundry.settings import LoggingSettings, setup_logging
setup_logging(LoggingSettings(level="INFO")) # or setup_logging() for the defaults
Drive it from the environment by embedding LoggingSettings as a field:
from fastfoundry.settings import BaseAppSettings, LoggingSettings, setup_logging
class Settings(BaseAppSettings):
logging: LoggingSettings = LoggingSettings()
settings = Settings() # FF_LOGGING__LEVEL=DEBUG, FF_LOGGING__SERIALIZE=true, …
setup_logging(settings.logging)
| Field | Default | Effect |
|---|---|---|
level |
INFO |
minimum level for the stderr sink |
serialize |
False |
emit structured JSON lines (set true in production) |
colorize |
True |
colored, human-readable output (ignored when serialize) |
backtrace / diagnose |
False |
loguru exception detail (keep off where secrets may appear) |
intercept_stdlib |
True |
route standard-library logging through loguru too |
Development
mise run install # uv sync --dev
mise run lint # ruff check
mise run typecheck # mypy --strict
mise run test # pytest
mise run build # uv build (sdist + wheel)
Versions are derived from git tags (hatch-vcs) and released automatically by
semantic-release on main; nothing is hand-written into pyproject.toml.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastfoundry_settings-1.0.0.tar.gz.
File metadata
- Download URL: fastfoundry_settings-1.0.0.tar.gz
- Upload date:
- Size: 50.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36ce008ecafb99c76cfabe83a730766e07bd2feaccf96447846b2421cb4c8053
|
|
| MD5 |
13786fa96a33106aad9341323d6785d3
|
|
| BLAKE2b-256 |
da21b96caddfc950c6c86c7dd65858211a57835ca0b9d77b7595556eafd4d485
|
Provenance
The following attestation bundles were made for fastfoundry_settings-1.0.0.tar.gz:
Publisher:
release.yml on Drozdetskiy/fastfoundry-settings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastfoundry_settings-1.0.0.tar.gz -
Subject digest:
36ce008ecafb99c76cfabe83a730766e07bd2feaccf96447846b2421cb4c8053 - Sigstore transparency entry: 1818426026
- Sigstore integration time:
-
Permalink:
Drozdetskiy/fastfoundry-settings@4b609adee907738e1c33d7da498125cf3070fe8b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Drozdetskiy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b609adee907738e1c33d7da498125cf3070fe8b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastfoundry_settings-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fastfoundry_settings-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a8e2c72100d5da8f232da127743f4e5e2a5be03d0e46567353e2fcc23a533c9
|
|
| MD5 |
9279ca747b6fafb889ea3128b073d7fa
|
|
| BLAKE2b-256 |
6f13f57c5b5e4f16675ef37a07b0dc0c31e59cf3983d9215d42ba8c7e5ccda32
|
Provenance
The following attestation bundles were made for fastfoundry_settings-1.0.0-py3-none-any.whl:
Publisher:
release.yml on Drozdetskiy/fastfoundry-settings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastfoundry_settings-1.0.0-py3-none-any.whl -
Subject digest:
6a8e2c72100d5da8f232da127743f4e5e2a5be03d0e46567353e2fcc23a533c9 - Sigstore transparency entry: 1818426064
- Sigstore integration time:
-
Permalink:
Drozdetskiy/fastfoundry-settings@4b609adee907738e1c33d7da498125cf3070fe8b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Drozdetskiy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b609adee907738e1c33d7da498125cf3070fe8b -
Trigger Event:
workflow_dispatch
-
Statement type: