Skip to main content

sleazy

A tiny utility to build CLI tools from Python TypedDict schemas.
Define your parameters with type hints (and Annotated for positionals), then call parse() to get a typed dict and stringify() to turn it back into args.

Installation

uv pip install sleazy

Example CLI

from typing import Annotated, Literal, TypedDict
from sleazy import parse, stringify


class AppConfig(TypedDict):
    # 1) Required positional (exactly one string)
    input_file: Annotated[str, 1]

    # 2) Optional positional (zero or more strings)
    tags: Annotated[str, "*"]

    # 3) Optional keyword args
    output: str  # string
    verbose: bool  # flag
    retries: int  # integer
    mode: Literal["auto", "manual"]  # choice via Literal or enum


if __name__ == "__main__":
    # parse() returns a dict matching AppConfig
    args = parse(AppConfig) # python example.py data.txt tag1 tag2 --output out.txt --verbose --retries 5 --mode auto
    print(args)
    # {
    #   'input_file': 'data.txt',
    #   'tags': ['tag1', 'tag2'],
    #   'output': 'out.txt',
    #   'verbose': True,
    #   'retries': 5,
    #   'mode': 'auto'
    # }

    # stringify back to CLI args, using AppConfig to keep positionals first
    print(stringify(args, AppConfig))
    # [
    #   'data.txt',
    #   'tag1', 'tag2',
    #   '--output', 'out.txt',
    #   '--verbose',
    #   '--retries', '5',
    #   '--mode', 'auto'
    # ]

    # Without the TypedDict, stringify treats everything as flags
    print(stringify(args))
    # [
    #   '--input-file', 'data.txt',
    #   '--tags', 'tag1', '--tags', 'tag2',
    #   '--output', 'out.txt',
    #   '--verbose',
    #   '--retries', '5',
    #   '--mode', 'auto'
    # ]

Notes

  • Positionals are marked via Annotated[type, count] (1, ?, *, +, or exact integer).
  • All other fields become --field-name flags by default.
  • It's useful to pass your TypedDict type to stringify() so it knows which fields are positional (and their order). Without it, everything is emitted as a keyword flag.

Metadata

Release files for sleazy 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sleazy 0.2.0
File Size Uploaded
sleazy-0.2.0.tar.gz 42.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sleazy 0.2.0
File Interpreter ABI Platform
sleazy-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.8 kB

Release files / sleazy-0.2.0.tar.gz

Download URL sleazy-0.2.0.tar.gz
Size 42.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7499177079a60a112510416a55d24536808ebc6f4a371ff5aec5cb6675ef98a2
BLAKE2b-256 checksum
How to use checksums
163e453c16b308d0e95fdc9039ef2e3d76678eef2e0d91045b0e975727a7414d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / sleazy-0.2.0-py3-none-any.whl

Download URL sleazy-0.2.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3a56ee770a80f84b8f4a0398d72f96abe3583cfd31ac1d381cf70f66346d636
BLAKE2b-256 checksum
How to use checksums
214ee666300efdd52f347c80c595e118fff110650eecc269d27ec3206cd57145
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page