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-dsl
# or
uv add envschema-dsl

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.1.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.1-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: envschema_dsl-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e15411c3bd490c57af4a41cfbacfe929b861239c305624b767882b6b7abf8c85
MD5 f68ee54628a7c9332faa79434fd30cfd
BLAKE2b-256 8eff8ab3c45e9d559280bea85c5477fff03b8ad800d46cb01845aa014eb3ec9a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: envschema_dsl-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c029fc96583e8cf5871b796e1672a3415ff2505d3a0a07a5e3a2147cb7d6f467
MD5 8d8225d85923cc0ed1c027c1499a2fac
BLAKE2b-256 22b55679f74f007ffaad3783618cce1f5308db5dcce24aee64ca63e368b47013

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