Metadata-Version: 2.1
Name: hyperparse
Version: 0.0.4
Summary: Parse shell env variables to python dict
Home-page: https://github.com/fuzihaofzh/hyperparse
Author: 
Author-email: 
License: UNKNOWN
Keywords: Shell env
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.7
Description-Content-Type: text/markdown

# Hyperparse : A Simple Shell Environment Variables Parser 

## Introduction
This script provides a way to parse environment variables and use them as hyperparameters in Python scripts.

The script parses a string that contains a comma-separated list of key-value pairs, where each key-value pair is separated by an equal sign (=). The keys should be strings, and the values can be integers, floats, lists of integers or floats, booleans, or None. The script can handle values that are enclosed in single or double quotes.

The script also provides a set_hyper function that allows you to set the variables in your Python script. You can pass in a dictionary of hyperparameters and a namespace or dictionary of arguments. The function will update the namespace or dictionary with the hyperparameters.


## Usage
First set a variable in shell and run the python file `main.py`.
```bash
export usermode="a=1,b,c=[1,2,3],d=4,e=3.2,f=itud,g=False"
python main.py
```

### Parse variables
```python
# main.py
from hyperparser import get_hyper
usermode = get_hyper("usermode")
print(usermode)
# {"a": 1, "b": None, "c": [1, 2, 3], "d": 4, "e": 3.2, "f": "itud"}
```

### Reset argparse elements

```python
# main.py
from hyperparse import get_hyper, set_hyper
usermode = get_hyper("usermode")
parser = argparse.ArgumentParser()
parser.add_argument('--a', type=int, default=5)
parser.add_argument('--f', type=str, default="hello")
args = parser.parse_args()
set_hyper(usermode, args)
print(args) # Namespace(a=1, f='itud')
```

### Reset Local Variables
```python
# main.py
from hyperparse import get_hyper, set_hyper
usermode = get_hyper("usermode")
a = 5
f = "stk"
set_hyper(usermode)
print(a) # 1
print(f) # itud
```# hyperparse


