Skip to main content

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

Project description

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

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

dotenvy_py-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

dotenvy_py-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dotenvy_py-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for dotenvy_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2400dbff4cff884696d4902b8c04e63f5244938e2035a4a5642c7c3e398aa57f
MD5 f9c2a7f7f2f953c1d38b9fa25db3c83c
BLAKE2b-256 dd0f4acd6e7b31a0e0f07339ab95d473ac5508b0fb620e1d379c08e4fc28a822

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dotenvy_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for dotenvy_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 806a0d209d3dd700c6e550eba6f532c53031d2800e10287797ad2116204fda84
MD5 e1d2016fb1be6185e818222db71534b2
BLAKE2b-256 ceadc2255557985c2cf0a2f855bf0d38cecc5808c08f3a976a3daa3e611ee1f4

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