argparsenv
This project extends python's argparse module to allow for environment variable overrides of command line arguments.
The rule for environment variable overrides is as follows:
- If the argument is provided on the command line, the environment variable is ignored.
- If the argument is not provided on the command line, the environment variable is used if it is set.
- If the argument is not provided on the command line and the environment variable is not set, the default value is used.
- If the argument is environment variable is set both on the command line and in the environment, the command line value is used.
Installation
Stable release version:
pip install argparsenv
Latest development version:
pip install git+https://github.com/snaeil/argparsenv
Usage
This module builds on top of python's standard library argparse.
import argparsenv
env_arg_parser = ArgumentParser()
env_arg_parser.add_argument(
"--port",
dest="port",
env_var="MY_APP_DB_PORT",
default="3306",
)
With this ArgumentParser instance, the port argument can be set in three ways:
- On the command line:
python my_app.py --port 3307
- As an environment variable (this can also be done by using a
.envfile):
export MY_APP_DB_PORT=3307
python my_app.py
- Using the default value (here
3306):
python my_app.py
Contributing
Contributions are welcome! For feature requests, bug reports or questions, please open an issue. For code contributions, please open a pull request.
The development environment can be set up using nix and devenv:
- Install nix package manager:
bash <(curl -L https://nixos.org/nix/install) --no-daemon - Make sure, your
~/.config/nix/nix.confcontains the following lines:experimental-features = nix-command flakes
- Install
devenvby running:nix profile install --accept-flake-config 'nixpkgs#devenv'
- Install nix-direnv by running:
nix profile install 'nixpkgs#nix-direnv'
Then add nix-direnv to$HOME/.config/direnv/direnvrc:source $HOME/.nix-profile/share/nix-direnv/direnvrc
- Hook direnv into your shell by adding a line to your shell's configuration file (e.g.
~/.bashrc), as described in the direnv documentation: - You might have to open a new shell to make the changes take effect.
Metadata
Release files for argparsenv 1.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| argparsenv-1.0.14.tar.gz | 62.2 kB | With provenance | Details for argparsenv-1.0.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| argparsenv-1.0.14-py3-none-any.whl | Python 3 | none | any | Details for argparsenv-1.0.14-py3-none-any.whl |
Total release size: 66.5 kB
Release files / argparsenv-1.0.14.tar.gz
| Download URL | argparsenv-1.0.14.tar.gz |
|---|---|
| Size | 62.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67c437dd68e6726be13e1673bef2f41132c49dbdee4e9e362c3ea915bb22da60
|
|
BLAKE2b-256 checksum How to use checksums |
38f9bba8115b671bc4b06b15de24d39ca304095f1faa8fdec68cb0d1a7257fa6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / argparsenv-1.0.14-py3-none-any.whl
| Download URL | argparsenv-1.0.14-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d13a7e8068c80297202977699aa7104b651ffac26143a28986ab4fe28a9f0942
|
|
BLAKE2b-256 checksum How to use checksums |
1d0419d72fd8a02dad8c3a48f6d1d448e8b00687e94e8ea35406ed6584e2bb3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for argparsenv 1.0.14
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for argparsenv-1.0.14.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA 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.