Skip to main content

envu

This package provides a convenient way to load environment variables from the .env file and system environment variables, automatically parsing them into appropriate Python types (bool, int, float, or str). It also allows you to access the loaded variables as attributes.

Features:

  • Parses .env file values into their correct types.
  • Supports boolean, integer, float, and string conversions.
  • Skips empty lines and comments.
  • Raises an error for malformed .env lines or missing variables.
  • Provides a __dir__ method for inspecting available keys.

Installation

pip install envu

Usage

>>> import env  # not envu

>>> env.KEY  # Access environment variables as attributes
'Value'

>>> env.DEBUG  # Boolean Variable
False

>>> env.SECRET_KEY  # String Variable
'fake-secret-key'

>>> env.POSTGRESQL_PORT  # Integer Variable
5432

>>> env.SLEEP_TIME  # Float Variable
1.5

>>> env.ALLOWED_HOSTS.split(",")  # Convert to a list
["localhost", "127.0.0.1", "example.com"]

>>> env.UNDEFINED_VARIABLE  # Undefined Variable
None

>>> env.MY_VARIABLE or "default_value"  # Get the variable with a default fallback
"default_value"

Example: How do I use it with Django?

For a typical Django project, the .env file is placed like this:

my_project/
├── .env                 # Your environment variables
├── manage.py            # Django project entry point
├── my_project/          # Main application folder
│   ├── __init__.py
│   ├── settings.py      # Django settings file where .env is loaded
│   ├── urls.py
│   └── wsgi.py
└── apps/
    ├── app1/
    └── app2/

An example of Django settings

import env
from unipath import Path

BASE_DIR = Path(__file__).parent


SECRET_KEY = env.SECRET_KEY
DEBUG = env.DEBUG or False
ALLOWED_HOSTS = env.ALLOWED_HOSTS.split(",")


DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": env.DJANGO_DB_NAME,
        "USER": env.DJANGO_DB_USERNAME,
        "PASSWORD": env.DJANGO_DB_PASSWORD,
        "PORT": env.DJANGO_DB_PORT or 5432,
        "HOST": env.DJANGO_DB_HOST or "localhost",
    }
}


EMAIL_HOST_PASSWORD = env.EMAIL_HOST_PASSWORD
EMAIL_HOST_USER = env.EMAIL_HOST_USER
EMAIL_PORT = env.EMAIL_PORT or 25
EMAIL_HOST = env.EMAIL_HOST or "localhost"
EMAIL_USE_TLS = env.EMAIL_USE_TLS or False

# ...

Running Tests

To run the tests, make sure you have pytest installed. You can install it using requirements.txt:

pip install -r requirements.txt

Then run:

pytest

This command will discover and execute all test cases in the project. For more advanced options, you can refer to the pytest documentation.

Metadata

Release files for envu 1.2.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 envu 1.2.0
File Size Uploaded Provenance Actions
envu-1.2.0.tar.gz 3.4 kB Without provenance Details for envu-1.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 7.4 kB

Release files / envu-1.2.0.tar.gz

Download URL envu-1.2.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e64758853fc8d276c2025116a130b4250cedb8520910a1b23aea6f9f0f3d8668
BLAKE2b-256 checksum
How to use checksums
0c4144ad020a2f5314e650aab0a2c967d6d64da3df47f31370114c259ebe7735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-52-generic

Release files / envu-1.2.0-py3-none-any.whl

Download URL envu-1.2.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a544865798e7bf58f28b754fff3f0b44eaf7f97908d91cbae279b32f89047072
BLAKE2b-256 checksum
How to use checksums
249dcf30c79058ea50d9c83e888c166538d88f02eee722368663a1b53b8faed6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-52-generic

Security for envu 1.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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