hyperparse


Namehyperparse JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/fuzihaofzh/hyperparse
SummaryParse shell env variables to python dict
upload_time2023-09-24 16:59:21
maintainer
docs_urlNone
author
requires_python
license
keywords shell env
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fuzihaofzh/hyperparse",
    "name": "hyperparse",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Shell env",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/9d/df/f95e208832755d999d419ec3407da0b1388e27fdae284df07dce09e75915/hyperparse-0.0.6.tar.gz",
    "platform": null,
    "description": "# Hyperparse : A Simple Shell Environment Variables Parser \n\n## Introduction\nThis script provides a way to parse environment variables and use them as hyperparameters in Python scripts.\n\nThe 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.\n\nThe 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.\n\n\n## Usage\nFirst set a variable in shell and run the python file `main.py`.\n```bash\nexport usermode=\"a=1,b,c=[1,2,3],d=4,e=3.2,f=itud,g=False\"\npython main.py\n```\n\n### Parse variables\n```python\n# main.py\nfrom hyperparser import get_hyper\nusermode = get_hyper(\"usermode\")\nprint(usermode)\n# {\"a\": 1, \"b\": None, \"c\": [1, 2, 3], \"d\": 4, \"e\": 3.2, \"f\": \"itud\"}\n```\n\n### Reset argparse elements\n\n```python\n# main.py\nfrom hyperparse import get_hyper, set_hyper\nusermode = get_hyper(\"usermode\")\nparser = argparse.ArgumentParser()\nparser.add_argument('--a', type=int, default=5)\nparser.add_argument('--f', type=str, default=\"hello\")\nargs = parser.parse_args()\nset_hyper(usermode, args)\nprint(args) # Namespace(a=1, f='itud')\n```\n\n### Reset Local Variables\n```python\n# main.py\nfrom hyperparse import get_hyper, set_hyper\nusermode = get_hyper(\"usermode\")\na = 5\nf = \"stk\"\nset_hyper(usermode)\nprint(a) # 1\nprint(f) # itud\n```# hyperparse\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Parse shell env variables to python dict",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/fuzihaofzh/hyperparse"
    },
    "split_keywords": [
        "shell",
        "env"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b9775fa55430308e384bbfe74745b0b1d1ad1610a5c62c34149c8659888544c8",
                "md5": "9eccd4c1b14c7e667762058ac3c5c9d3",
                "sha256": "0555a3546a354c9f0ce9dec67a44f8c8c22fa5d7e4326fdd08ff3a8d4542a591"
            },
            "downloads": -1,
            "filename": "hyperparse-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9eccd4c1b14c7e667762058ac3c5c9d3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3464,
            "upload_time": "2023-09-24T16:59:19",
            "upload_time_iso_8601": "2023-09-24T16:59:19.342883Z",
            "url": "https://files.pythonhosted.org/packages/b9/77/5fa55430308e384bbfe74745b0b1d1ad1610a5c62c34149c8659888544c8/hyperparse-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ddff95e208832755d999d419ec3407da0b1388e27fdae284df07dce09e75915",
                "md5": "04c4859794f5f43132e8729db663be1f",
                "sha256": "6c9755573da39ff0cedaab19a8a525ec9d88f6342be90a87ea0a5eaf3973b81a"
            },
            "downloads": -1,
            "filename": "hyperparse-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "04c4859794f5f43132e8729db663be1f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3447,
            "upload_time": "2023-09-24T16:59:21",
            "upload_time_iso_8601": "2023-09-24T16:59:21.821011Z",
            "url": "https://files.pythonhosted.org/packages/9d/df/f95e208832755d999d419ec3407da0b1388e27fdae284df07dce09e75915/hyperparse-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-24 16:59:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fuzihaofzh",
    "github_project": "hyperparse",
    "github_not_found": true,
    "lcname": "hyperparse"
}
        
Elapsed time: 1.45583s