Create safe .example files from secret config files by masking sensitive values
Project description
mask-env
Note: PyPI and Python version badges will appear after the first release is published to PyPI.
Create safe example files from secret files in multiple formats by replacing all secret-looking values with human-readable placeholders.
Supports: .env, .JSON, .YAML, .INI/CFG/CONF, .properties, .TOML, and .key/certificate files.
Features
- 🔒 Automatic secret detection using heuristics (API keys, tokens, passwords, etc.)
- 📝 Preserves formatting (comments, blank lines, inline comments, export statements)
- 🚀 Fast and efficient - handles thousands of environment variables
- 🛡️ Never logs secrets - safe for production use
- 📦 Zero dependencies - uses only Python standard library
- 🎯 Simple CLI - one command to generate safe examples
Installation
pip install mask-env
Optional extras (enable parsers for additional formats):
# YAML support
pip install "mask-env[yaml]"
# TOML support (Python < 3.11 uses tomli)
pip install "mask-env[toml]"
# Everything
pip install "mask-env[yaml,toml]"
Usage
Basic Usage
# Reads .env and creates .env.example
mask-env
# Works with any supported format (auto-detected)
mask-env config.json # Creates config.json.example
mask-env secrets.yaml # Creates secrets.yaml.example
mask-env config.ini # Creates config.ini.example
mask-env application.properties # Creates application.properties.example
# Specify custom output file
mask-env .env -o .env.example
mask-env config.json -o config.safe.json
CLI Options
usage: mask-env [-h] [-o OUTPUT] [input]
Create safe .env.example files from .env files
positional arguments:
input Input .env file path (default: .env)
options:
-h, --help show this help message and exit
-o, --output OUTPUT Output file path (default: input_path + ".example")
Supported Formats
- .env files -
.env,.env.*(fully supported) - JSON -
config.json,credentials.json, etc. (requires stdlib only) - YAML -
config.yaml,secrets.yaml,docker-compose.yml(requirespyyamlpackage) - INI/CFG/CONF -
config.ini,settings.cfg,app.conf(fully supported) - .properties -
application.properties,gradle.properties(fully supported) - TOML -
pyproject.toml,config.toml(requirestomliortomlpackage) - Key/Certificate files -
.pem,.key,.crt,.p12,.pfx(fully supported)
What Gets Replaced?
The tool detects secrets using multiple heuristics:
-
Key name patterns: Keys containing
KEY,SECRET,TOKEN,PASSWORD,PASS,API_KEY,PRIVATE,CREDENTIAL,AUTH,ACCESS_KEY,SECRET_KEY -
Value characteristics:
- Long random strings (12+ characters, high entropy)
- Connection strings with embedded passwords
- Private key blocks (
BEGIN PRIVATE KEY)
-
Safe values preserved:
- URLs, file paths, email addresses
- Short values, obvious non-secrets
Python API
from mask_env import process_file
# Works with any supported format (auto-detected)
secrets_replaced = process_file('config.json')
secrets_replaced = process_file('secrets.yaml')
secrets_replaced = process_file('.env')
# Custom input and output
secrets_replaced = process_file('input.json', 'output.safe.json')
# For .env files specifically, you can also use:
from mask_env import create_safe_example
secrets_replaced = create_safe_example('.env')
Requirements
- Python 3.7+
- Optional dependencies (for extended format support):
pyyaml- for YAML file support:pip install pyyamltomliortoml- for TOML file support:pip install tomli
Note: Core functionality (.env, JSON, INI, .properties, key files) works with zero dependencies using only Python standard library.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Links
- PyPI:
https://pypi.org/project/mask-env/ - Source:
https://github.com/VishApp/mask-env - Issues:
https://github.com/VishApp/mask-env/issues
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 mask_env-1.0.0.tar.gz.
File metadata
- Download URL: mask_env-1.0.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8315d96c124703bc682011279e2b96aa94970596ce9b76a9cd2f67156bbc2ced
|
|
| MD5 |
a6994e730210e728364f93f8a1f928a5
|
|
| BLAKE2b-256 |
eb11bf21aec8b71fe6f9020bdcc4886b6f5cd43132cef7b79934dcb0612595bc
|
File details
Details for the file mask_env-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mask_env-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
192c2a45bab478dfff2efbc6b32e672d9bee598d77dc2595dc4bd25f0a588d74
|
|
| MD5 |
5c8245a6df14209f034541d6f97e157b
|
|
| BLAKE2b-256 |
75fc699f39772b25c33d22e177229a144ebf72f2ce7643fb7c720d745bfef604
|