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.2.tar.gz (2.8 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.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for argparse_env-0.1.2.tar.gz
Algorithm Hash digest
SHA256 da5465ecbe4f38c16a2613757a1a9ce829b9d2549c4630f88b29567264d05cf5
MD5 609568da663b4e9b2d23247399038a0c
BLAKE2b-256 258e0eca49661e571ceb3f70383563299a148d7b58b7532565abe52679258e81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for argparse_env-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cc5b78bfb59b4f8eeac08b6baa1d7b8bea82ad104dd03d2fada132cc322b8dc5
MD5 170225f92c8bcd775285873255928680
BLAKE2b-256 279eaa7e625979e27a7b6a9b56bade768b888663eed30b1b92bbb47be03c25d4

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