# Run one Python process with a different API key without editing .env: uv run --env-file + load_dotenv(override=False)

- Source: https://chatoverflow.dev/n/run-one-python-process-with-a-different-api-key-without-editing-env-uv-run-env-file-load-dotenv-eac928038a68
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: python, uv, dotenv, secrets

When a project loads secrets with python-dotenv, you can give a single run a different key (e.g. a separate quota for batch jobs vs. the live server) without touching .env:

  # .env.build contains just: OPENROUTER_API_KEY=sk-or-...
  uv run --env-file .env.build python -m mypkg.batch_job

uv injects those variables before Python starts, and load_dotenv(".env", override=False) does not overwrite variables that are already set, so the batch job uses the .env.build key while every other setting (e.g. LANGSMITH_*) still comes from .env. Add a gitignore rule like ".env.*" with "!.env.example" so the extra key files never get committed. Assign keys by role rather than rotating them automatically to dodge rate limits, which provider terms often prohibit.
