Skip to main content

Environment file generator with template + override support. Born from UpbrosAI team's production experience.

Project description

env-patch

PyPI version Python 3.8+ License: MIT

Environment file generator with template + override support.

Born from UpbrosAI team's production experience building cross-border e-commerce and AI-powered applications.

中文文档

Why env-patch?

Most dotenv libraries load .env files at runtime. But what if you need to:

  • Build Docker images with baked-in environment configs?
  • Deploy to platforms that don't support dotenv loading?
  • Debug configuration by seeing exactly what values will be used?

env-patch generates a single .env file at build time by merging your template with environment-specific overrides.

Installation

# Using pip
pip install env-patch

# Using uv (recommended)
uv add env-patch

# Using pipx (for global CLI)
pipx install env-patch

Quick Start

# 1. Create your template
cat > .env.example << 'EOF'
DATABASE_URL=postgres://localhost/myapp
REDIS_URL=redis://localhost:6379
DEBUG=false
EOF

# 2. Create environment-specific config
cat > .env.development << 'EOF'
DEBUG=true
EOF

# 3. Generate .env
env-patch -e development

# Result: .env contains DATABASE_URL, REDIS_URL from template + DEBUG=true from override

File Hierarchy

.env.example              # Template (git tracked)
.env.development          # Development config (git tracked)
.env.development.local    # Local overrides (git ignored)
.env                      # Output (git ignored)

Priority (highest to lowest):

  1. .env.{env}.local - Personal machine-specific overrides
  2. .env.{env} - Environment-specific config
  3. .env.example - Default template values

Usage

Basic Usage

# Auto-detect env file (when only one exists)
env-patch

# Specify environment
env-patch -e development
env-patch -e production
env-patch -e staging

Aliases

Built-in aliases for common environments:

env-patch -e dev    # Same as: env-patch -e development
env-patch -e prod   # Same as: env-patch -e production
env-patch -e stage  # Same as: env-patch -e staging

Custom Environments

# Use any environment name
env-patch -e uai-prod       # Uses .env.uai-prod
env-patch -e feature-auth   # Uses .env.feature-auth

Options

env-patch -e <env>           # Environment name
env-patch -t <file>          # Template file (default: .env.example)
env-patch -o <file>          # Output file (default: .env)
env-patch -s                 # Strict mode: error on unknown keys
env-patch -h                 # Show help
env-patch -v                 # Show version

Local Overrides

Create .env.{env}.local for machine-specific settings that shouldn't be committed:

# .env.development.local (git ignored)
DATABASE_URL=postgres://localhost:5433/myapp_local
API_KEY=my-personal-api-key

These values override both the template and the environment config.

Recommended .gitignore

# Output file
.env

# Local overrides
.env.local
.env.*.local

# Keep these tracked
!.env.example

CI/CD Integration

# GitHub Actions example
steps:
  - name: Generate .env for production
    run: |
      pip install env-patch
      env-patch -e production
# Dockerfile example
FROM python:3.12
RUN pip install env-patch
COPY .env.example .env.production ./
RUN env-patch -e production

Why Not Just Use dotenv-flow?

Feature env-patch dotenv-flow
When it runs Build time Runtime
Output Single .env file In-memory only
Docker builds Easy Requires workaround
Debug visibility Check .env directly Add logging
Language Python CLI Node.js library

Use env-patch when you need a generated file. Use dotenv-flow when you want runtime loading.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE for details.


Made with love by UpbrosAI Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

env_patch-1.0.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

env_patch-1.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file env_patch-1.0.0.tar.gz.

File metadata

  • Download URL: env_patch-1.0.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for env_patch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3435bd3b06af55bb1960079bf6432be35cb85b6ff8ff16ee4057515dc610e481
MD5 47f7f95e7af19a27f91ed4db67626859
BLAKE2b-256 8865711bb24f33d26f76e9fc350252e57ef3a4a389aacb1b21fdcba9c6de1637

See more details on using hashes here.

Provenance

The following attestation bundles were made for env_patch-1.0.0.tar.gz:

Publisher: publish.yml on upbrosai/env-patch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file env_patch-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: env_patch-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for env_patch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d7cd449e451d451746f1fa4463d66078fefe9efba6c800507c9cd18bd3206fb
MD5 a201ab377e8338ad846f32718e0bd460
BLAKE2b-256 ac22fc26602aee419ae2fea28bc58799f4d727675d2d5e914dd659b97ca954a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for env_patch-1.0.0-py3-none-any.whl:

Publisher: publish.yml on upbrosai/env-patch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page