Skip to main content

Argexec

Build status PyPI PyPI - License

An unobtrusive, elegant mechanism to provide seamless command line interfaces through argparse for Python functions. All you have to do is decorate your function of choice with @argexec and away you go!

Features

  • Description parsing from docstring
  • Argument help parsing from reStructuredText-like docstrings
  • Argument type enforcement via typeguard from type hints
  • Argument default values from function signature
  • Support for the following argument types:
    • All builtin primitives (bool, int, float, str, bytes)
    • Fixed length tuples of a supported type
    • Variable length tuples of a supported type
    • Lists of a supported type
  • Extensible, complex custom type parsing via dynamic_dispatch

Install

You may install this via the argexec package on PyPi:

pip3 install argexec

Usage

The decorator may be applied to any Python function that meets the following requirements:

  • Is not a member function
  • Has PEP 484 type hints for all parameters
  • Does not use *args or **kwargs

Example (foo.py):

#!/usr/bin/python3

from typing import Tuple

from argexec import argexec
from argexec.types import LogLevel

@argexec
def _(w: int, x: Tuple[str, ...], y: LogLevel, z: bool = True):
    """
    Hello, world!

    :param w: foo.
    :param x: bar.
    :param y: baz.
    :param z: qux.
    """
    pass
$ ./foo.py --help
usage: foo.py [-h] [-y] [--no-z] w [x [x ...]]

Hello, world!

positional arguments:
  w           [int] foo
  x           [Tuple[str, ...]] bar

optional arguments:
  -h, --help  show this help message and exit
  -y, --y     [LogLevel=CRITICAL] baz (more flags for lower level)
  --no-z      [bool=True] qux

Development

When developing, it is recommended to use Pipenv. To create your development environment:

pipenv install --dev

Testing

TODO

Metadata

Release files for argexec 1.0.3

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

Source distribution (sdist)

Source distribution for argexec 1.0.3
File Size Uploaded Provenance Actions
argexec-1.0.3.tar.gz 7.2 kB Without provenance Details for argexec-1.0.3.tar.gz

Release files / argexec-1.0.3.tar.gz

Download URL argexec-1.0.3.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
61f9ae9322e38ae64996848421afbdb018239a99c4e796fe064f172d6c98c3bf
BLAKE2b-256 checksum
How to use checksums
b03ab089133ff2aec45a1dfd58f46996587f978055606607ee98df192fc63783
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Security for argexec 1.0.3

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