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.4.tar.gz (12.2 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.4-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mydotenv-0.2.4.tar.gz
  • Upload date:
  • Size: 12.2 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.4.tar.gz
Algorithm Hash digest
SHA256 2d8d0566ec83dd0d7448ff9d719b43c1ce1bee0732bdd436cfa15f912173fac8
MD5 4ce3d1269b757c4273a4916c6d95148d
BLAKE2b-256 2eddef7aa1fcb0d601a3d11dbbec4b11cb88e7534d148a87253a74a391e25cb3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mydotenv-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 12.6 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ee2433a2bfc0fba62cee6741cb9a0c39be524b769d085eddd6e21431f2de3238
MD5 e57b1124fba072e7f1ec83e6607042e3
BLAKE2b-256 e8c4897ec96c1bcf92684a0d8d21207001c8fa3abc201abfd6b3609ba8ba383f

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