ajyadav013/claude-kit/configargparse-yaml-env-layering
Claude Code and agent skill by ajyadav013/claude-kit
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Three-layer service config — YAML defaults, configargparse CLI/env override, Pydantic BaseSettings singleton. Use for Python services with multiple runtime modes and precedence-ordered config sources.
Install
npx vskill@latest install ajyadav013/claude-kit/configargparse-yaml-env-layeringSKILL.md
The same SKILL.md was published earlier as ajyadav013/claude-kit/configargparse-yaml-env-layering.
Standardize service configuration using a three-layer hierarchy with YAML defaults, configargparse CLI/env merging, and a Pydantic BaseSettings singleton.
When to use
- Setting up configuration for a new Python backend service or microservice
- Building services with multiple runtime modes (server, consumer, temporal_worker, cron)
- Implementing precedence-ordered configuration (YAML defaults < environment variables < CLI arguments)
- Migrating from flat .env files to structured, type-safe configuration
- Configuring services that need different entrypoints based on MODE environment variable
- Setting up mode-specific dispatch via entrypoint.py pattern
- Building container-deployable services that override defaults via environment variables
- Needing a module-level config singleton accessible throughout the codebase
- Implementing auto-prefixed environment variable parsing for all config keys
- Setting up services with database, Kafka, Temporal, Redis, and other infrastructure dependencies
Core conventions
- Three-layer config hierarchy: (1)
config/default.yamlcontains structured defaults for all environments; (2)configargparse.ArgParserwithauto_env_var_prefix=""merges CLI args and env vars over YAML; (3)config/docker_config.pywraps parsed args in PydanticBaseSettingsand exports a module-level singletonloaded_config. Precedence: YAML < env vars < CLI args.
- YAML defaults in `config/default.yaml`: define all config keys with development-friendly defaults. Structure groups logically (Environment, Mode, Database, Kafka, Temporal, Sentry, etc.). Use scalar types (string, int, bool). Common sections:
ENV,MODE,DEBUG,POSTGRES_*,REDIS_*,KAFKA_BROKER_LIST,TEMPORAL_HOST,TEMPORAL_NAMESPACE,GOOGLE_CLOUD_PROJECT. Never commit production secrets; use placeholder values.
- configargparse parser in `config/config_parser.py`: create
parser = configargparse.ArgParser(config_file_parser_class=configargparse.YAMLConfigFileParser, default_config_files=[default_config_file], auto_env_var_prefix=""). Add each config key viaparser.add("--KEY_NAME", help="..."). The emptyauto_env_var_prefixmeans every--KEY_NAMEcan be set viaKEY_NAMEenv var. Parse withargument_options = parser.parse_known_args(sys.argv)and expose namespace asdocker_args = argument_options[0].
- Pydantic BaseSettings wrapper in `config/docker_config.py`: define
class Settings(BaseSettings)with fieldsKEY: type = args.KEY_NAMEfor each config key. Use type annotations (str, int, bool) for validation. Importfrom config.config_parser import docker_argsand alias asargs = docker_args. Export singletonloaded_config = Settings()at module level. All application code imports this singleton:from config.docker_config import loaded_config.
- MODE-based entrypoint dispatch:
entrypoint.pyimportsloaded_configand definesmode_actions = {"server": start_server, "consumer": start_consumer, "temporal_worker": start_temporal_worker, "cron": start_cron}. Main block:if __name__ == "__main__": action = mode_actions.get(loaded_config.MODE); if action: action(). Each mode function delegates to the appropriate main (e.g.,app.main.main,services.kafka.consumer.main,services.temporal.run_workers.worker_main).
- Common MODE values:
server(FastAPI app),consumer(Kafka consumer),temporal_worker(Temporal worker),cron(scheduled job),webhook_server,test. Worker modes often readloaded_config.WORKER_MODEorloaded_config.CONSUMER_NAMEfor further dispatch.
- docker_args namespace access pattern: in
docker_config.py, useargs.KEY_NAMEto access parsed config. For optional keys with defaults, usegetattr(args, 'KEY_NAME', 'default_value'). Example:SERVICE_NAME: str = getattr(args, 'SERVICE_NAME', 'my-service').
- Import singleton everywhere: application code never re-parses config. Always
from config.docker_config import loaded_configand access fields asloaded_config.DATABASE_URL,loaded_config.MODE, etc. The singleton is initialized once at module import time.
- Type-safe config access: Pydantic validates types at
loaded_config = Settings()instantiation. If a boolean env var is set to a non-boolean string, instantiation fails. Use explicit type coercion in parser if needed (parser.add("--DEBUG", type=bool, ...)).
- Optional proxy settings layer: some services add a
packages/common/settings.pythat wrapsloaded_configin domain-specific properties. Example:class Settingswith@property def database_url(self) -> str: return loaded_config.DATABASE_URL. This is optional; directloaded_configaccess is more common.
- No .env file dependency: configargparse's
auto_env_var_prefix=""makes .env files unnecessary. Container orchestration (Docker Compose, Kubernetes) injects env vars directly. YAML provides local defaults. Never usepython-dotenv.
- Config file location convention:
config/directory at service root containsconfig_parser.py,default.yaml,docker_config.py. Some repos useconfig/docker_config.py, othersconfig/settings.py, but the pattern is identical.
- Temporal-safe imports: if using Temporal workflows, wrap heavyweight imports in
with workflow.unsafe.imports_passed_through():to prevent serialization issues. Example: HTTP clients, BigQuery utils.
- Common config keys:
ENV(development/staging/production),MODE(server/consumer/temporal_worker/cron),DEBUG(bool),POSTGRES_*_READ_WRITE(database URL),REDIS_*_READ_WRITE(Redis URL),KAFKA_BROKER_LIST,TEMPORAL_HOST,TEMPORAL_NAMESPACE,GOOGLE_CLOUD_PROJECT,SENTRY_DSN,ENABLE_SENTRY,K8S_POD_NAME/K8S_POD_NAMESPACE/K8S_NODE_NAME(injected by Kubernetes).
- Contrast with plain .env loading: unlike
python-dotenv, this pattern supports CLI arg override, YAML structure, type validation, and auto env-var discovery without explicit.envfile. Cross-referencepydantic-schema-patternsfor BaseSettings usage andbackend-repo-architecturefor service structure.
Skeleton / example
Anti-patterns to avoid
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/configargparse-yaml-env-layering/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ajyadav013/claude-kit/configargparse-yaml-env-layering)