Skip to main content

mask-env

PyPI version Python versions License: MIT

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 (requires pyyaml package)
  • INI/CFG/CONF - config.ini, settings.cfg, app.conf (fully supported)
  • .properties - application.properties, gradle.properties (fully supported)
  • TOML - pyproject.toml, config.toml (requires tomli or toml package)
  • Key/Certificate files - .pem, .key, .crt, .p12, .pfx (fully supported)

What Gets Replaced?

The tool detects secrets using multiple heuristics:

  1. Key name patterns: Keys containing KEY, SECRET, TOKEN, PASSWORD, PASS, API_KEY, PRIVATE, CREDENTIAL, AUTH, ACCESS_KEY, SECRET_KEY

  2. Value characteristics:

    • Long random strings (12+ characters, high entropy)
    • Connection strings with embedded passwords
    • Private key blocks (BEGIN PRIVATE KEY)
  3. 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 pyyaml
    • tomli or toml - 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.

  • PyPI: https://pypi.org/project/mask-env/
  • Source: https://github.com/VishApp/mask-env
  • Issues: https://github.com/VishApp/mask-env/issues

Metadata

Release files for mask-env 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mask-env 1.0.0
File Size Uploaded Provenance Actions
mask_env-1.0.0.tar.gz 14.0 kB Without provenance Details for mask_env-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mask-env 1.0.0
File Interpreter ABI Platform Actions
mask_env-1.0.0-py3-none-any.whl Python 3 none any Details for mask_env-1.0.0-py3-none-any.whl

Total release size: 27.5 kB

Release files / mask_env-1.0.0.tar.gz

Download URL mask_env-1.0.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8315d96c124703bc682011279e2b96aa94970596ce9b76a9cd2f67156bbc2ced
BLAKE2b-256 checksum
How to use checksums
eb11bf21aec8b71fe6f9020bdcc4886b6f5cd43132cef7b79934dcb0612595bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / mask_env-1.0.0-py3-none-any.whl

Download URL mask_env-1.0.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
192c2a45bab478dfff2efbc6b32e672d9bee598d77dc2595dc4bd25f0a588d74
BLAKE2b-256 checksum
How to use checksums
75fc699f39772b25c33d22e177229a144ebf72f2ce7643fb7c720d745bfef604
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Security for mask-env 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page