Skip to main content

Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.

Project description

DotEnvPlus

Reads key-value pairs from a .env file with automatic type conversion and variable interpolation. Zero dependencies, native Python 3.10+.

Values are returned as a dictionary-like object, so .items(), .keys(), .values(), and all standard dict operations work out of the box.

Installing

You need Python >=3.10 to use this library.

pip install dotenvplus

Usage

# .env
KEY1=value
KEY2=123
KEY3=true
from dotenvplus import DotEnv

env = DotEnv(".env")

env["KEY1"]  # "value"
env["KEY2"]  # 123
env["KEY3"]  # True

Type conversion

Values are automatically converted to the appropriate Python type:

.env value Python type Example
hello str "hello"
"123" str "123"
123 int 123
12.34 float 12.34
true / false bool True / False
null / none / nil / undefined None None

Quoting a value (single or double quotes) forces it to remain a string regardless of its content.

Variable interpolation

Reference other keys or system environment variables using ${VAR}:

HOST=localhost
PORT=5432
DATABASE_URL=postgres://${HOST}:${PORT}/mydb
env["DATABASE_URL"]  # "postgres://localhost:5432/mydb"

Constructor options

# Returns None instead of raising KeyError for missing keys
env = DotEnv(".env", handle_key_not_found=True)
env["MISSING"]  # None

# Loads all values into os.environ (non-strings are converted to strings)
env = DotEnv(".env", update_system_env=True)

TypedDict support

For full type hint support, define a TypedDict and use as_typed():

from typing import TypedDict
from dotenvplus import DotEnv

class MyEnv(TypedDict):
    HOST: str
    PORT: int
    DEBUG: bool

env: DotEnv[MyEnv] = DotEnv(".env")
typed = env.as_typed()
typed["PORT"]  # typed as int

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

dotenvplus-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

dotenvplus-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file dotenvplus-0.1.0.tar.gz.

File metadata

  • Download URL: dotenvplus-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dotenvplus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f716387812b38da578ce7bf9a1273d3e8be89839c8fa687ab8d619a918391ff6
MD5 96ebc5804bf2256c2dfdf77fefb532db
BLAKE2b-256 332c951dffeebf57e02e52fde83f6b9dd65a1a43736263cb37d8311448659827

See more details on using hashes here.

File details

Details for the file dotenvplus-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dotenvplus-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dotenvplus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d76469e3515e01e6b08b784ebcb8f811150bd0d5fdad5e52a9819450701d5b12
MD5 d87a45e4d833db681325c2b71974dbd9
BLAKE2b-256 111bde87d28516c9d9096395e9217a6fa0100d88411e6203f030ff2e1c58fc4e

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