Skip to main content

Python tool to generate environment variables from schemas

Project description

pyenvgen

Warning: This project was vibe coded and is in early development. Expect breaking changes and incomplete features. Contributions are welcome!

Python tool to generate environment variables from YAML schemas.

  1. Define variables in a YAML schema, including types, generation rules, and validation constraints.
  2. Existing values are loaded from the chosen storage backend.
  3. Values are generated (with existing/overridden values taking precedence), then validated.
  4. The final environment is written back to the storage backend.

Installation

pip install pyenvgen

Usage

pyenvgen <schema.yaml> [-s STORAGE] [-b BACKEND] [-o KEY=VALUE ...] [--force]
Flag Description
-s, --storage Storage (default: stdout), path to a file to store output to.
-b, --backend Storage backend, when the file extension is ambiguous (e.g. komodo vs toml backend).
-o, --override Override a value via KEY=VALUE (repeatable)
--force Regenerate all values, ignoring existing stored values
# Print to stdout
pyenvgen examples/basic.yaml

# Write to a .env file
pyenvgen examples/basic.yaml -s .env

# Override a value
pyenvgen examples/basic.yaml -o APP_PORT=9000

Schema format

variables:
  MY_VAR:
    type: str          # str | int | float | bool (default: str)
    description: "..."
    internal: false    # default: false
    generation:
      rule: default
      value: "hello"
    validation:
      length:
        min: 1
        max: 128

Variable types

str, int, float, bool

Generation rules

All string fields in generation rules are rendered as Jinja2 templates against already-generated values before execution.

  • default – use a static value (supports Jinja2, e.g. "postgres://{{ HOST }}:{{ PORT }}/app")
  • command – run a shell command and capture its stdout
  • openssl – generate cryptographic material via the cryptography package

openssl commands

Command Description Key args
rsa RSA private key (PEM or DER base64) key_size (default 2048), encoding (pem|der_b64)
ec EC private key curve (secp256r1|secp384r1|secp521r1|secp256k1), encoding (pem|der_b64)
ed25519 Ed25519 private key encoding (pem|raw_b64)
x25519 X25519 private key encoding (pem|raw_b64, default raw_b64)
fernet URL-safe base64 Fernet key
random Random bytes length (default 32), encoding (hex|base64|base64url)

Validation rules

Backed by marshmallow.

Rule Applies to Fields
length str min, max
range int, float min, max, min_inclusive, max_inclusive
one_of any choices: [...]
regexp any pattern

Storage backends

Value Description
stdout Print to standard output
.env Read/write a .env file
json Read/write a JSON file
toml Read/write a TOML file
yaml Read/write a YAML file
komodo Read/write a Komodo-style TOML

Special properties

  • internal: true – the variable is generated and available to Jinja2 templates but excluded from the output.

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

pyenvgen-0.3.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

pyenvgen-0.3.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file pyenvgen-0.3.0.tar.gz.

File metadata

  • Download URL: pyenvgen-0.3.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyenvgen-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7c0b6914586bd102a6d6cc3ade2b4ed79c40982bc6b773f061e0c84266c25599
MD5 9cf1cd0c9c5e1e015f759f43d265bdce
BLAKE2b-256 80d334f3bb0a2379cbda46282e479038de0a06c23dbec20708a10b02d39a63e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyenvgen-0.3.0.tar.gz:

Publisher: publish-to-pypi.yml on bastienlc/pyenvgen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyenvgen-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyenvgen-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyenvgen-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 049e4cf48408a9f173a5007d5086ff16fceec3ff1674040291b75088e94989be
MD5 c10de178254b86e61a9841c267dadd0e
BLAKE2b-256 7eff0f4bbbe7efc945fc60a72ba3854b971a7216a60fe4096319fe3abace5bfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyenvgen-0.3.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on bastienlc/pyenvgen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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