Skip to main content

A readable DSL on top of argparse

Project description

argsl️

A clean and readable DSL for building command-line interfaces in Python — without the boilerplate.

argsl is for developers who want fast, expressive CLI definitions using just a few lines of text.


Why use argsl?

Python’s built-in argparse is powerful but verbose:

# 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")

With argsl:

args = argsl("""
filename <path!>         # required positional
--name <str!>            # required flag
--debug <flag>           # boolean switch
""")
  • 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.2.tar.gz (4.9 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.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file argsl-0.1.2.tar.gz.

File metadata

  • Download URL: argsl-0.1.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for argsl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f471d9ef103474e049e50f3ca190918b67cd3a488e4fbe2c5202ecdfc6c7bd3d
MD5 8667fc781cc55f9b0f1332fe81dbd9c5
BLAKE2b-256 01432a15791b32500e65ff0fe7024c9f7233f0f6dad14bbc5109239ceff3797c

See more details on using hashes here.

File details

Details for the file argsl-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: argsl-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for argsl-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 868fa579896bc99b5648b940dccdf101e03ef2790139b264b2e29cd645a2e40d
MD5 2e78200414ecd206018d442f723d017c
BLAKE2b-256 f97de2a011ae5677134dedf9c18b92fd07e105d090f76dfde8140b9202cf63cd

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