Hyperparse
A simple and powerful parser for shell environment variables and command line arguments.
Installation
pip install hyperparse
Quick Start
from hyperparse import parse_string
config = parse_string('lr=1e-4,batch=32,model={name:bert,layers:12}')
print(config.lr) # 0.0001
print(config.batch) # 32
print(config.model.name) # 'bert'
Supported Types
| Type | Example | Result |
|---|---|---|
| Integer | a=1 |
1 |
| Negative | a=-1 |
-1 |
| Float | a=3.14 |
3.14 |
| Scientific | a=1e-5 |
0.00001 |
| Boolean | a=True |
True |
| None | a=None or a |
None |
| String | a=hello |
'hello' |
| List | a=[1,2,3] |
[1, 2, 3] |
| Nested List | a=[[1,2],[3,4]] |
[[1, 2], [3, 4]] |
| Dict | a={x:1,y:2} |
{'x': 1, 'y': 2} |
| Nested | a={x:[1,2],y:{z:3}} |
{'x': [1, 2], 'y': {'z': 3}} |
Attribute Access
Parse results support both dict-style and attribute-style access:
config = parse_string('a=1,b={x:2,y:3}')
# Dict style
config['a'] # 1
config['b']['x'] # 2
# Attribute style
config.a # 1
config.b.x # 2
Check Key Existence
config = parse_string('a=1,b=2,c=3')
# Check if all keys exist
config.hasall('a', 'b') # True
config.hasall('a', 'x') # False
# Check if any key exists
config.hasany('a', 'x') # True
config.hasany('x', 'y') # False
Environment Variables
export usermode="lr=1e-4,batch=32,epochs=10"
python main.py
from hyperparse import parse, reset_hyper
usermode, _ = parse("usermode")
print(usermode.lr) # 0.0001
print(usermode.batch) # 32
Argparse Integration
from hyperparse import parse, reset_hyper
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--lr', type=float, default=0.01)
parser.add_argument('--batch', type=int, default=16)
args = parser.parse_args()
usermode, _ = parse("usermode")
reset_hyper(usermode, args)
print(args.lr) # 0.0001 (overridden by env)
print(args.batch) # 32 (overridden by env)
Local Variables
from hyperparse import parse, reset_hyper
lr = 0.01
batch = 16
usermode, _ = parse("usermode")
reset_hyper(usermode)
print(lr) # 0.0001
print(batch) # 32
API Reference
parse_string(s)
Parse a string into an AttrDict.
parse(name)
Parse from environment variable or command line argument.
reset_hyper(hyper, pargs=None)
Update argparse namespace or local variables with parsed values.
AttrDict
Dict subclass with attribute access and helper methods:
.hasall(*keys)- True if all keys exist.hasany(*keys)- True if any key exists
License
MIT
Metadata
Release files for hyperparse 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hyperparse-0.0.9.tar.gz | 5.9 kB | Without provenance | Details for hyperparse-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hyperparse-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for hyperparse-0.0.9-py3-none-any.whl |
Total release size: 12.8 kB
Release files / hyperparse-0.0.9.tar.gz
| Download URL | hyperparse-0.0.9.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3cc56c278b91d0f62558799b4351c13aa284f791cd42bf04930157bbb99fede6
|
|
BLAKE2b-256 checksum How to use checksums |
421481aaeba5a6a433b5673befedb20701c2e3f2930e305d13ac0a9bab68ae9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / hyperparse-0.0.9-py3-none-any.whl
| Download URL | hyperparse-0.0.9-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d73b162ebff51ba4f485bea7c5fd90c4be598dc5f972d1724082eeaa175ba715
|
|
BLAKE2b-256 checksum How to use checksums |
0dc4920ec255e3bdd75419c3374149b05ed7d0da705bd05816df05ecbee4e04c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for hyperparse 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.