Skip to main content

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, optional, parent directories created, no error if it already existed, value=/var/log/garden/plants.log
# ⚠️ Default value is a string because `convert_default=True` to ensure the path is created whether default or the env value is used.
plant_log = env.read("PLANT_LOG", "/tmp/log/garden/plants.log", astype=env.to_filepath, convert_default=True)

# 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.

Metadata

Release files for envyronment 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for envyronment 0.4.0
File Size Uploaded
envyronment-0.4.0.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envyronment 0.4.0
File Interpreter ABI Platform
envyronment-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / envyronment-0.4.0.tar.gz

Download URL envyronment-0.4.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9ffca947d8e19ff1f87974517c76c57ebd9d7e180f667154e499eeb03bf7fad7
BLAKE2b-256 checksum
How to use checksums
f6327c75c23c01e40e5302e71bfa2f0ab92ff82c5637a576d51dff2ed32920a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2025.

Transparency log

Release files / envyronment-0.4.0-py3-none-any.whl

Download URL envyronment-0.4.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f5f16c1a5d661c75e9eb5d202e625bc90e4ac501cea55441915c52ddfbe0cdb
BLAKE2b-256 checksum
How to use checksums
cd1dfe6f1f3051c3c30691ae1ec511bf128fc220b8455910e23b984e56c62f95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page