Skip to main content

A lightweight Python package for managing environment variables with advanced features.

Project description

envplus

envplus is a lightweight Python package for managing environment variables with advanced features like type conversion, auto validation, hot reloading, and alias support.

Features

  • Type Casting: Easily cast environment variables to str, int, float, bool, list, and json.
  • Auto Validation: Detect missing keys and invalid types with clear error messages.
  • Hot Reload: Automatically reload values when .env file changes (lazy reload).
  • Alias Support: Fallback to alternative keys if the primary key is missing.
  • Strict Mode: Enforce presence of required variables.
  • Default Values: Safe handling of defaults.
  • Debug Console: Inspect loaded variables.

Installation

pip install envplus

Usage

Basic Usage

Create a .env file:

APP_ENV=development
DEBUG=true
PORT=8080
ALLOWED_HOSTS=localhost,127.0.0.1
DB_CONFIG={"host": "localhost", "port": 5432}

Use envplus in your code:

from envplus import Env

env = Env()

# Read values with type casting
mode = env.str("APP_ENV")
debug = env.bool("DEBUG")
port = env.int("PORT")
hosts = env.list("ALLOWED_HOSTS")
db_config = env.json("DB_CONFIG")

print(f"Mode: {mode}, Debug: {debug}, Port: {port}")
print(f"Hosts: {hosts}")
print(f"DB Config: {db_config}")

Strict Mode

Enable strict mode to raise errors for missing variables without defaults.

env = Env(strict=True)

# Raises MissingEnvError if API_KEY is missing
api_key = env.str("API_KEY")

# Safe with default
api_key = env.str("API_KEY", default="secret")

Aliases

Support legacy or alternative environment variable names.

# Tries DATABASE_URL first, then DB_URL
db_url = env.alias(["DATABASE_URL", "DB_URL"])

Debugging

Print all loaded environment variables (masked values not implemented yet, be careful in production!).

env.debug()

Development Setup

  1. Clone the repository.
  2. Install dependencies:
    pip install -e .[dev]
    
  3. Run tests:
    pytest
    

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

envplusai-0.0.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

envplusai-0.0.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file envplusai-0.0.2.tar.gz.

File metadata

  • Download URL: envplusai-0.0.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for envplusai-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f202e787f5045b3bcd92d22cc8d38b5ac34d7e99cdfc36698e01c4aab1aab422
MD5 6e2d951ecf1db82002ce37e86f339416
BLAKE2b-256 716a276c79ec57dd703a9c78f0b5319dea426cebfdd81c67d383da3e46bf12a8

See more details on using hashes here.

File details

Details for the file envplusai-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: envplusai-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for envplusai-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a97026f2ad01df4dc3e231a76df7a69bfae5a488619a0246bf89651b60609fa3
MD5 b10c0512fbb87561291893cf982bf643
BLAKE2b-256 1b4ee9bbc99247da3892e439959a422218bf5a8511a20040fcd5cacaad73d497

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