Ultra-light command-line argument grabber for quick scripts
Project description
TinyArgs
A micro command-line argument helper for tiny Python scripts.
TinyArgs gives you the 80/20 of CLI parsing in a few functions—no boilerplate, no dependencies. It’s perfect for quick utilities where argparse or click feel like overkill.
✨ Features
- Parse flags in 1–3 lines instead of 20+
- Accepts both
--key valueand--key=value - Types, defaults, and required args
- Simple boolean flags via
flag("--debug") - Minimal, readable API built on
sys.argv - Zero dependencies, tiny footprint
📦 Installation
Add tinyargs.py to your project (or install from your own distribution, if you publish it). Then:
from tinyargs import args, get, flag, TinyArgsError
Tip: If you prefer a package layout, place the code in a module (e.g.,
tinyargs/__init__.py) and install locally withpip install -e ..
🚀 Quick Start
Single value with type, default, and required
# script.py
from tinyargs import get, TinyArgsError
try:
port = get("--port", type=int, default=8000)
host = get("--host", default="127.0.0.1")
api_key = get("--api-key", required=True) # raises TinyArgsError if missing
print(host, port, api_key)
except TinyArgsError as e:
print(f"Error: {e}")
raise SystemExit(2)
Run it:
python script.py --host 0.0.0.0 --port=8080 --api-key secret
Boolean flag
from tinyargs import flag
verbose = flag("--verbose") # True if provided, else False
CLI:
python script.py --verbose
Unpack multiple at once
from tinyargs import args
name, age = args(
"--name", "--age",
types={"--age": int},
defaults={"--age": 18}
)
print(name, age)
Run:
python script.py --name Alice --age=21
🧠 API Reference
get(key, type=str, default=None, required=False)
Fetch a single argument.
-
Parameters
key(str): e.g.,"--host".type(type): caster for the value. Defaults tostr. Useint,float,bool, etc.default(Any): returned when the key is not present (unlessrequired=True).required(bool): ifTrueand the key is missing, raisesTinyArgsError.
-
Returns: casted value or default.
-
Raises:
TinyArgsErrorif a required key is missing or casting fails.
⚠️ Note on booleans
If you set type=bool and pass the flag without a value (e.g., --flag), TinyArgs returns True.
If you pass --flag false, Python’s bool("false") is True—avoid that style.
flag(key)
Shorthand for boolean flags.
- Returns:
Trueif--keyappears on the command line, elseFalse.
args(*keys, types=None, defaults=None, required=None)
Fetch multiple arguments in one call and unpack them.
-
Parameters
*keys(str): e.g.,"--name", "--age".types(dict): optional per-key type mapping, e.g.{"--age": int}.defaults(dict): default values per key.required(list[str]): keys that must appear.
-
Returns: tuple of parsed values in the same order as keys.
-
Raises:
TinyArgsErrorif a required key is missing or a cast fails.
⚠️ Error Handling
All errors raise TinyArgsError with a descriptive message. Wrap calls in try/except for robustness.
🤝 Contributing
Contributions welcome!
Open an issue or PR with improvements, bug fixes, or new features.
📜 License
MIT License. See LICENSE for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tinyargs-0.1.1.tar.gz.
File metadata
- Download URL: tinyargs-0.1.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
192cedf1a881c0fc8d760bdb63cafdf34b9ae9603960d3203fad73565350b78e
|
|
| MD5 |
84e0c9abf0263d7a56fbd7e7395e622c
|
|
| BLAKE2b-256 |
52f043952530d8914285b029e41b7d84010c2fa5722bde0f96e0d099a7a1f8d5
|
File details
Details for the file tinyargs-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tinyargs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77ba5e76fcfa5105adb073f80b1728f6584dd33ba076e2476af29034edfc4036
|
|
| MD5 |
78553a340f3fb022f97352fc2e7aa22c
|
|
| BLAKE2b-256 |
8dd1d5f687d9c2b44b4d3139a49b5e4dd358772ea8624586282a8a67cb6848b0
|