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.0.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.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dotenvplus-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 32f236e672711e590117904ae8a19c310c11c1e98a9da57127a5b1aad5f533b3
MD5 e677cd3b8f481815ef26042a02840724
BLAKE2b-256 f9dd2c4b4f5c881bfed139748636c674009e99aa2b01300b318bde977ec2c854

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dotenvplus-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b69c0f43f4927cba4034a8cd5d72a817d7104bfa8c46b750f738462422e4eca9
MD5 471533374837c3c4920c20f7fef56c6d
BLAKE2b-256 79b6ea55331354bb2a4a968f810a0298543b34326c33486837c65f66b97e6fb8

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