Skip to main content

License PyPI version PyPI - Python Version Ruff Checked with mypy Github Actions Build Code Coverage

execenv

Powered by click, execenv is a simple cross-platform cli utility that allows you to execute commands with different environment variables by passing directly or loading from a .env file.

Preview

Thanks to rich-click, it also supports rich output for a better user experience:

Preview (rich)

Installation

With pipx

As a cli application, it is recommended to install execenv via pipx:

pipx install execenv

To enable rich output, use

pipx install execenv[rich]

With pip

Alternatively, you can install execenv via pip:

pip install execenv

# Or with rich output
pip install execenv[rich]

From Source

You might also want to install execenv from source.

This project uses poetry for dependency management. Make sure you have it installed before proceeding.

git clone https://github.com/zyf722/execenv.git
cd execenv/

poetry lock
poetry install

After that, you can run the application with:

poetry run execenv

Usage

This package contains three cli applications:

  • execenv: The main application.
  • execenv-completion: A completion utility to generate completion scripts for other shells.
  • execenv-echo: A simple application for testing, which prints out K-V pairs of all given environment variables.

Basic Usage

-e / --env

To run command with specific environment variables, you can pass them directly using the -e / --env flag:

execenv -e SHELL overwritten -e KEY VAL -- execenv-echo SHELL KEY

# Or put command before options
execenv execenv-echo SHELL KEY -e SHELL overwritten -e KEY VAL

# Output
# SHELL=overwritten
# KEY=VAL

-f / --file

Or you can load K-V pairs from a .env file (dotenv compatible syntax) using the -f / --file flag:

execenv -f .env -- execenv-echo KEY

# Output
# KEY=VAL

-c / --clear

By default, current environment variables will be preserved. You can override this behavior by using the -c / --clear flag:

execenv -c -- set

# Output differs on different platforms
#
# Note that for Windows with Python 3.10 and earlier,
# this command might not work as expected with an error with `CreateProcess`
# Check python/cpython#105436 for further information 

-a / --append-env & --append-separator

Use -a / --append-env to append value to variables instead of overwriting:

execenv -e KEY VAL -a KEY test -- execenv-echo KEY

# Output
# KEY=VAL;test (on Windows)
# KEY=VAL:test (on Linux / macOS)

# Also works with existing ones
execenv -a PATH test -- execenv-echo PATH

# Output
# PATH=%PATH%;test (on Windows)
# PATH=$PATH:test (on Linux / macOS)

By default os.pathsep is used as the separator when appending. You can change it by using --append-separator flag:

execenv --append-separator . -a KEY test -e KEY VAL -- execenv-echo KEY

# Output
# KEY=VAL.test

-s / --shell

Use -s / --shell to set shell=True to subprocess in order to use expansion, built-in commands, pipes, redirection and other shell features:

# Linux / macOS
execenv -e PATH overwritten -e KEY VAL -s -- echo EXECENV_PATH \$KEY

# Windows
execenv -e PATH overwritten -e KEY VAL -s -- echo EXECENV_PATH %KEY%

# Output
# overwritten VAL

-C / --cwd

Use -C / --cwd to set the working directory, and note that -s / --shell is not mandatory to use this option:

# Linux / macOS
execenv -C /home -- pwd

# Windows
execenv -C C:\ -s -- echo EXECENV_CD

# Output
# C:\ (on Windows)
# /home (on Linux / macOS)

Miscellaneous

-h / --help

Use -h / --help to get help information:

execenv -h

# Or simply without any flags and arguments
execenv

-V / --version

Use -V / --version to get the version information.

-v / -vv / --verbose

Use -v / -vv / --verbose to enable verbose mode, which is useful for debugging:

execenv -e SHELL overwritten -e KEY VAL -v -- execenv-echo SHELL KEY

Verbose

A header section will be added to the output to show details about execenv itself. Use -vv to show more information.

--config

Use --config to load configuration from a file. Note that config file itself is a valid .env file.

Default config file will be created after the first run at ~/.execenv.env on Linux / macOS and %USERPROFILE%\.execenv.env on Windows.

Refer to execenv/config.py to see all available configuration with their default values.

Auto Completion

Click Built-in Shells (Bash 4.4+, Zsh & Fish)

For shells supported by click, execenv will automatically setup tab completion after the first run (screenshot below is for Fish):

Auto Completion (fish)

You may restart or source your shell to enable the completion.

Other Shells

A completion utility execenv-completion will also be installed with execenv. You can use it to generate completion scripts for other shells:

execenv-completion

execenv-completion provides support for clink.

Auto Completion (clink)

You can install it by running:

execenv-completion -s clink [-p /path/to/your/script]

It will create a completions directory in the specified path (or the current directory if not provided) with the completion .lua script inside.

Contributing

Pull Requests are welcome!

It is strongly recommended to follow the Conventional Commits specification when writing commit messages and creating pull requests.

License

MIT

Metadata

Release files for execenv 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for execenv 0.1.1
File Size Uploaded Provenance
execenv-0.1.1.tar.gz 13.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for execenv 0.1.1
File Interpreter ABI Platform
execenv-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / execenv-0.1.1.tar.gz

Download URL execenv-0.1.1.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6ef4d6f1c41f37cc0cc65732a175fa8f20800e91cb6e86e1d925d8b007e6f15f
BLAKE2b-256 checksum
How to use checksums
1c4ead8cc74571b74dfdbf9a71185bea55f4cf2442a32ac2ce2bb7df3a66ef2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure

Release files / execenv-0.1.1-py3-none-any.whl

Download URL execenv-0.1.1-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
adf1f747dfa9067f62d023add9a913c3408b551ac85e24e141996ad3339cfbd1
BLAKE2b-256 checksum
How to use checksums
31da4f22a9d0a6e6d085cf12f7dbde860b4a08a77db6665bcf060c1a753dff8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure

Security for execenv 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page