Skip to main content

bicker

PyPI Python CI

Tiny, fully typed CLI argument parser: declare your args as a class.

pip install bicker

No dependencies.

Usage

from typing import Literal

from bicker import flag, opt, parse_args, pos


class Args:
    src: str = pos(description="Image to resize")
    dst: str = pos("out.png", description="Where to save it")
    width: int = opt(required=True, short="-w", metavar="PX", description="Target width")
    height: int | None = opt(short="-H", metavar="PX", description="Target height")
    fmt: Literal["png", "jpg"] = opt("png", short="-f", description="Output format")
    verbose: bool = flag(short="-v", description="Print progress")


args = parse_args(Args)

args is an instance of Args, so type checkers know args.height is int | None and args.fmt is Literal["png", "jpg"].

$ python resize.py -h
Usage: resize.py -w PX [-H PX] [-f {png,jpg}] [-v] src [dst]

Positionals:
  src                  Image to resize
  [dst]                Where to save it [default: "out.png"]

Options:
  -w, --width PX       Target width
  -H, --height PX      Target height
  -f, --fmt {png,jpg}  Output format [default: "png"]
  -v, --verbose        Print progress
  -h, --help           Show this message and exit

$ python resize.py cat.jpg -w 400 -f gif
error: -f must be one of: "png", "jpg"

Usage: resize.py -w PX [-H PX] [-f {png,jpg}] [-v] src [dst]

Output is colored in a terminal, unless NO_COLOR is set.

Declaring arguments

Declaration Gives
pos() Required positional
pos(default) Optional positional (after required ones)
opt(default, short="-c") Option: --name VALUE, plus an optional short key
opt() Option that's None unless given (annotate it T | None)
opt(required=True) Required option
flag(short="-v") bool option with no value: False unless given

Each also takes:

  • description=: its help text
  • long= (options and flags): its long key -- defaults to the field name with _ as -; long=False for a short-only one
  • metavar= (options): its value's placeholder in help
  • group= (options and flags): the help heading it's listed under, Options by default

Types: str, int, float, or a Literal of string/int values. Annotate a field as list[...] of any of these to take several values:

class Args:
    point: list[int] = pos(nargs=2)  # Exactly 2
    files: list[str] = pos()  # One or more: the remaining positionals
    tags: list[str] = opt([], short="-t")  # Repeatable: -t a -t b
    ids: list[int] = opt([], nargs=(1, 3))  # Given 1 to 3 times

A list positional must come last, unless nargs fixes its count.

Mistakes in the class itself (e.g. an unsupported type or a key used twice) raise TypeError as soon as parse_args runs.

Commands

Declare each command as a class, and the command field with cmd():

from bicker import cmd, flag, parse_args, pos


class Build:
    """Build the project."""

    release: bool = flag(short="-r")


class Test:
    """Run the tests."""

    pattern: str | None = pos(None)


class Args:
    verbose: bool = flag(short="-v")
    command: Build | Test = cmd()


args = parse_args(Args)
match args.command:
    case Build(release=release):
        print("release build" if release else "debug build")
    case Test(pattern=pattern):
        print(f"testing {pattern or 'everything'}")
  • A command's name is its class name in kebab-case (RunTests is run-tests), or set it with @command("ls", aliases=("l",))
  • Its docstring is its help text
  • Global options (like -v) can go before or after it
  • Add | None to make the command optional
  • Commands can have their own subcommands

Parsing

CLI parsing follows GNU conventions:

  • Options and positionals can be mixed
  • Values can be attached: --width=400, -w400
  • Short flags can be grouped: -vq
  • Long keys can be shortened to any unambiguous prefix: --wid
  • Everything after -- is a positional

parse_args takes description=, epilog= and examples= for the help page, version= to add a --version option, and other settings like prog= and help_keys=. See docstring for more.

Not supported (yet)

  • Other value types (e.g. Path, Enum)
  • Custom colors

Feature requests are welcome: open an issue.

License

MIT

Metadata

Release files for bicker 2.1.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 bicker 2.1.0
File Size Uploaded Provenance Actions
bicker-2.1.0.tar.gz 18.1 kB Without provenance Details for bicker-2.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 38.5 kB

Release files / bicker-2.1.0.tar.gz

Download URL bicker-2.1.0.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
966deefb79f640da86fe97cc6b6ff707bfe8a5b10241830acc44c0f82f9075d3
BLAKE2b-256 checksum
How to use checksums
a726aaeac257f26f66b7209541289a49cdfb35042649b9b1a351af38fea43436
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / bicker-2.1.0-py3-none-any.whl

Download URL bicker-2.1.0-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8afa4d35ff60bc1bd5e00a17630a14d2aea56d604331125d167ae432f7c3d330
BLAKE2b-256 checksum
How to use checksums
407501101d09b3fc866bc4b69440c7f7bc26fdcd8e2d672b1ce73497d571b31d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for bicker 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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