python-configuration
यह क्या करती है
यह टूल program की settings को व्यवस्थित करने में मदद करता है। पासवर्ड या website के पते जैसी ज़रूरी values को सीधे code में लिखने के बजाय, यह उन्हें environment variables से पढ़ता है, जिससे program ज़्यादा लचीला और सुरक्षित बनता है।
कब इस्तेमाल करें
- ✓नया project शुरू करते समय और उसकी configurations व्यवस्थित करना चाहते हों।
- ✓जब एक ही code को अलग-अलग environments (जैसे development और production) में चलाना हो।
- ✓पासवर्ड और API keys जैसी संवेदनशील जानकारी सुरक्षित तरीके से संभालने के लिए।
Skill का लिंक
https://github.com/wshobson/agents/blob/main/plugins/python-development/skills/python-configuration/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं अपने application में database और API keys के लिए environment variables का इस्तेमाल कैसे सेट करूं?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह Pydantic नाम की library से तय करता है कि कौन-सी settings चाहिए और उनका प्रकार (text, number आदि) क्या है। program शुरू होते समय यह जांचता है कि सभी ज़रूरी settings environment variables में दी गई हैं या नहीं, और उन्हें लोड कर लेता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Python Configuration Management
Externalize configuration from code using environment variables and typed settings. Well-managed configuration enables the same code to run in any environment without modification.
When to Use This Skill
- Setting up a new project's configuration system
- Migrating from hardcoded values to environment variables
- Implementing pydantic-settings for typed configuration
- Managing secrets and sensitive values
- Creating environment-specific settings (dev/staging/prod)
- Validating configuration at application startup
Core Concepts
1. Externalized Configuration
All environment-specific values (URLs, secrets, feature flags) come from environment variables, not code.
2. Typed Settings
Parse and validate configuration into typed objects at startup, not scattered throughout code.
3. Fail Fast
Validate all required configuration at application boot. Missing config should crash immediately with a clear message.
4. Sensible Defaults
Provide reasonable defaults for local development while requiring explicit values for sensitive settings.
Quick Start
from pydantic_settings import BaseSettings
from pydantic import Field
class Settings(BaseSettings):
database_url: str = Field(alias="DATABASE_URL")
api_key: str = Field(alias="API_KEY")
debug: bool = Field(default=False, alias="DEBUG")
settings = Settings() # Loads from environment
Fundamental Patterns
Pattern 1: Typed Settings with Pydantic
Create a central settings class that loads and validates all configuration.
from pydantic_settings import BaseSettings
from pydantic import Field, PostgresDsn, ValidationError
import sys
class Settings(BaseSettings):
"""Application configuration loaded from environment variables."""
# Database
db_host: str = Field(alias="DB_HOST")
db_port: int = Field(default=5432, alias="DB_PORT")
db_name: str = Field(alias="DB_NAME")
db_user: str = Field(alias="DB_USER")
db_password: str = Field(alias="DB_PASSWORD")
# Redis
redis_url: str = Field(default="redis://localhost:6379", alias="REDIS_URL")
# API Keys
api_secret_key: str = Field(alias="API_SECRET_KEY")
# Feature flags
enable_new_feature: bool = Field(default=False, alias="ENABLE_NEW_FEATURE")
model_config = {
"env_file": ".env",
"env_file_encoding": "utf-8",
}
# Create singleton instance at module load
try:
settings = Settings()
except ValidationError as e:
print(f"Configuration error:\n{e}")
sys.exit(1)
Import settings throughout your application:
from myapp.config import settings
def get_database_connection():
return connect(
host=settings.db_host,
port=settings.db_port,
database=settings.db_name,
)
Pattern 2: Fail Fast on Missing Configuration
Required settings should crash the application immediately with a clear error.
from pydantic_settings import BaseSettings
from pydantic import Field, ValidationError
import sys
class Settings(BaseSettings):
# Required - no default means it must be set
api_key: str = Field(alias="API_KEY")
database_url: str = Field(alias="DATABASE_URL")
# Optional with defaults
log_level: str = Field(default="INFO", alias="LOG_LEVEL")
try:
settings = Settings()
except ValidationError as e:
print("=" * 60)
print("CONFIGURATION ERROR")
print("=" * 60)
for error in e.errors():
field = error["loc"][0]
print(f" - {field}: {error['msg']}")
print("\nPlease set the required environment variables.")
sys.exit(1)
A clear error at startup is better than a cryptic None failure mid-request.
Pattern 3: Local Development Defaults
Provide sensible defaults for local development while requiring explicit values for secrets.
class Settings(BaseSettings):
# Has local default, but prod will override
db_host: str = Field(default="localhost", alias="DB_HOST")
db_port: int = Field(default=5432, alias="DB_PORT")
# Always required - no default for secrets
db_password: str = Field(alias="DB_PASSWORD")
api_secret_key: str = Field(alias="API_SECRET_KEY")
# Development convenience
debug: bool = Field(default=False, alias="DEBUG")
model_config = {"env_file": ".env"}
Create a .env file for local development (never commit this):
# .env (add to .gitignore)
…
अक्सर पूछे जाने वाले सवाल
पासवर्ड सीधे code में क्यों न रखें?
पासवर्ड और दूसरी संवेदनशील जानकारी code में सीधे रखना असुरक्षित है। अगर code शेयर हो जाए या गलती से सामने आ जाए, तो यह जानकारी चोरी हो सकती है। Environment variables इस जानकारी को मुख्य code से बाहर रखते हैं।
'environment variables' क्या होते हैं?
ये वे values हैं जो आप उस operating system में सेट करते हैं जहां program चल रहा है। Program इन्हें बिना code में लिखे पढ़ सकता है। जैसे आप `DATABASE_URL` नाम का variable अपने database के पते के साथ सेट कर सकते हैं।
अगर कोई ज़रूरी configuration न हो तो क्या होगा?
Program शुरू में ही रुक जाएगा और साफ संदेश दिखाएगा कि कौन-सी configuration नहीं है। यह बाद में किसी उलझन भरी गड़बड़ी से बेहतर है।
जानकारी
लेखक का मूल विवरण
Python configuration management via environment variables and typed settings. Use when externalizing config, setting up pydantic-settings, managing secrets, or implementing environment-specific behavior.
repo: wshobson/agents
लोकप्रियता
- GitHub स्टार
- 41k
- रैंकिंग में स्थान
- #6759
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
screen-reader-testing
41kआपके एजेंट को screen readers का इस्तेमाल करके वेबसाइटों की जांच करने देता है, ताकि यह पक्का हो सके कि वे accessible हैं।
wcag-audit-patterns
41kआपके एजेंट को वेबसाइटों का accessibility audit करने और WCAG guidelines के हिसाब से समस्याएं ठीक करने में मदद करता है।
multi-reviewer-patterns
41kआपके एजेंट को कई code reviews को एक साथ चलाने देता है। यह एक जैसे findings हटाता है और सारी रिपोर्ट को एक जगह जोड़ता है।
parallel-debugging
41kआपके एजेंट को parallel जांच के साथ जटिल समस्याओं को debug करने और root cause analysis में मदद करता है।
मिलती-जुलती skills
api-connector-builder
280kयह आपके एजेंट को मौजूदा pattern के हिसाब से नए API connections बनाने देता है। जब बिना कोई नया तरीका बनाए एक और integration जोड़ना हो, तब इसका इस्तेमाल करें।
api-design
280kयह आपके एजेंट को best practices के हिसाब से REST APIs डिज़ाइन करने में मदद करता है। यह तय करने में काम आता है कि APIs आपस में कैसे बात करें, errors कैसे दिखें, और data को कैसे व्यवस्थित करें।
backend-patterns
280kआपके एजेंट को server-side architecture patterns और database optimization में मदद करता है। server पर चलने वाला code बनाने या review करने के लिए उपयोगी है।