envdot - Enhanced Environment Variable Manager

PyPI Version Python Versions License

envdot is an enhanced environment variable management library for Python with multi-format support and automatic type detection.

Features

🔧 Multiple Format Support

Load configuration from .env, .json, .yaml, .yml, and .ini files.

🎯 Automatic Type Detection

Automatically converts strings to bool, int, float, or keeps as string. and Support converts strings to list, tuple by using cast_type.

💾 Read and Write

Load from and save to configuration files seamlessly.

🔄 Method Chaining

Fluent API for cleaner, more readable code.

🌍 OS Environment Integration

Works seamlessly with os.environ.

📦 Zero Dependencies

Core functionality works without external packages (YAML support requires PyYAML).

🌿 Auto re-load

Automatically reload the config file if the hash changes or use reload=True

Quick Example

from envdot import load_env, get_env, set_env

# Load environment variables from .env file
load_env()

# or load_env('.env')
# or load_env('.json')
# or load_env('.yaml')
# or load_env('.ini')
# or load_env('config.env')
# or load_env('/etc/config.env')
# or load_env(r'c:\.env')
# or load_env(r'c:\traceback.ini')

# Get values with automatic type detection
debug = get_env('DEBUG')       # Returns: True (bool)
port = get_env('PORT')         # Returns: 8080 (int)
timeout = get_env('TIMEOUT')   # Returns: 30.5 (float)
allowed_hosts = os.getenv("*,127.0.0.1 192.168.10.2,example.com", cast_type=list) # Return: [*,127.0.0.1,192.168.10.2,example.com]  # (list)
allowed_hosts = os.getenv("*,127.0.0.1 192.168.10.2,example.com", cast_type=tuple) # Return: (*,127.0.0.1,192.168.10.2,example.com)  # (tuple)

# Set new values
set_env('NEW_FEATURE', True) or os.setenv('NEW_FEATURE', True)

# Find by keys
os.find("DB_*") # return dict

Installation

# Basic installation
pip install envdot

# With YAML support
pip install envdot[yaml]

# With all extras
pip install envdot[all]

Documentation Contents

Indices and tables

License

envdot is released under the MIT License. See the LICENSE file for details.

Author

Created by Hadi Cahyadi

Support the Project