Skip to main content

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

Project description

mydotenv

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 also rewrite import statements in your Python files to use the preferred style:

mydotenv --add imports [<path>]

This will find any import mydotenv or from mydotenv import ... statements and rewrite them as from mydotenv import env.

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 import statements to a consistent style

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.3.tar.gz (11.4 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.3-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mydotenv-0.2.3.tar.gz
  • Upload date:
  • Size: 11.4 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.3.tar.gz
Algorithm Hash digest
SHA256 2cb069296f6072734440440432ec8db6a4c23c11b42e70c1aab4371d46bb7425
MD5 679def2e76b0c92c7b62dd48c0e50e27
BLAKE2b-256 547a13aaabc65e9906eb2b9024fbd4621d339b6b6a05c0dee3e64f60cc355f9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mydotenv-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 11.9 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28564ea7b269ef18b4c4ee102fbed5901a77ff021960fb2d06e40f7228ae6f23
MD5 295cb56c4634c46b8c3cd5b02342c4bf
BLAKE2b-256 3492094016305d1db40fd03740a3837778cbe50e047ea434b9b0bada1b2637e8

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