1414[ ![ Pyright] ( https://microsoft.github.io/pyright/img/pyright_badge.svg )] ( https://microsoft.github.io/pyright/ )
1515[ ![ Copier] ( https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json )] ( https://github.com/aignostics/foundry-python )
1616
17- > [ !NOTE]
18- > This is your project README - please feel free to update as you see fit.
19- > For first steps after scaffolding, check out [ FOUNDRY_README.md] ( FOUNDRY_README.md ) .
20-
21- ---
22-
2317Foundational infrastructure for Foundry components.
2418
2519## Prerequisites
@@ -34,6 +28,61 @@ Or follow the [installation guide](https://mise.jdx.dev/getting-started.html) fo
3428
3529## Usage
3630
31+ ### Initialise the context at application startup
32+
33+ Call ` set_context() ` once, before any library code runs, then call ` boot() ` to
34+ initialise logging, the SSL trust chain, and optional Sentry integration:
35+
36+ ``` python
37+ # main.py
38+ from aignostics_foundry_core.foundry import FoundryContext, set_context
39+ from aignostics_foundry_core.boot import boot
40+
41+ set_context(FoundryContext.from_package(" myproject" ))
42+ boot()
43+ ```
44+
45+ ` FoundryContext.from_package() ` derives everything from package metadata and
46+ environment variables:
47+
48+ - ` name ` , ` version ` , ` version_full ` — from ` importlib.metadata `
49+ - ` environment ` — from ` MYPROJECT_ENVIRONMENT ` → ` ENV ` → ` VERCEL_ENV ` →
50+ ` RAILWAY_ENVIRONMENT ` → ` "local" `
51+ - ` is_container ` , ` is_cli ` , ` is_test ` , ` is_library ` — detected automatically
52+ - ` env_prefix ` (` "MYPROJECT_" ` ) — used by every settings class in the library
53+
54+ ### Access the context from any module
55+
56+ ``` python
57+ from aignostics_foundry_core.foundry import get_context
58+
59+ ctx = get_context()
60+ print (f " Running { ctx.name} v { ctx.version_full} in { ctx.environment} " )
61+ # → Running myproject v1.2.3+main---run.12345 in staging
62+ ```
63+
64+ ` get_context() ` raises ` RuntimeError ` with a clear message if ` set_context() `
65+ was never called.
66+
67+ ### Pass context explicitly in tests
68+
69+ Never call ` set_context() ` in tests. Pass a ` FoundryContext ` directly to each
70+ function via its optional ` context ` parameter instead:
71+
72+ ``` python
73+ from aignostics_foundry_core.foundry import FoundryContext
74+ from aignostics_foundry_core.log import logging_initialize
75+
76+ ctx = FoundryContext(name = " myproject" , version = " 0.0.0" , version_full = " 0.0.0" , environment = " test" )
77+ logging_initialize(context = ctx)
78+ ```
79+
80+ All public library functions (` logging_initialize ` , ` sentry_initialize ` , ` boot ` ,
81+ ` load_modules ` , etc.) accept an optional ` context ` keyword argument and fall
82+ back to ` get_context() ` when it is ` None ` .
83+
84+ ### Health API
85+
3786``` python
3887from aignostics_foundry_core.health import Health, HealthStatus
3988
0 commit comments