A convenience DSL layer over the `argparse` package.
Project description
argsl️
argsl is for everybody who finds argparse too verbose.
argsl (“args DSL” / “argparse DSL”) lets you define CLI arguments in a tiny DSL and get an argparse.Namespace back — with types, defaults, and optional --help text.
from argsl import argsl
args = argsl("""
filename <path> # positional file/path
--name|-n <str!> # required option
--debug|-d <flag> # boolean switch
""")
…instead of writing argparse boilerplate.
- Expressive: one line per argument
- No boilerplate: returns
argparse.Namespace(parsed fromsys.argv) - Typed:
int,float,str,path,bool,flag,choice - Compatible with argparse: wraps it internally
Installation
Using uv (recommended)
uv add argsl
Or with pip
pip install argsl
Basic Example
from argsl import argsl
args = argsl("""
filename <path> # positional file/path
--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> # store_true flag; app decides semantics
""")
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
DSL Format
Each non-empty line describes one argument:
<flags or positional> <type-expression> [# help text]
Examples:
- Positional:
filename <path>
- Long option only:
--count <int=3>
- Long + short option:
--name|-n <str!>
Flags / option names
- Use
--longfor long options and-sfor short options. - Combine long and short options with
|without spaces:--name|-n <str!>--name | -n <str!>(avoid spaces around|)
Inline help text with #
If a line contains #, everything after the first # becomes the help= text passed to argparse.
args = argsl("""
--debug|-d <flag> # Enable debug logging
""")
Notes (current behavior):
- The split is done on the first
#anywhere in the line. - Help text is trimmed (
strip()). - Lines starting with
#are ignored. #is not quote-aware. If you put#inside a quoted default (e.g.<str="a#b">), it will still be treated as the start of help text.
Supported Type Expressions
Type expressions live inside <...>.
Built-in types
| DSL | Meaning | argparse behavior |
|---|---|---|
<str> |
string value | type=str |
<int> |
integer value | type=int |
<float> |
float value | type=float |
<path> |
filesystem path | type=pathlib.Path |
<bool> |
boolean value from a string | parses 1/true/yes (case-insensitive) |
<flag> |
boolean flag | action="store_true" (default False, becomes True if present) |
Required (!)
!marks named options as required:--name <str!>→required=True
- For positionals,
argparsealready requires them by default, so!is effectively redundant.
Defaults (=)
You can provide defaults with =.
--count <int=3>
--title <str="hello world">
Defaults are parsed with ast.literal_eval when possible (numbers, quoted strings, etc.). If parsing fails, the raw string is used.
Environment fallback (=env:VAR)
Use an environment variable as a default:
--user <str=env:USER>
--home <path=env:HOME>
This sets default=os.getenv("VAR") (which may be None if the variable is unset).
Multiple values (*)
Add * to accept one or more values:
--list <str*>
This maps to nargs="+".
Choices (choice:)
Restrict input to a fixed set of strings:
--level <choice:low,med,high>
You can also set a default using =:
--level <choice:low,med,high="med">
--level <choice:low,med,high=med>
(Choices are always treated as strings.)
Supported Flag Variants
args = argsl("""
--user|-u <str!> # short + long
--only <int=1> # long-only option
--debug <flag> # store_true
--no-cache <flag> # store_true; app interprets as "disable cache"
""")
Test Coverage & Edge Cases
Covered in tests (see tests/test_argsl.py and tests/test_argsl_all.py):
- 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 and short+long (
--onlylong,--msg|-m) - choice types + defaults (
--level <choice:low,med,high="med">)
Development Workflow
Using uv:
uv add .[dev]
uv add '.[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/ # remove old builds (PyPI rejects re-uploads)
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.4.tar.gz.
File metadata
- Download URL: argsl-0.1.4.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36f188af7dc40e711ea8d7b8c9150c71a1cfe7c7e1dc9a0355983f0ffe6e1116
|
|
| MD5 |
fe051a5e69426b008e8411b410352d5c
|
|
| BLAKE2b-256 |
2f549b838d3236b09d7f99fa3e0f70b89d72b7eef7536bd266e82dac76ec4579
|
File details
Details for the file argsl-0.1.4-py3-none-any.whl.
File metadata
- Download URL: argsl-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c937d812849c20db2ed23b8d43dd9b4502ce8a415eb31a15cdabdc223270f05
|
|
| MD5 |
fdbdd0b6104228cf4ac8f0915ded0b53
|
|
| BLAKE2b-256 |
dedf61e9481a2874575ab821877c58055f8932d797f45fd7756f5ad723b5ea71
|