Skip to main content

Utilizes environment variables in argparse

Project description

Utilizes environment variables in argparse

Installation

To install gatsby-envarg, simply:

$ sudo pip install gatsby-envarg

API Reference

required_or_default_from_env

>>> import argparse
>>> from gatsby_envarg import *
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-u', '--url',
>>>     action=required_or_default_from_env('URL'))
If expected variable is set in environment,
then argument is NOT required and default value is set with the value in the environment variable.
>>> import argparse
>>> from gatsby_envarg import *
>>> parser = argparse.ArgumentParser()
>>> p = parser.add_argument('-u', '--url', action=required_or_default_from_env('URL'))
>>> print(p.required)
>>> True
>>> print(p.default)
>>> None
If expected variable is NOT set in environment,
then argument is not required.
>>> import argparse, os
>>> from gatsby_envarg import *
>>> os.environ['URL'] = 'abc.com'
>>> parser = argparse.ArgumentParser()
>>> p = parser.add_argument('-u', '--url', action=required_or_default_from_env('URL'))
>>> print(p.required)
False
>>> print(p.default)
'abc.com'

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
gatsby-envarg-1.0.3.tar.gz (1.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page