Skip to main content

Yet another argparse extension for building CLI tools.

Project description

yapx

Yet another argparse extension for building CLI tools.

Links
Code Repo https://www.github.com/fresh2dev/yapx
Mirror Repo https://www.Fresh2.dev/code/r/yapx
Documentation https://www.Fresh2.dev/code/r/yapx/i
Changelog https://www.Fresh2.dev/code/r/yapx/i/changelog
License https://www.Fresh2.dev/code/r/yapx/i/license
Funding https://www.Fresh2.dev/funding

GitHub release (latest SemVer) GitHub Release Date License GitHub issues GitHub pull requests GitHub Repo stars PyPI - Downloads Docker Pulls Docs Website Coverage Website Funding

Brought to you by...


yapx is yet another argparse extension that helps you build Python CLI applications with ease.

yapx makes use of type annotations build a capable command-line utility using Python's native argparse library. yapx inherits from -- and can serve as a drop-in replacement to -- the argparse.ArgumentParser to provide benefits including:

  • adding arguments derived from existing functions or dataclases.
  • support use of environment variables as argument values.
  • performing argument validation, with or without Pydantic.
  • generation of shell-completion scripts with shtab.
  • CLI to TUI support with Trogon.

Note: yapx is in beta status. Please report ideas and issues here.

Install

pip install yapx

By default, yapx has no 3rd-party dependencies, but they can be added to unlock additional functionality. For example:

When Pydantic is present, yapx can support more types.

pip install 'yapx[pydantic]'

When shtab is present, yapx can output shell-completion scripts.

pip install 'yapx[shtab]'

When Trogon is present, yapx can present a terminal user interface (TUI) of the application.

pip install 'yapx[tui]'

Install all of these with:

pip install 'yapx[pydantic,shtab,tui]'
# or, equivalently:
pip install 'yapx[extras]'

Use

Here's a simple example using typical argparse semantics:

>>> import yapx
...
### Define some function.
>>> def add_nums(x: int, y: int):
...     return x + y
...
### Create a parser
>>> parser = yapx.ArgumentParser()
### Add function arguments to parser.
>>> parser.add_arguments(add_nums)
### Parse arguments.
>>> parsed = parser.parse_args(['-x', '1', '-y', '2'])
...
### Call function with parsed args.
>>> add_nums(parsed.x, parsed.y)
3

This capability -- and much more -- is simplified even further with the yapx.run command:

>>> import yapx
...
>>> def add_nums(x: int, y: int):
...     return x + y
...
>>> yapx.run(add_nums, _args=['-x', '1', '-y', '2'])
3

Read more @ https://www.Fresh2.dev/code/r/yapx/i

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

yapx-0.1.0.tar.gz (51.1 kB view hashes)

Uploaded Source

Built Distribution

yapx-0.1.0-py3-none-any.whl (46.7 kB view hashes)

Uploaded Python 3

Supported by

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