Skip to main content

An argpase that can take values from the environment.

Project description

argparse-env - argparse with environment

Use this package when you want to be able to set arguments wither at the command line or through environment variables.

from argparse_env import EnvArgumentParser

parser = EnvArgumentParser(env_prefix="MYAPP")
parser.add_argument
>>> from argparse_env import EnvArgumentParser
>>> parser = EnvArgumentParser(env_prefix='MYAPP')
>>> parser.add_argument("--hello", type=str, default="Alex" help="Say hello to.")
>>> parser.parse_args(["--hello", "Jane"])
Namespace(hello='Jane')
>>> parser.parse_args([])
Namespace(hello=Alex)
>>> import os
>>> os.environ["MYAPP_HELLO"] = "Jim"
>>> parser.parse_args([])
Namespace(hello='Jim')
>>> parser.parse_args(["--hello", "Jane"])
Namespace(hello='Jane')

argparse Feature Support

There are some extras added to the class to support argparse features from environment variables.

nargs

Provide arguments with nargs != 1 using a comma-separated list in an environment variable.

MYAPP_NARGS_MANY=arg1,arg2,arg3

store true/false

Use true, 1, or on for True or false, 0, or off for False.

MYAPP_STORE_FALSE=false
MYAPP_STORE_FALSE=off
MYAPP_STORE_TRUE=true
MYAPP_STORE_TRUE=1

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

argparse_env-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

argparse_env-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file argparse_env-0.1.0.tar.gz.

File metadata

  • Download URL: argparse_env-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for argparse_env-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c965f41480248830bda844abb6ee08b89bbbc8fffb2e7a523e4834c7081d4cb
MD5 b65bc6532d989f6c7430138f32df3a03
BLAKE2b-256 b15766853071af4a4c39f0c03daabb89f690d8f4f3d05adaad36578293d729d8

See more details on using hashes here.

File details

Details for the file argparse_env-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for argparse_env-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab9e98ff29eff90a03b757403e381db6ba5ff24f97c26364fd94fab38187c0fe
MD5 340ec0d86338e139211e11bd18fab6ca
BLAKE2b-256 2f63bc271e66d51a9cb0917c2836602dd0559aa6959da1ac237ac594c6bc7301

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