A readable DSL on top of argparse
Project description
argsl️
argsl is for everybody who finds argparse too verbose.
argsl (args DSL or argparse DSL) allows you to specify your CLI flags
and arguments with a succinct notation
(and at the same time specifying the --help text!).
args = argsl("""
filename <path!> # required positional
--name <str!> # required flag
--debug <flag> # boolean switch
""")
instead of:
# argparse version
parser = argparse.ArgumentParser()
parser.add_argument("filename", type=pathlib.Path)
parser.add_argument("--name", required=True)
parser.add_argument("--debug", action="store_true")
- ✅ Expressive: just describe your arguments
- ✅ No boilerplate: get
argparse.Namespacedirectly - ✅ Typed and validated: int, float, str, path, bool, choices, etc.
- ✅ Compatible with argparse: wraps it internally
Installation
Using uv (recommended):
uv pip install argsl
Or with pip:
pip install argsl
🚀 Basic Example
from argsl import argsl
args = argsl("""
filename <path!> # required positional
--name|-n <str=env:USER> # optional with env fallback
--level|-l <choice:low,med,high="med"> # choice with default
--debug|-d <flag> # boolean flag
--onlylong <int=1> # long-only argument
--no-cache <flag> # negate behavior if passed
""")
print(vars(args))
In your pyproject.toml:
[project.scripts]
run = "main:main"
Run it:
uv run run file.txt --name Alice --debug --level high --no-cache
Supported Argument Types
| DSL Expression | Description |
|---|---|
<str>, <int>, <float> |
Single typed argument |
<path> |
File/path via pathlib.Path |
<flag> |
Boolean flag (false unless present) |
<str!> |
Required string argument |
<int=42> |
With default value |
<choice:a,b,c="b"> |
Choice + default |
<str*> |
Accept multiple values |
=env:VAR |
Fallback to environment variable |
Supported Flag Variants
args = argsl("""
--user|-u <str!> # short + long
--only <int=1> # long-only
--debug <flag> # long-only boolean flag
--no-cache <flag> # negated logic: default False → True if passed
""")
Test Coverage & Edge Cases
✔ Required positional + typed
✔ Required named args (--foo <str!>)
✔ Optional args with defaults (--bar <int=42>)
✔ Multiple values (--list <str*>)
✔ Boolean flags (--debug <flag>)
✔ Env fallback (--x <str=env:HOME>)
✔ Quoted defaults (--title <str="The Answer">)
✔ Long-only or short+long (--onlylong, --msg|-m)
✔ Choice types (--level <choice:low,med,high="med">)
✔ All covered in tests/test_argsl_all.py
Development Workflow
uv pip install .[dev]
uv pip install '.[dev]' # on zsh (macos)
uv run test
Or with classic tools:
pip install -e .[dev]
pip install -e '.[dev]' # on zsh (macos)
pytest
Publishing to PyPI
rm -rf dist/ # necessary - otherwise PyPI would upload old version, too, resulting in an error
uv build
uv publish
MIT licensed • Built by Gwang-Jin Kim
Project details
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 argsl-0.1.3.tar.gz.
File metadata
- Download URL: argsl-0.1.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2f9789770450613551209db43cbbaeadd7c8356e17f61befa8cf14537e2e8ea
|
|
| MD5 |
77c7c6da4e1212842ccaa64f19a4e3c2
|
|
| BLAKE2b-256 |
3e6aec20b5e12062b3ac7d39e17266d6d40d3a4a87a3aa640c4cb3793531338f
|
File details
Details for the file argsl-0.1.3-py3-none-any.whl.
File metadata
- Download URL: argsl-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
785a0d3419037b0b905d06d575ef886b35a215fe997ef22a12dbf1dc99de96c8
|
|
| MD5 |
784ca1d97849d55118c9172b5c48c550
|
|
| BLAKE2b-256 |
04bd3d950ce90cfcd3b02f8a8600cf94b9e855233250da74adcfdd00dd50fcb9
|