Skip to content

Commit e5f414d

Browse files
committed
Simplify ApplicationSettings
1 parent 31ece92 commit e5f414d

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,18 @@ uv run -- poe start-api-dev
1515
```bash
1616
docker compose --file docker-compose-dev.yaml down --volumes
1717
```
18+
19+
# Reasonings
20+
21+
## .env files
22+
23+
**Key points:**
24+
25+
- We store settings in .env files.
26+
- There's a .env.{environment} file for each environment (Local, Development, Staging, Production).
27+
- There's a .env file for common settings.
28+
- If a setting is in both .env and .env.{environment}, the one in .env.{environment} takes precedence.
29+
30+
The typical is to save .env files in the root of the project, but due to some popular tools and libraries (Jupyter, FastAPI, Docker Compose...) load the file `.env` automatically (and an application has its own order, such as giving priority to the current environment, environment variables or a secret store), then we need to store them in another location (in this case, in the "api" folder) and give `ApplicationSettings` the path to the files.
31+
32+
Note: Renaming `.env` to `.env.Common` in the root isn't better because if your notebook isn't in the root, you have to specify the path in `ApplicationSettings` anyway, and `Common` can be confusing because it's not an environment.

src/python_archetype/api/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LOGGING_LEVEL="WARNING"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
LoggingLevel="CRITICAL"
21
AZURE_KEY_VAULT_URL="https://my-resource.vault.azure.net/"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
LoggingLevel="CRITICAL"
21
AZURE_KEY_VAULT_URL="https://my-resource.vault.azure.net/"

src/python_archetype/api/application_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class ApplicationSettings(BaseSettings):
3333
def settings_customise_sources(
3434
cls,
3535
settings_cls: type[BaseSettings],
36-
init_settings: PydanticBaseSettingsSource, # noqa: ARG003
36+
init_settings: PydanticBaseSettingsSource,
3737
env_settings: PydanticBaseSettingsSource,
3838
dotenv_settings: PydanticBaseSettingsSource,
39-
file_secret_settings: PydanticBaseSettingsSource, # noqa: ARG003
39+
file_secret_settings: PydanticBaseSettingsSource,
4040
) -> tuple[PydanticBaseSettingsSource, ...]:
41-
settings = (env_settings, dotenv_settings)
41+
settings = (init_settings, env_settings, dotenv_settings, file_secret_settings)
4242

4343
if ApplicationEnvironment.get_current() != ApplicationEnvironment.LOCAL:
4444
azure_key_vault = AzureKeyVaultSettingsSource(

0 commit comments

Comments
 (0)