Parse environment variables and CLI arguments for a given function signature.
Project description
Argmagic
Based on a idea by @lbb.
Automatically generate argparse based env-var/CLI-interface from a given function.
Example:
Given a function with a docstring and type hints.
def hello(name: str):
'''
Say hello to name.
Args:
name: Your name.
Raises:
Nothing.
Returns:
Nothing.
'''
print('Hello', name)
Create a CLI interface:
argmagic(hello)
Argmagic will call the function with all parameters filled from CLI arguments.
$ ./hello.py -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.py
Hello test
These can then again be overriden by CLI arguments.
$ NAME=test hello.py --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}
Alternatives
click uses decorators
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file argmagic-1.0.1.tar.gz
.
File metadata
- Download URL: argmagic-1.0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdebda19fd8cb8f44d4d4a4d65a20bf02105da638c2d8cf1cfce6a658147bdfc |
|
MD5 | 3ca6bd314e40a9f6ad823ea7acf34975 |
|
BLAKE2b-256 | 18d242aa2c03d99000786488338935bf4e4b0f84479fe473bd85788d5a1c955a |
File details
Details for the file argmagic-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: argmagic-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5069fad4940a699e51f5750f47c27f2b5668de979c767eca2b13b9cc9ced2ba |
|
MD5 | 19db4292a259574ab744081847afa7b7 |
|
BLAKE2b-256 | c88afcbfda45ab674a2c76af2d9e9192841de2f7e01272af412e90320513d1ef |