Documentation
🚀 Quick Start Guide
Go from a chaotic environment to a single Environment Contract — documented, validated, and compiled into typed code — in less than 5 minutes. This guide will walk you through the essential workflow.
🎬 Prefer visual learning? Check out the Features & Examples page for real-life walkthroughs with before/after scenarios and animations.
1. Install EnvShield
You'll need Python 3.10 or newer. Install EnvShield directly from PyPI — it's a standalone CLI, no dependencies on your project's stack.
pip install envshield
2. Initialize Your Project (Two Paths)
Choose the path that fits your project. Both create a schema (`env.schema.toml`) that becomes your single source of truth.
# Scaffolds a schema from your framework (Next.js, Django, Flask, etc.)
# Also creates a git hook and updates .gitignore
envshield init
# Reads your existing .env file and auto-generates 90% of the schema
# The tool detects secrets, suggests defaults, and saves you manual work
envshield import .env.production --interactive
💡 Real example: Have a 50-var .env file? EnvShield detects 45 of them correctly, asks you about the tricky ones, and generates your schema in 2 minutes instead of an hour.
3. Curate Your Schema (The Contract)
Open the newly created `env.schema.toml`. This is your Environment Contract — the single source of truth for all configuration. Review each variable, add human-readable descriptions, and mark which ones are secrets. This is the ONLY file you'll hand-edit.
[DATABASE_URL]
description = "The full connection string for the database."
secret = true
[LOG_LEVEL]
description = "Controls the application's log verbosity (DEBUG, INFO, WARNING, ERROR)"
secret = false
defaultValue = "info"
[STRIPE_API_KEY]
description = "Stripe API secret for payment processing"
secret = true
💡 Why this matters: This schema now drives everything — your `.env.example` generation, your typed config code, your validation, your onboarding wizard. Once it's right, everything stays in sync automatically.
4. Sync Documentation & Setup Your Environment
Now generate your `.env.example` (documentation) from the schema, and create your local `.env` file interactively. EnvShield will prompt you for each variable, hide secrets as you type, and validate everything.
# Generate .env.example from your schema (docs stay in sync)
envshield schema sync
# Interactively create your local .env (you'll be prompted for each var)
envshield setup
# Or create a different env file:
envshield setup .env.local
💡 What just happened: Your `.env.example` was regenerated from the schema (never stale again), and you created your local `.env` without any manual copy-paste or guessing about which vars are secrets.
5. You're All Set!
Your environment is now secure and documented. The Git pre-commit hook is active and will scan for secrets before each commit. Your configuration is guaranteed to be in sync with your schema. You're ready to go!
# Verify everything is in order
envshield doctor
# Now build something amazing!
python app.py # or npm start, etc.
6. (Optional) Compile Your Contract Into Code
Turn the schema into the actual config your app
imports — typed, validated, and with secrets
masked by default. Auto-detected for your
stack, or set explicitly with
--lang.
# Python (pydantic-settings)
envshield generate --lang python
# TypeScript (zod)
envshield generate --lang typescript
💡 Core Concepts: The Environment Contract
EnvShield treats configuration as a **contract** — a formal agreement between your schema and your application. Understanding these three artifacts is key to mastering this workflow. Only the first one is hand-written — the other two are always generated from it.
- The Schema (`env.schema.toml`): This file is the **Environment Contract** itself. It's the undisputed source of truth, defining every variable your project needs, what it does, whether it's a secret, and if it has a default value. It lives in your repository and is version-controlled like the rest of your code.
- The Example File (`.env.example`): This file is the **human-readable documentation**. It's a build artifact that is automatically generated from your schema via the `schema sync` command. You never edit this file by hand; you commit it so that anyone browsing your repository can quickly understand the configuration requirements without needing the tool installed.
- The Generated Config Module: This is the **machine-readable enforcement** of the contract. Running `envshield generate` compiles the schema into real, importable `pydantic-settings` (Python) or `zod` (TypeScript) code — your application reads its configuration through this typed, validated module instead of raw `os.getenv`/`process.env` calls.
🎯 Why EnvShield is Different
EnvShield is the only configuration tool that approaches the problem as a contract across multiple services. Here's how we compare to alternatives:
| Feature | EnvShield | Gitleaks | dotenvx | Infisical |
|---|---|---|---|---|
| Schema-driven configuration | ✅ Unique | ❌ | ❌ | ❌ |
| Multi-service support | ✅ Built-in | ❌ | ❌ | ❌ |
| Typed config code generation | ✅ Unique | ❌ | ❌ | ❌ |
| Interactive onboarding | ✅ | ❌ | ❌ | ✅ Cloud-only |
| Works offline | ✅ | ✅ | ✅ | ❌ |
The bottom line: Other tools solve pieces of the configuration puzzle. Gitleaks detects secrets. dotenvx encrypts files. Infisical stores secrets in the cloud. But EnvShield solves the whole problem — schema definition, multi-service orchestration, typed code generation, and secret scanning — all in one local-first CLI.
📖 A-to-Z Command Reference
🏗️ init
The "zero-to-hero" command. Run this first in a new project to scaffold a complete, best-practice configuration foundation.
What it does:
- Intelligently inspects your project to detect the framework (e.g., Next.js, Django).
- Creates an `env.schema.toml` file with smart defaults for that framework.
- Creates a simple `envshield.yml` configuration file.
- Safely updates your `.gitignore` file with necessary patterns.
- Automatically installs the Git pre-commit hook for proactive security.
Flags:
--force or -f: Allows
`init` to overwrite existing EnvShield files. It
will always ask for a final confirmation before
proceeding.
Use Case
You're starting a new Django project. You run `envshield init`. The tool detects Django, creates a schema with `SECRET_KEY` and `DATABASE_URL`, updates your `.gitignore`, and installs the security hook. Your project is set up for success in one command.
🚚 import
The "get started yesterday" command. This is the fastest way to adopt EnvShield for an existing project with a large, messy `.env` file.
What it does:
- Reads an existing `.env` file (like `.env.production`).
- Intelligently analyzes each variable's key and value.
- Automatically marks known secrets (API keys, tokens) using its built-in scanner logic.
- Suggests default values for common variables (like `DEBUG` or `PORT`).
- Generates a complete `env.schema.toml` file for you.
Arguments & Flags:
-
<file>: (Required) The path to the `.env` file you want to import. -
--outputor-o: Specify a different output path for the schema file (default: `env.schema.toml`). -
--forceor-f: Allows `import` to overwrite an existing schema file. -
--interactive: Walks you through each variable one by one, letting you confirm if it's a secret and if you want to set a default value.
Use Case
You want to adopt EnvShield for a 2-year-old project. You run the command:
envshield import .env --interactive
The tool guides you through all 50 variables, correctly guessing 45 of them, and generates a perfect schema file in two minutes instead of an hour of manual work.
💪 scan
Your project's personal bodyguard. It scans files for hardcoded secrets and undeclared environment variables used in your code.
Arguments & Flags:
-
[PATHS]...: The specific files or directories to scan. If you don't provide a path, it scans the current directory. -
--staged: Scans only the files you've staged for your next Git commit. This is the heart of the pre-commit hook. -
--config <file>: Use a different `envshield.yml` for this specific scan. -
--exclude <pattern>: A glob pattern to exclude from this specific scan. Can be used multiple times.
Use Case
Your pre-commit hook is blocking a commit because of a secret in a test file. You realize you forgot to add an exclusion rule. You can add it to `envshield.yml` to fix it permanently, or use a one-off command to bypass it for now:
git commit -m "My commit" --no-verify # Bypass the hook for now
envshield scan . --exclude "**/tests/*"
🛑 install-hook
Manually installs the Git pre-commit hook if you skipped it during `init` or if it was removed.
What it does:
Creates (or overwrites) a `pre-commit` script in your `.git/hooks/` directory that runs `envshield scan --staged`.
Use Case
You've added `envshield` to a project that already had a different pre-commit hook. After you manually merge the two scripts, you can run `envshield install-hook --force` to create the final, combined hook.
📚 schema
The `schema` command is a subcommand with one action: `sync`. It's your primary tool for keeping your project's documentation (`.env.example`) perfectly in sync with your schema.
Usage
envshield schema sync
Use Case
You add a new `REDIS_URL` variable to your `env.schema.toml`. Before you commit, you run `envshield schema sync`. The `.env.example` is instantly and correctly updated with the new variable and its description, ready to be committed.
✅ check
The "is it plugged in?" command for your local setup. It validates a local environment file against the official contract in `env.schema.toml`.
What it does:
It reports missing variables (that don't have a default) and extra variables that are not in the schema, helping you find configuration errors before they cause runtime bugs.
Use Case
Your app fails to start after a teammate's PR. You run the command:
envshield check .env.local
The tool reports `Missing in Local: NEW_SERVICE_API_KEY`, instantly telling you what's wrong.
🪄 setup
A taste of the automated onboarding magic. This is the perfect command for getting started on a project.
What it does:
It reads your `.env.example`, finds any variables that are empty, and interactively prompts you for their values. It then generates your first local `.env` file.
Use Case
You just cloned a new project. You run `envshield setup`. The tool asks you for the `DATABASE_URL` and `STRIPE_API_KEY`, then generates your fully-populated `.env` file. You are ready to run the project in minutes.
🩺 doctor
The "turn it off and on again" command for your entire configuration. It runs a comprehensive suite of health checks on your project's `envshield` setup.
What it does:
- Checks that your `envshield.yml` and `env.schema.toml` files exist and are valid.
- Validates your local `.env` file against the schema.
- Ensures your `.env.example` file is in sync with the schema.
- Verifies that the security hook is installed and active.
Flags:
--fix: The magic wand. If the doctor
finds a problem, it will interactively ask you if
you want to fix it automatically.
Use Case
Something just feels wrong with your setup. You run `envshield doctor`. It reports that your `.env.example` is out of date and the Git hook is missing. You run `envshield doctor --fix`, answer "Yes" to both prompts, and the tool fixes everything for you.
🧬 generate
The command that turns your contract into code. It compiles `env.schema.toml` into a typed, validated config module — no more raw `os.getenv()` / `process.env` calls scattered through your codebase, and no more secrets that can accidentally end up in a log line.
What it does:
- Renders every variable in your schema into a real, importable module: `pydantic-settings` for Python, or a `zod`-validated module for TypeScript.
- Infers each variable's type (`str`, `int`, `bool` / `string`, `number`, `boolean`) from its `defaultValue`. Variables with no default become required fields — the module raises a validation error at import time if they're missing.
- Wraps every `secret = true` variable in a masked type (`SecretStr` in Python, a local `Secret<T>` wrapper in TypeScript) so it can't accidentally leak via a `print()`, `console.log`, `JSON.stringify`, or stack trace. You call `.get_secret_value()` / `.value` explicitly to read it.
Arguments & Flags:
-
[output_file]: Where to write the generated module. Defaults to `config.py` or `config.ts` depending on the resolved language. -
--langor-l: `python` or `typescript`. If omitted, EnvShield auto-detects from your project the same way `init` does — Next.js, Vite, and Node.js projects default to TypeScript; everything else defaults to Python. -
--forceor-f: Allows `generate` to overwrite an existing output file.
Use Case
Your Next.js app currently reads `process.env.STRIPE_SECRET_KEY` directly in six different files, with no validation that it's actually set. You run:
envshield generate --lang typescript
EnvShield writes `config.ts` with a `zod` schema built from your contract. You replace the six direct `process.env` reads with `import { env } from './config'` — now a missing or malformed variable fails loudly at startup instead of silently at runtime, and `env.STRIPE_SECRET_KEY` prints as `**********` anywhere it's accidentally logged.
⚙️ The `env.schema.toml` File
This file is the heart of your configuration. It's a TOML file where you define every environment variable your project needs. Here's a breakdown of the keys for a variable:
[DATABASE_URL]
# (Required) A human-readable explanation of what this variable is for.
# This is used to generate comments in your .env.example file.
description = "The full connection string for the PostgreSQL database."
# (Required) A boolean that marks the variable as sensitive.
# This will be used by future commands like `onboard` and `audit`.
secret = true
# (Optional) A default value for the variable.
# If a variable has a defaultValue, `envshield check` will not report it as missing.
# It will also be pre-filled in your .env.example file.
defaultValue = "postgres://user:pass@localhost:5432/mydb"
⚙️ The `envshield.yml` File
This file controls the workflow and settings for the EnvShield tool itself.
# The name of your project (used for display purposes).
project_name: my-project
# The version of the config file format.
version: 2.0
# (Required) The path to your schema file.
schema: env.schema.toml
# Global settings for the secret scanner.
secret_scanning:
# A list of file patterns to ignore during scans (e.g., test files).
exclude_files:
- "**/tests/*"
- "**/test/*"
🛣️ Roadmap: The Future is Bright
Phase 1 is the free, powerful foundation. But the journey doesn't end here. Upcoming paid tiers will turn EnvShield into a complete collaboration and automation platform for teams and enterprises.
Phase 1: The Local Guardian (Free, Live Now) ✅
Everything you need for a single developer or small team:
- Schema-driven configuration management
- Multi-service support
- Typed config code generation (Python + TypeScript)
- Interactive onboarding wizard
- Configuration drift detection
- Pre-commit secret scanning
Phase 2: The Team Collaborator (Paid Tier, Coming Soon)
Scale to teams with environment profiles and automation:
- Environment Profiles: Switch between dev/staging/prod configurations with one command.
- Schema Diffing: See exactly what configuration changed between environments.
- Automated Onboarding: Setup command that also runs database migrations, docker compose, and custom scripts.
- Team Collaboration: Securely share secrets with teammates via encrypted links.
- CI/CD Integration: Validate configuration before deployment, inject secrets into pipelines.
Phase 3: The Enterprise System (Paid Tier, Future)
Mission-critical features for large organizations:
- Cloud Secret Vault: Optional centralized backend for teams that need it (not required, everything still works locally).
- Vault Integration: Pull secrets from HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, etc.
- Audit Logs & RBAC: Complete compliance trail of all secret access with role-based access control.
- Policy Engine: Enforce naming conventions, require descriptions, mandate secrets for certain patterns.