Skip to content

illinois-cs241/flagset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlagSet

Build Status Coverage Status License Python Versions

A Python module for managing flags across environment variables, commandline arguments, and configuration files

Dependencies

See requirements_test.txt for test dependencies The package itself doesn't have any dependencies on third-party packages

Usage

pip install git+https://github.com/illinois-cs241/flagset

Create a FlagSet object

fset = FlagSet(
    {
        "debug": Flag(
            bool,
            default=False,
            cmdline_name=["-d", "--debug"],
            help="enable debug mode",
        ),
        "token": Flag(
            str,
            required=True,
            cmdline_name="--token",
            help="access token",
        ),
        "bind_addr": Flag(
            str,
            default="localhost:8080",
            cmdline_name="--bind-addr",
            env_name="BIND_ADDR",
            help="web app bind address",
        ),
        "mongodb_dsn": Flag(
            str,
            default="mongodb://localhost:27017",
            config_name="some.path.in.the.config",
            help="mongodb",
        ),
    }
)

Then parse the given flags and config(args defaults to sys.argv[1:] and env defaults to os.environ)

config = fset.parse(args=[...], env={...}, ...)