Skip to main content

Dotenv parser with automatic type conversion, variable interpolation, and multiline support. Zero dependencies.

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} or $VAR:

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

Multiline values

Wrap a value in quotes and span it across multiple lines:

PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA...
-----END RSA PRIVATE KEY-----"
env["PRIVATE_KEY"]  # "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEA...\n-----END RSA PRIVATE KEY-----"

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)

# Don't overwrite keys already set in os.environ (useful as a dev fallback)
env = DotEnv(".env", update_system_env=True, override=False)

# Custom file encoding (defaults to utf-8)
env = DotEnv(".env", encoding="latin-1")

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.2.1.tar.gz (8.5 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.2.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dotenvplus-0.2.1.tar.gz
  • Upload date:
  • Size: 8.5 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.2.1.tar.gz
Algorithm Hash digest
SHA256 ef1c79ad4bcfc8a770257c057a91a88a0d5b2ec52957be236746139dc3b1be26
MD5 da22c985b764a567159d8484f16ca75b
BLAKE2b-256 db39e9032058b0b9bf6bfd073152de57405a0735f8fd1ddaf4f6d4814f6ca282

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dotenvplus-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 069870745047a9ca81bb306f07bda85833a86d4d11e40541118624b56b56e9b4
MD5 1e9e2e9747051ef6f9c2cebbbdf03090
BLAKE2b-256 912dc6b50e5df9ccbe19537e3951e5028f4ea1e9597aad53c79364520c0dfb4e

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