Skip to main content

A Python utility for automatically managing environment variables with type safety and easy configuration.

Project description

Awesome Environment Manager

A Python utility for automatically managing environment variables with type safety and easy configuration.

Description

Environment Manager provides a simple yet powerful way to handle environment variables in Python applications through type-hinted class attributes. It automatically loads environment variables and converts them to the correct types based on your type hints.

Features

  • 🔒 Type-safe environment variable handling
  • 🔄 Automatic type conversion
  • 📝 Support for .env files (via python-dotenv)
  • 🎯 Support for various data types:
    • Basic types (str, int, float, etc.)
    • Boolean values with flexible input formats
    • Lists with type hints (using semicolon as separator)
    • Dictionaries (key-value pairs)

Installation

bash pip install awesome-environment-manager

or using uv

uv pip install awesome-environment-manager

Quick Start

from aem import EnvironmentClass

class AppConfig(EnvironmentClass):
  DATABASE_URL: str = "postgresql://localhost"
  PORT: int = 8080
  DEBUG: bool = False
  ALLOWED_HOSTS: list[str] = ["localhost", "127.0.0.1", "example.com"]
  DB_CONFIG: dict = {"host": "localhost", "port": "5432", "name": "mydb"}

Create an instance - environment variables will be loaded automatically

os.environ["PORT"] = 8282

config = AppConfig()
print(config.DATABASE_URL) # => postgresql://localhost
print(config.PORT) # => 8282

Environment Variable Formats

  • Strings: Simple string values

    DATABASE_URL=postgresql://localhost:5432/db
    
  • Numbers: Will be converted to int/float

    PORT=8080
    
  • Booleans: Supports various formats

    DEBUG=true  # Also accepts: 1, yes, y, on
    
  • Lists: Use semicolons as separators

    ALLOWED_HOSTS=localhost;127.0.0.1;example.com
    
  • Dictionaries: Use semicolons between pairs and colons between keys and values

    DB_CONFIG=host:localhost;port:5432;name:mydb
    

.env Support

The package automatically supports .env files if python-dotenv is installed:

pip install python-dotenv

Then create a .env file:

DATABASE_URL=postgresql://11.22.33.44
DEBUG=1

Result

config = AppConfig()
print(config.DATABASE_URL) # => postgresql://11.22.33.44
print(config.PORT) # => 8080
print(config.DEBUG) # => True

License

This project is licensed under the European Union Public License v1.2 (EUPL-1.2).

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

awesome_environment_manager-1.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

awesome_environment_manager-1.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file awesome_environment_manager-1.0.0.tar.gz.

File metadata

File hashes

Hashes for awesome_environment_manager-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cac28e84b6dc1f9e56585269eb982ce92de2b2548f464d996324235b1991faa6
MD5 33e274ab259b152a203784a059d0a832
BLAKE2b-256 539b9665a1d93c52beb5b99f33722fd3ca6a80550fde794e58ba9cf063acff8c

See more details on using hashes here.

File details

Details for the file awesome_environment_manager-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for awesome_environment_manager-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d464c0d838001d8b87dec090e7eeb0095abc40d830a936471fefd4423885526
MD5 26069ed88ce35dce93cab49fce28ebee
BLAKE2b-256 6ddc293644fd4a4e59959ce164340db85aa4166f580975b540b3a39a8610a59a

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