Skip to main content

Parse environment variables and CLI arguments for a given function signature.

Project description


Based on a idea by @lbb.

Automatically generate argparse based env-var/CLI-interface from a given function.


Given a function with a docstring and type hints.

def hello(name: str):
    Say hello to name.

        name: Your name.


    print('Hello', name)

Create a CLI interface:


Argmagic will call the function with all parameters filled from CLI arguments.

$ ./ -h
usage: hello [-h] [--name NAME]

Say hello to name.

optional arguments:
  -h, --help   show this help message and exit
  --name NAME  Your name.

Additionally all specified parameters can also be defined via environment variables.

$ NAME=test
Hello test

These can then again be overriden by CLI arguments.

$ NAME=test --name something
Hello something

Support of composite types

Current parsing of lists, tuples and unions are supported.

For example a typehint containing List[str], will parse input [a, b, c] to a python list containing ["a", "b", "c"].

Also these types can be arbitrarily nested, such as Dict[str, List[int]] will correctly parse strings of structure {a: [1, 2, 3], b: [5, 3]}.

Syntax overview:

Tuple syntax:
(a, b, c)

List syntax:
[a, b, c]

Dict syntax:
{a: i, b: j, k: l}


click uses decorators

Project details

Download files

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

Files for argmagic, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size argmagic-1.0.1-py3-none-any.whl (6.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size argmagic-1.0.1.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page