Skip to main content

dotenvy-py

A Python port of Rust's dotenvy with first-occurrence-wins behavior.

Features

  • Loads environment variables from .env files
  • Implements "first occurrence wins" behavior, matching Rust's dotenvy
  • Searches for env files in parent directories
  • Allows prioritized loading of multiple env files
  • Fully typed with PEP 484 annotations
  • 100% compatible API with Rust's dotenvy

Installation

pip install dotenvy-py

Usage

Basic Usage

import dotenvy_py

# Load .env file from current directory
env_path = dotenvy_py.dotenv()
if env_path:
    print(f"Loaded environment from: {env_path}")
else:
    print("No .env file found")

Loading Specific File

import dotenvy_py

# Load specific .env file
env_path = dotenvy_py.from_filename(".env.development")
if env_path:
    print(f"Loaded environment from: {env_path}")

Search in Parent Directories

import dotenvy_py

# Find an env file in the current or parent directories
env_path = dotenvy_py.find_upwards(".env.production")
if env_path:
    print(f"Found environment file at: {env_path}")
    # Load it
    dotenvy_py.from_filename(env_path)

Priority Loading (like .env.game_client then .env)

import dotenvy_py

# Load files in priority order (first file has highest priority)
loaded_files = dotenvy_py.load_with_priority([".env.game_client", ".env"])
if loaded_files:
    print(f"Loaded environment files: {', '.join(str(p) for p in loaded_files)}")
else:
    print("No environment files found")

First Occurrence Wins Behavior

Unlike the standard Python python-dotenv library where later definitions override earlier ones, dotenvy-py implements the "first occurrence wins" behavior:

  1. Environment variables that already exist in the process environment take precedence over variables in .env files
  2. The first definition of a variable in a file (or across multiple files) is used, later definitions are ignored
  3. This matches the behavior of Rust's dotenvy crate

License

MIT

Metadata

Release files for dotenvy-py 0.1.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 dotenvy-py 0.1.0
File Size Uploaded Provenance Actions
dotenvy_py-0.1.0.tar.gz 6.1 kB Without provenance Details for dotenvy_py-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dotenvy-py 0.1.0
File Interpreter ABI Platform Actions
dotenvy_py-0.1.0-py3-none-any.whl Python 3 none any Details for dotenvy_py-0.1.0-py3-none-any.whl

Total release size: 12.5 kB

Release files / dotenvy_py-0.1.0.tar.gz

Download URL dotenvy_py-0.1.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2400dbff4cff884696d4902b8c04e63f5244938e2035a4a5642c7c3e398aa57f
BLAKE2b-256 checksum
How to use checksums
dd0f4acd6e7b31a0e0f07339ab95d473ac5508b0fb620e1d379c08e4fc28a822
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / dotenvy_py-0.1.0-py3-none-any.whl

Download URL dotenvy_py-0.1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
806a0d209d3dd700c6e550eba6f532c53031d2800e10287797ad2116204fda84
BLAKE2b-256 checksum
How to use checksums
ceadc2255557985c2cf0a2f855bf0d38cecc5808c08f3a976a3daa3e611ee1f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for dotenvy-py 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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