Level 3 / Project 11 - Project Config Bootstrap¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Estimated time: 50 minutes
Focus¶
- bootstrap config with environment overrides
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-3/11-project-config-bootstrap
python project.py show
python project.py show --config-file config.json
python project.py validate --config-file config.json
python project.py generate default_config.json
pytest -q
Expected terminal output¶
{"app_name": "myapp", "debug": false, "port": 8000, ...}
Sources:
app_name: myapp (from default)
port: 5000 (from file)
12 passed
Expected artifacts¶
- Config output on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add support for TOML config files alongside JSON.
- Add a
--mask-secretsflag that hides secret_key and database_url in output. - Add a
diffsubcommand that shows which values differ from defaults.
Break it (required) — Core¶
- Set
APP_PORT=notanumberas an environment variable — what happens? - Pass a config file with an unknown key — is it ignored or does it crash?
- Set
portto -1 in the config — doesvalidatecatch it?
Fix it (required) — Core¶
- Add type coercion error handling with clear messages.
- Warn about unknown config keys instead of ignoring them silently.
- Ensure
validate_configcatches all edge cases (negative values, etc.).
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why do configs need precedence (defaults < file < env < CLI)?
- How does
os.environwork and what are environment variables? - What is type coercion and why is it needed for env/CLI string values?
- How does
monkeypatch.setenvwork in pytest?
Mastery check¶
You can move on when you can:
- load configuration from multiple sources with precedence,
- coerce string values to typed Python values,
- validate configuration for common issues,
- test environment variable handling with monkeypatch.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|