Skip to main content

A lightweight Python utility for loading and retrieving environment variables

Project description

Enventory

Enventory is a lightweight Python utility for loading and retrieving environment variables with optional type casting, defaults, and required flags.


Features

  • Load environment variables from current directory or specified paths.
  • Retrieve environment variables with default values, type casting, and required checks.
  • Helper functions for casting strings to booleans or lists.
  • Raises clear errors when environment files or required variables are missing.
  • Compatible with Python 3.8+.

Installation

Once published to PyPI, you can install Enventory via pip:

pip install enventory

Or for local development:

git clone https://github.com/yourusername/enventory.git
cd enventory
pip install -e .

Usage

Load Environment Variables

from enventory import loadenv

# Load environment variables from cwd or parent paths
loadenv()

# Load environment variables from a specific file in a base directory
from pathlib import Path
loadenv(base=Path("/path/to/project"), name=".env.production")

Retrieve Environment Variables

from enventory import getenv, to_boolean, to_list

# Get a variable with optional default
db_host = getenv("DB_HOST", default="localhost")

# Get a required variable (raises ValueError if missing)
secret_key = getenv("SECRET_KEY", required=True)

# Cast a variable to boolean
debug_mode = getenv("DEBUG", default="False", cast=to_boolean)

# Cast a comma-separated variable to a list
allowed_hosts = getenv("ALLOWED_HOSTS", default="", cast=to_list)

Helper Functions

from enventory import to_boolean, to_list

to_boolean("yes")  # True
to_boolean("0")    # False

to_list("a,b,c")   # ['a', 'b', 'c']
to_list("a;b;c", separator=";")  # ['a', 'b', 'c']

Error Handling

  • EnvNotFoundError is raised if loadenv cannot find an environment file.
  • ValueError is raised by getenv if a required environment variable is missing.

Project Structure

enventory/
├── setup.py
├── pyproject.toml
├── README.md
└── enventory/
    ├── __init__.py  # exposes env.py
    └── env.py       # main environment utility

Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-name)
  3. Make your changes
  4. Submit a pull request

License

MIT License © Your Name



Compatibility

  • Python 3.8 and above

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

enventory-0.0.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

enventory-0.0.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for enventory-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b4643e807e23f09b94568be9461690372cd0c3ad5be208426199019571d5d260
MD5 1acee3a2f79c60d6f356bce0717978cc
BLAKE2b-256 4ddc3b2e82246c611b60342de7bd2058adb8bb27286bc79f1b56daae8c7fb85f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for enventory-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 96a9a97f3d626a4d1fd9cea72ac705e1680f7a48e9a3786d992707445651e25a
MD5 ccd69051ce9acc2bd957ae8d7c206c2a
BLAKE2b-256 bec2f8361d2fde8561a2e60f83387cdb4b1c0af336e17bcfa581016a4dd7e9c3

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