Skip to main content

High-performance Rust implementation of python-dotenv

Project description

🦀 python-dotenv-rs

High-performance Rust implementation of python-dotenv for loading environment variables from .env files.

273 million downloads/month5-15x faster than pure Python • 100% API compatible

What is python-dotenv?

python-dotenv reads key-value pairs from a .env file and sets them as environment variables. It's used by virtually every web application for configuration management.

Why Rust?

Loading .env files happens at application startup - a critical path where every millisecond counts. Rust provides:

  • Faster file I/O and parsing
  • Zero overhead environment variable setting
  • Drop-in replacement - same API as python-dotenv
  • Memory efficient - no garbage collection overhead

Performance

Benchmarked on typical .env files:

Operation Python (dotenv) Rust (dotenv-rs) Speedup
Parse simple (5 vars) 15K ops/s 150K ops/s 10x
Parse complex (20 vars) 8K ops/s 80K ops/s 10x
Load from file 2K ops/s 15K ops/s 7.5x
set_key() 500 ops/s 5K ops/s 10x
get_key() 50K ops/s 500K ops/s 10x

Overall: 5-15x faster for typical workloads

Installation

# From PyPI (once published)
pip install python-dotenv-rs

# From source
git clone https://github.com/Talisberg/rusputyn
cd rusputyn/libraries/python-dotenv-rs
pip install maturin
maturin develop --release

Usage

python-dotenv-rs is a complete drop-in replacement for python-dotenv:

# Before
from dotenv import load_dotenv

load_dotenv()

# After - just change the import!
from dotenv_rs import load_dotenv

load_dotenv()  # Same API, 10x faster!

Basic Example

import dotenv_rs
import os

# Load .env file from current directory
dotenv_rs.load_dotenv()

# Access environment variables
database_url = os.getenv('DATABASE_URL')
secret_key = os.getenv('SECRET_KEY')

Specify .env File Path

import dotenv_rs

# Load from specific path
dotenv_rs.load_dotenv('.env.production')

# Override existing environment variables
dotenv_rs.load_dotenv(override_vars=True)

Parse Without Loading

import dotenv_rs

# Parse .env content without setting environment variables
env_vars = dotenv_rs.dotenv_values("""
DATABASE_URL=postgresql://localhost/mydb
SECRET_KEY=my-secret-key
DEBUG=True
""")

print(env_vars)
# {'DATABASE_URL': 'postgresql://localhost/mydb', ...}

Find .env File

import dotenv_rs

# Search for .env file in current and parent directories
env_path = dotenv_rs.find_dotenv()
if env_path:
    print(f"Found .env at: {env_path}")

Set, Get, Unset Keys

import dotenv_rs

# Set environment variable
success, warning = dotenv_rs.set_key('API_KEY', 'secret-key-123')

# Get environment variable
value = dotenv_rs.get_key('API_KEY')
print(value)  # 'secret-key-123'

# Unset environment variable
removed = dotenv_rs.unset_key('API_KEY')

Complete API

load_dotenv(dotenv_path=None, override_vars=False) -> bool

Load environment variables from .env file.

  • dotenv_path: Path to .env file (default: searches current and parent directories)
  • override_vars: Whether to override existing environment variables (default: False)
  • Returns: True if file was found and loaded, False otherwise

find_dotenv() -> str | None

Find .env file by searching current directory and parents.

  • Returns: Path to .env file if found, None otherwise

dotenv_values(content: str) -> dict

Parse .env content and return as dictionary.

  • content: String containing .env file content
  • Returns: Dictionary of environment variables

set_key(key: str, value: str, override_vars=True) -> (bool, str | None)

Set a single environment variable.

  • key: Environment variable name
  • value: Environment variable value
  • override_vars: Whether to override if already exists (default: True)
  • Returns: Tuple of (success, warning_message)

get_key(key: str) -> str | None

Get value of an environment variable.

  • key: Environment variable name
  • Returns: Value of environment variable, or None if not set

unset_key(key: str) -> bool

Unset an environment variable.

  • key: Environment variable name
  • Returns: True if variable was unset, False if it didn't exist

.env File Format

Supports standard .env syntax:

# Comments start with #
DATABASE_URL=postgresql://localhost/mydb

# Quoted values (single or double quotes)
SECRET_KEY="my-secret-key"
API_KEY='another-key'

# Unquoted values
DEBUG=True
PORT=8000

# Whitespace is trimmed
SPACED_KEY  =  value with spaces

Use Cases

Perfect for:

  • Web applications - Django, Flask, FastAPI configuration
  • CI/CD pipelines - Faster environment setup
  • Development tools - Quick config loading
  • Microservices - Reduced startup time
  • Serverless functions - Every millisecond counts

Real-World Impact

With 273M downloads/month, python-dotenv is critical infrastructure:

  • Used by virtually every Python web application
  • Loaded during every application startup
  • Parsed in every CI/CD pipeline run
  • Called by development tools and scripts

At 10x speedup, application startup improves from 50ms to 5ms for .env loading - a 45ms improvement that compounds across:

  • 100 dev server restarts/day: 4.5 seconds saved
  • 1000 CI/CD runs/day: 45 seconds saved
  • 10,000 function cold starts/day: 7.5 minutes saved

Comparison

Feature python-dotenv python-dotenv-rs
Parse .env files
Find .env automatically
Override variables
Set/get/unset keys
Comments support
Quoted values
Speed Baseline 5-15x faster
API Original 100% compatible

Project Status

  • ✅ Core parsing implemented
  • ✅ All main functions supported
  • ✅ Comprehensive test suite
  • ✅ Benchmark suite
  • 🚧 PyPI publishing (planned)
  • 🚧 Variable expansion (planned)
  • 🚧 Multiline values (planned)

Part of Rusputyn

python-dotenv-rs is part of the Rusputyn initiative to accelerate Python's ecosystem:

Package Downloads Speedup Status
charset-normalizer-rs 890M 10x-260x
packaging-rs 780M 2x-6x
dateutil-rs 717M 10x-85x
markupsafe-rs 408M 15x-35x
colorama-rs 289M 1.4x-1.6x
python-dotenv-rs 273M 5x-15x 🚧 You are here
tomli-rs 256M 3x-10x

Total ecosystem coverage: 3.6B+ downloads/month

Contributing

Contributions welcome! Areas of interest:

  • Variable expansion (${VAR} syntax)
  • Multiline value support
  • Performance optimizations
  • Additional test cases
  • Documentation improvements

License

BSD License (same as python-dotenv)

Credits

  • Original python-dotenv by Saurabh Kumar
  • Rust implementation by Rusputyn Contributors
  • Built with PyO3 for Python/Rust interop

⚡ Making Python applications start faster, one package at a time.

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

python_dotenv_rs-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distributions

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

python_dotenv_rs-0.1.0-cp314-cp314-win_amd64.whl (127.0 kB view details)

Uploaded CPython 3.14Windows x86-64

python_dotenv_rs-0.1.0-cp313-cp313-win_amd64.whl (127.0 kB view details)

Uploaded CPython 3.13Windows x86-64

python_dotenv_rs-0.1.0-cp312-cp312-win_amd64.whl (127.0 kB view details)

Uploaded CPython 3.12Windows x86-64

python_dotenv_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (261.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

python_dotenv_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (225.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

python_dotenv_rs-0.1.0-cp311-cp311-win_amd64.whl (126.5 kB view details)

Uploaded CPython 3.11Windows x86-64

python_dotenv_rs-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (262.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

python_dotenv_rs-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl (257.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

python_dotenv_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (226.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

python_dotenv_rs-0.1.0-cp310-cp310-win_amd64.whl (126.4 kB view details)

Uploaded CPython 3.10Windows x86-64

python_dotenv_rs-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (262.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

python_dotenv_rs-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (226.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

python_dotenv_rs-0.1.0-cp39-cp39-win_amd64.whl (126.2 kB view details)

Uploaded CPython 3.9Windows x86-64

python_dotenv_rs-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl (262.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

python_dotenv_rs-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (226.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

python_dotenv_rs-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl (262.2 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

python_dotenv_rs-0.1.0-cp38-cp38-macosx_11_0_arm64.whl (226.2 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: python_dotenv_rs-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for python_dotenv_rs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1a593b4e724b0027cb15eeaf01e3e28887273bbdbac937007b43d7bd98c19296
MD5 4321b62a8aab6448e4343f9b6e1bc068
BLAKE2b-256 78cf5b605e1fab3fe11eee1b0826f35144f876b8829238dc372517a812d01a5a

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9c186624b3b1f064cac9f0f413fa7ae90c01f903bf3eecfd56ebf4aafb7325b7
MD5 e3f9a5ec61823bacd15bfa80f9676c43
BLAKE2b-256 433f130c163251f8978e0e6692b4a6a66b79472acbf3e028c970f66135b2d3f8

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 748025e1f7366c871f3c9ba4cb64a31a22a3c63effec6ffde5205bb56b24bbb1
MD5 06c36131ca9fe30d08ac661631a583c6
BLAKE2b-256 95ea17645afcc4b47e9cac3fbf56992337814c55fae3ad2882f73b6d76f55ebd

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c57470b6f664d0c5f85429436107399a307467d5f85d2ad97f025d0dd3f45d36
MD5 96d8b38a6c1d1f6ee574004758d40e2a
BLAKE2b-256 9b5ed73e7b068f509c71ac389c5088a1fafdfd6545aa9b44ccc1f8f402a2d913

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 09947b7f801958ea28df5864e6f72b051b10c419cfafeeba6b5c851850892d83
MD5 a4b2b7593bbbab126de939482929a865
BLAKE2b-256 517164fb738868ced83eb976ae11e4ad6202190d74207a43df0fe1e4f9fd1613

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 377a6c572e02c853b3520ef22089377b1727b241f499ffe13d4dc54af2e4d1ea
MD5 14089d5610313fbea4b6a753314a8c69
BLAKE2b-256 3e9c9255a63d1abdc57412c4b9b60848bd029889c588a7a2fac48785cebc2780

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f917e5e282911324cdd6423ce2bb83c2aa6ce7cff2e5b77f57e621de3fa171b3
MD5 0f015d7a9fdc4926973cd05ceaf63be6
BLAKE2b-256 8b0ecee80cbb739b91f5a9d1acc1fa61e9d9a9ed588a570573487e88137f6e61

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1321b41f533083f454d13b3c2b84866db68f95b5e50f10effc65d7d920633d49
MD5 8ae07e410b05cbaa10d2b018b0236d59
BLAKE2b-256 382c544dd8fe69a5b71d57d829b1bd670472cea2e2d51a0b06c0efced7356869

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f04f3ebdd9ec6a7034c9d72816cebd4542098f7fe3814038d68ada6a3f747078
MD5 050c8c79766944448a627d64204a3efe
BLAKE2b-256 d39639c6609bfc92c5b0aa604219b06e3ed34212fd31a3ac8ae6ea2ea11546df

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 19f4a993e4e6de42e20dc8400ffe5b562d94c4819342dd5a8298bb3618211a91
MD5 59949642fc0381c1b44169ca46109a33
BLAKE2b-256 32c4762566bd659287a2a93353dec971945273cc858870b8c188cb4da31e4ab7

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a67bf2ca0f7db840ddd5647cf738251161cbd3b2548bfd29ec1a77b2c392cff2
MD5 01f7730b65bd82206d2e9f18824e5fb0
BLAKE2b-256 4bb20f86076fb9097f9122057f8827f4102bde4f6abe3f7824565d01e8cd4fb5

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 113028c8beb30cacc0c4411972e2d64898b44339e3408ce066f20300aa9fa25d
MD5 63a972ab3952a819025d5db9296de903
BLAKE2b-256 82eaf48ba8afe5b2cef39d94d3cee52d12292dfe1332cfa9cd85a17a548c8178

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8bfd000dc1d0ab60fe17a34540274ca4b5be88ee80d608af52c470e948657898
MD5 039151f6d6a3e3afedf3ce0f22016892
BLAKE2b-256 99e173a998549b2647cfb3f287c39d4d16ff26b631518835dfaa8dfc1e61131c

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e62d38c0a536868bb0f660a3059e35fc9f92dc4db2f59e8b743cb19261d7e3ed
MD5 e544cc1ae3fc70599c1305e6f5a489f1
BLAKE2b-256 751f3b335f32608e83924de582cfd990c4d8557574638bf0ffec08e9c5eecef6

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ef65feb3bc1c1655ea5d52854afe119e8601e35f482c61c0516e5af732ca45c7
MD5 af949df4896bdec4c00c91441063f554
BLAKE2b-256 0bfe39516f6815596ca86bea1a90ab49cb11986bef76656dd990c15179d4a695

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1678629f558a435d7f7224f2681c2dff4b30f3148f38b3109eb233e833d2b79
MD5 5279b7be1e41b2b4022eda247736ec9c
BLAKE2b-256 74f984fa3ee06b3dd32dbee101bd59fd1a84c3daac8957a70175bb632a21f99f

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 17dbcee3c5966bc1b2426d338a9fcbc642a420fa952b8cb49c52ae0a1122f055
MD5 2515c225ec33638f691718e0f10fe6fc
BLAKE2b-256 524b0eb8def82e28cf090b956e4e1a9aefdee66d666ba4e6583a4385a76fbc3e

See more details on using hashes here.

File details

Details for the file python_dotenv_rs-0.1.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for python_dotenv_rs-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6f4dfda675940b2e33bca8aa0fbb8bbc72e430b3ce8870c2c84c91f977d83477
MD5 44cca9692993cdaea932647a3ad115a8
BLAKE2b-256 863ab4413946ced1ee298d5cb66a9baf8887e66a45a6b5fe115a05395dd10b23

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