![]() |
|
|
Ваша MP3 библиотека Корана |
|
|
|
|
|
# Sensitive or machine-specific overrides DATABASE_USER=local_admin DATABASE_PASSWORD=super_secret_password_123 API_KEY=python_local_dev_token_xyz Use code with caution. Step 3: Add to .gitignore
In modern Python development, especially when using tools like python-dotenv , developers use multiple files to separate configuration from code:
To implement this hierarchy in a Python script, use the popular library python-dotenv on PyPI. It offers native support for loading multiple configuration files sequentially. 1. Install Dependencies .env.python.local
: It is strictly for the developer's personal machine.
# Access environment variables db_host = os.getenv('DB_HOST') db_port = os.getenv('DB_PORT') db_user = os.getenv('DB_USER') db_password = os.getenv('DB_PASSWORD') This file is never committed to version control
if env_name: env_specific = project_root / f".env.python.env_name" load_dotenv(env_specific, override=False)
Next, implement the loading logic in your main entry point script (e.g., main.py or config.py ): When testing integrations locally
: Machine-specific variables used exclusively for local debugging and overrides. This file is never committed to version control.
: Environment-specific settings. .env.local : Generic local overrides.
When testing integrations locally, you may want to toggle specific features off or redirect microservice API calls to a localhost mock server. Isolating these toggles within a local environment file ensures you do not inadvertently disable features for the rest of your development team. Setting Up .env.python.local in Python Projects