Skip to main content

DSL for typed .env files — schema, validation, codegen

Project description

envschema

DSL for typed .env files — schema, validation, codegen.

Install

pip install envschema
# or
uv add envschema

Quick Start

Create a .env.schema file:

# Database
DB_HOST str @required
DB_PORT port = 5432
DB_PASSWORD str @secret @required
DB_NAME str = "myapp"

# App
NODE_ENV enum("development", "production", "test") = "development"
PORT int = 3000 : 0 < x < 65535
DEBUG bool = false
CORS_ORIGIN str[] = "http://localhost:3000"
API_KEY str @required : len(x) >= 32

Validate your .env file:

envschema validate .env.schema --env .env
  ✓ DB_HOST = db.example.com
  ✓ DB_PORT = 5432
  ✓ DB_PASSWORD = ***
  ✓ NODE_ENV = development
  ✓ PORT = 3000
  ✗ API_KEY — validation failed: len(x) >= 32 (x='short')
  ⚠ UNKNOWN_VAR — not defined in schema

Result: 5 OK, 1 errors, 1 warnings

Generate code:

envschema generate .env.schema -t ts          # TypeScript interface
envschema generate .env.schema -t zod         # Zod v4 schema
envschema generate .env.schema -t pydantic    # Pydantic BaseSettings
envschema generate .env.schema -t dataclasses # Python dataclass (no deps)
envschema generate .env.schema -t env-example # .env.example

Features

Types

HOST str = "localhost"            # string
PORT int = 3000                   # integer
RATIO float = 0.5                 # float
DEBUG bool = false                # boolean
API_PORT port = 8080              # port (int 1-65535)
BASE_URL url                      # URL (any scheme://)
ADMIN_EMAIL email                 # email
DATA_DIR path = "/var/data"       # filesystem path
NODE_ENV enum("dev", "prod")      # enum
HOSTS str[]                       # array (comma-separated)

Type inference from defaults — PORT = 3000 is inferred as int.

Decorators

DB_HOST str @required                      # must be set
DB_PASSWORD str @secret @required          # hidden in output
LOG_LEVEL str @description("Logging level") # description

Inline Validation

Python expressions with x as the value:

PORT int = 3000 : 0 < x < 65535
API_KEY str @required : len(x) >= 32
RATE_LIMIT int = 100 : 0 < x < 10000

Block Syntax

For complex variables:

DATABASE_URL {
    type = url
    description = "PostgreSQL connection string"
    @secret
    @required
    validate = "x.startswith('postgres://')"
}

Type Aliases

type LogLevel = enum("error", "warn", "info", "debug")
type ExtendedEnv = NodeEnv + enum("local")

LOG_LEVEL LogLevel = "warn"

Presets

#include <node.js>       # built-in preset (NODE_ENV, PORT, HOST)
#include <vite>          # VITE_* variables
#include "shared.schema" # local file

APP_NAME str = "myapp"
envschema presets list             # list available presets
envschema presets load directus    # download from registry

Wildcard Expansion

AUTH_PROVIDERS str[] = "google,github"

AUTH_{AUTH_PROVIDERS}_DRIVER str @required
AUTH_{AUTH_PROVIDERS}_CLIENT_ID str @secret @required
AUTH_{AUTH_PROVIDERS}_CLIENT_SECRET str @secret @required

Expands to AUTH_GOOGLE_DRIVER, AUTH_GITHUB_DRIVER, etc. Default filter: upper. Custom: {AUTH_PROVIDERS|lower}.

CLI

envschema parse <file>              # parse and display AST
envschema parse <file> --json       # output as JSON
envschema validate <schema> --env <env>  # validate .env against schema
envschema generate <schema> -t <target>  # generate code
envschema generators list           # list available targets
envschema presets list              # list presets
envschema presets load <name>       # download preset
envschema lsp                       # start LSP server (stdio)

VS Code Extension

cd editors/vscode/envschema
npx @vscode/vsce package --allow-missing-repository
cursor --install-extension envschema-0.1.0.vsix

Provides syntax highlighting for .env.schema files.

License

MIT

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

envschema_dsl-0.1.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

envschema_dsl-0.1.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file envschema_dsl-0.1.0.tar.gz.

File metadata

  • Download URL: envschema_dsl-0.1.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for envschema_dsl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 12a13e25a1984be7257f076af46ca6d3d4d6e8cca92e008e78012bb807386de9
MD5 639bfedee92c105f56b7a5776bcde6fc
BLAKE2b-256 5801f017107723185565729e5b13ac7ccf78f469c6f2e1bb8e092e5c508c7a2b

See more details on using hashes here.

File details

Details for the file envschema_dsl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: envschema_dsl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for envschema_dsl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 230e6609f9c18f256b1772494823d3f2fdcfbdd1e871d44014e77a365e192ee3
MD5 e502cee687cb4f39a65123e08ba64623
BLAKE2b-256 000aa23a519c1c11f3c646318fe07782e712ea91dbe30b692a4c86e4d0916763

See more details on using hashes here.

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