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.1.tar.gz (5.9 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.1-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: envplusai-0.0.1.tar.gz
  • Upload date:
  • Size: 5.9 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.1.tar.gz
Algorithm Hash digest
SHA256 ab08dbfbd3fa2e270664e45de58801c15cc37a238a5cb41356c44eb0e4f1a3fb
MD5 f8e59a4adb4ac5e5882cca20ad1c0f28
BLAKE2b-256 d783c99fb881d086b07fc7e7bbf209a340b0ba94ffe0af77b1613e45ac9a05ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: envplusai-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4fe507fc6c8b8453e85f9c557baf08b8c3f3466f9f6202f6c4bfcf3f32cbb4d
MD5 ac8ff89450559eaefbe1d9b7260c14bc
BLAKE2b-256 3314e83b8c485254166c5393c87af6f9944e5fd2d6c7a094021cf72b240696ef

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