Skip to main content

A simple package to manage environment variables with command-line interface

Project description

mydotenv

rrr A simple Python package to manage environment variables in your .env file with command-line interface.

Installation

Using pipx (Recommended)

pipx install mydotenv

Using pip

pip install mydotenv

From Source

git clone https://github.com/banddude/mydotenv.git
cd mydotenv
pip install -e .

Usage

Basic Command Line Interface

  1. Print a variable's value:
mydotenv API_KEY
  1. Add or update a variable:
mydotenv NEW_KEY=value
mydotenv "KEY_WITH_SPACES=value with spaces"
  1. Delete a variable:
mydotenv delete VARIABLE_NAME
  1. View all variables:
mydotenv

Custom Command Name

You can set a custom command name to use instead of mydotenv:

mydotenv --set-command dotman

Now you can use either mydotenv or dotman to run commands:

dotman NEW_KEY=value
dotman delete NEW_KEY

When you set a new command name, it replaces any previous custom command name.

Advanced Features (New)

Scanning for Environment Variables

The new CLI functionality lets you scan your codebase for env.VARIABLE_NAME references and manage your .env file based on what it finds:

  1. Replace existing .env with newly discovered variables (empty values):
mydotenv --replace env [<path>]
  1. Add newly discovered variables as empty placeholders (preserving existing ones):
mydotenv --add-empty env [<path>]
  1. Add newly discovered variables (same as --add-empty in current implementation):
mydotenv --add env [<path>]

Import Statement Rewriting

You can rewrite Python files to directly access environment variables without needing to use the env object:

# Rewrite imports for a specific file or directory
mydotenv --add imports [<path>]

# Rewrite imports for all Python files in the current directory
mydotenv --add imports

This will:

  1. Remove any import mydotenv or from mydotenv import ... statements
  2. Add code to automatically find and load the .env file from your project
  3. Make environment variables directly accessible as Python variables

For example, if your .env contains API_KEY=123, you can simply do:

# This works after running mydotenv --add imports on your file
print(API_KEY)  # Prints: 123

No more need for: from mydotenv import env and print(env.API_KEY)!

Optional Parameters

  • --ignore: Specify paths to ignore when scanning
mydotenv --add env . --ignore tests venv
  • --env-file: Specify which .env file to use (default: .env)
mydotenv --replace env . --env-file .env.dev

Features

  • Manage environment variables from the command line
  • Set custom command names for easier use
  • Preserves comments and formatting in .env file
  • Handles values with spaces and special characters
  • Works from any directory
  • Creates and manages .env file in your current directory
  • NEW: Scan codebase for environment variable references
  • NEW: Replace or update .env files based on discovered variables
  • NEW: Rewrite imports to allow direct environment variable access

Dependencies

  • python-dotenv >= 1.0.0

Configuration

  • The package stores its configuration in ~/.config/mydotenv/config.env
  • Custom command names are managed through symlinks in ~/.local/bin

License

MIT License - feel free to use this package in your projects!

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

mydotenv-0.2.6.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

mydotenv-0.2.6-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file mydotenv-0.2.6.tar.gz.

File metadata

  • Download URL: mydotenv-0.2.6.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mydotenv-0.2.6.tar.gz
Algorithm Hash digest
SHA256 bd051c1b748f47208bc3ae99e0f5a49445bcb1d9c5129dcce1396004a44241e5
MD5 86f9c323ebf005cc6f61cc17b61bda60
BLAKE2b-256 2436caa248daa93778f86045221422e9eec6df6f183f3b78d8b9e975e4d912d7

See more details on using hashes here.

File details

Details for the file mydotenv-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: mydotenv-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mydotenv-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b494a3ab050cf97a4443ece3bd116146de8b542d1761ef4cd663f59f35841538
MD5 7a88e5473f44d105f65035f62ed81c4f
BLAKE2b-256 c77efa3ffa9e8452645d9c2a69d2c3f78e58475fdbaa326f74b4532d59f0ec6c

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