Skip to main content

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.Namespace directly
  • 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

argsl-0.1.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

argsl-0.1.3-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for argsl-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f2f9789770450613551209db43cbbaeadd7c8356e17f61befa8cf14537e2e8ea
MD5 77c7c6da4e1212842ccaa64f19a4e3c2
BLAKE2b-256 3e6aec20b5e12062b3ac7d39e17266d6d40d3a4a87a3aa640c4cb3793531338f

See more details on using hashes here.

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

Hashes for argsl-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 785a0d3419037b0b905d06d575ef886b35a215fe997ef22a12dbf1dc99de96c8
MD5 784ca1d97849d55118c9172b5c48c550
BLAKE2b-256 04bd3d950ce90cfcd3b02f8a8600cf94b9e855233250da74adcfdd00dd50fcb9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page