Environment file generator with template + override support. Born from UpbrosAI team's production experience.
Project description
env-patch
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):
.env.{env}.local- Personal machine-specific overrides.env.{env}- Environment-specific config.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3435bd3b06af55bb1960079bf6432be35cb85b6ff8ff16ee4057515dc610e481
|
|
| MD5 |
47f7f95e7af19a27f91ed4db67626859
|
|
| BLAKE2b-256 |
8865711bb24f33d26f76e9fc350252e57ef3a4a389aacb1b21fdcba9c6de1637
|
Provenance
The following attestation bundles were made for env_patch-1.0.0.tar.gz:
Publisher:
publish.yml on upbrosai/env-patch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
env_patch-1.0.0.tar.gz -
Subject digest:
3435bd3b06af55bb1960079bf6432be35cb85b6ff8ff16ee4057515dc610e481 - Sigstore transparency entry: 833445019
- Sigstore integration time:
-
Permalink:
upbrosai/env-patch@cb301118c2b1179f400b8c4c45105a2608b54b37 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/upbrosai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cb301118c2b1179f400b8c4c45105a2608b54b37 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d7cd449e451d451746f1fa4463d66078fefe9efba6c800507c9cd18bd3206fb
|
|
| MD5 |
a201ab377e8338ad846f32718e0bd460
|
|
| BLAKE2b-256 |
ac22fc26602aee419ae2fea28bc58799f4d727675d2d5e914dd659b97ca954a4
|
Provenance
The following attestation bundles were made for env_patch-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on upbrosai/env-patch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
env_patch-1.0.0-py3-none-any.whl -
Subject digest:
6d7cd449e451d451746f1fa4463d66078fefe9efba6c800507c9cd18bd3206fb - Sigstore transparency entry: 833445042
- Sigstore integration time:
-
Permalink:
upbrosai/env-patch@cb301118c2b1179f400b8c4c45105a2608b54b37 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/upbrosai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cb301118c2b1179f400b8c4c45105a2608b54b37 -
Trigger Event:
push
-
Statement type: