Skip to main content

A tiny module to read environment variables and tranform them.

Project description

envyronment

A tiny module to read environment variables and tranform them.

When load_dotenv is available, this is called at import time.


Code style: Ruff Typing: Pyright Linting: Pylint License CI Validation


Features

  • ✅ Simple, typed API
  • ✅ Loads .env if installed with extra dotenv
  • ✅ Flexible casting via astype=...
  • ✅ Propagates errors raised in the astype callable
  • ✅ Zero dependencies required, python-dotenv optionally installed

Requirements

  • Python 3.10+ (only 3.13 is tested)

Quick start

  1. Install the package

    pip install "envyronment[dotenv]"
    

    (the [dotenv] extra is optional — include it to enable .env file loading)

  2. Import and use

    import envyronment as env
    
    some_value = env.read("SOME_VALUE", 42, astype=int)
    

Example usage

import os

import envyronment as env

os.environ.update(
    {
        "GREENHOUSE_NAME": "dr. greenthumb's greenhouse",
        "ENABLE_PHOTOSYNTHESIS": "yes",
        "GARDEN_TOOLS": "shovel,rake,watering_can",
        "GARDEN_PLAN": '{"flowers": ["rose", "tulip"], "vegetables": ["carrot", "tomato"]}',
        "PLANT_LOG": "/var/log/garden/plants.log",
        "GREENHOUSE_DIR": "/srv/greenhouse",
        "GREENHOUSE_STATE": "open",
    }
)


def to_upper(value: str) -> str:
    """Convert a string to an uppercase string."""
    return value.upper()


# str, required, no astype provided, so str(value) is used, value="dr. greenthumb's greenhouse"
greenhouse_name = env.read("GREENHOUSE_NAME")

# int, optional, by default 42, value=42
max_plants = env.read("MAX_PLANTS", 42, astype=int)

# bool, optional, by default False, value=True
enable_photosynthesis = env.read("ENABLE_PHOTOSYNTHESIS", default=False, astype=env.to_bool)

# list[str], required, ["shovel", "rake", "watering_can"]
garden_tools = env.read("GARDEN_TOOLS", astype=env.to_list)

# dict (due to input format), required, value={"flowers": ["rose", "tulip"], "vegetables": ["carrot", "tomato"]}
garden_plan = env.read("GARDEN_PLAN", astype=env.to_json)

# Path, required, parent directories created, no error if it already existed, value=/var/log/garden/plants.log
plant_log = env.read("PLANT_LOG", astype=env.to_filepath)

# Path, required, parent directories created, no error if it already existed, value=/src/greenhouse
greenhouse = env.read("GREENHOUSE_DIR", astype=env.to_dirpath)

# str, optional, by default CLOSED, uses custom converter defined above, value="OPEN"
greenhouse_state = env.read("GREENHOUSE_STATE", "CLOSED", astype=to_upper)

License

This project is licensed under the MIT License — see the LICENSE file for details.

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

envyronment-0.3.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

envyronment-0.3.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file envyronment-0.3.0.tar.gz.

File metadata

  • Download URL: envyronment-0.3.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for envyronment-0.3.0.tar.gz
Algorithm Hash digest
SHA256 552c826609c0c38ab287db4dbb79b1bffff99e852fd825679048dd024de76440
MD5 84a6f5752db0b68f635c30e38ec4b2cc
BLAKE2b-256 741e58dbc69a17754dc937d4ea1866303556af3b422f8e4ac488ea30d21c16d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for envyronment-0.3.0.tar.gz:

Publisher: release.yml on shifqu/envyronment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file envyronment-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: envyronment-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for envyronment-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a40c0c746c5b42e3a9b3fdc7ca89989bb0016f55ba3c088de924c5516af4464
MD5 599757e904e756bcc2641d799f4f7bd9
BLAKE2b-256 be0b574ee215937bf5377efb747647f92168bb6eeb86eb327b97aed5b9ce9ed6

See more details on using hashes here.

Provenance

The following attestation bundles were made for envyronment-0.3.0-py3-none-any.whl:

Publisher: release.yml on shifqu/envyronment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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