Skip to main content

Easy environment variables management with type validation

Project description

easy-dotenv

PyPI version Python Versions License: MIT

Simple and type-safe environment variables management for Python.

Installation

pip install easy-dotenv

Usage

First, create an environment configuration file (e.g., env_loader.py):

from easy_dotenv import EnvLoader

# Initialize environment variables once
env = EnvLoader.load(
    port=int,
    api_key=str,
    debug=(bool, False),  # Optional with default value
    workers=(int, 4)      # Optional with default value
)

__all__ = ['env']

Then use it in your code:

from env_loader import env

print(f"Port: {env.port}")
print(f"API Key: {env.api_key}")
print(f"Debug mode: {env.debug}")    # False if not set
print(f"Workers: {env.workers}")     # 4 if not set

Features

  • Type validation
  • Required/optional variables
  • Default values
  • .env file support
  • Clean and simple API
  • Type hints support

Error Handling

The environment validation happens when you initialize the configuration:

from easy_dotenv import EnvLoader, EnvMissingError, EnvTypeError

try:
    env = EnvLoader.load(
        api_key=str,
        port=int
    )
except EnvMissingError as e:
    print("Missing environment variables:", e)
except EnvTypeError as e:
    print("Invalid environment variable type:", e)

Development

Setup

# Create virtual environment
python3 -m venv venv

# Activate virtual environment
source venv/bin/activate  # Linux/MacOS
# or
# venv\Scripts\activate  # Windows

# Install with development dependencies
pip install -e ".[dev]"

Running Tests

# Run tests
pytest

# Run tests with coverage
pytest --cov=easy_dotenv

License

MIT

Requirements

  • Python 3.7 or higher
  • python-dotenv>=0.19.0

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

easy_dotenv-0.1.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

easy_dotenv-0.1.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file easy_dotenv-0.1.4.tar.gz.

File metadata

  • Download URL: easy_dotenv-0.1.4.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for easy_dotenv-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2f2bbb7000681dd880546b2f4357435068610b3ad1bfc4ce6501b6ef8fecbc0f
MD5 b242d6612530614ebb39409419fd5903
BLAKE2b-256 3a5ed8434ef2adbe37e5230236d985353b4ef5d6eb94b5a69601fc197b4dedeb

See more details on using hashes here.

File details

Details for the file easy_dotenv-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: easy_dotenv-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for easy_dotenv-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6c902ebc16f84bb4ef46941994cc3007e8ff687ddf5af5efb8b02a4159af07ce
MD5 c2fa926e2e7f578456fbf5bf4247fdc6
BLAKE2b-256 6f22752733253a5be46d46730a1504747ad2dba5cd761cf5cc23a315c12623c7

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