Coder Social home page Coder Social logo

yapx's Introduction

Yapx

The next generation of Python's Argparse.

Yapx is "Yeah, Another Argparse eXtension", a Python library for creating tools with type-safe command-line interfaces (CLIs) -- and even textual user interfaces (TUIs) -- by analyzing type-hints of functions and dataclasses.

Yeah, Another?

I intended to publish this package as simply apx, but PyPi didn't allow it, so I tacked on the y to make *yapx*. The nomenclature "Yet Another" seems demeaning considering what this package is capable of.

So, Yeah, Another Argparse eXtension πŸ‘Š

Think about the repetitive steps involved in creating a command-line application.

  1. Define function(s).
  2. Define the command-line interface; i.e., build the ArgumentParser.
  3. Parse arguments.
  4. Call the appropriate function(s).

For example:

from argparse import ArgumentParser

# 1. Define function(s).
def say_hello(name: str = 'World'):
    print(f"Hello {name}")

# 2. Define the command-line interface.
parser = ArgumentParser()
parser.add_argument("--name", default="World")

# 3. Parse arguments.
parsed_args = parser.parse_args()

# 4. Call the appropriate function(s).
say_hello(name=parsed_args.name)

Yapx combines these steps into one:

import yapx

def say_hello(name: str = 'World'):
    print(f"Hello {name}")

yapx.run(say_hello)

Yapx is a superset of Python's native Argparse ArgumentParser, so you can make use of the high-level abstractions or do the low-level work you're familiar with. Either way, Yapx provides benefits including:

  • πŸ”’ Type-casting and validation, with or without Pydantic.
  • ❓ Automatic addition of "helpful" arguments, including --help, --help-all, --version, and most impressively --tui.
  • ❀️ Prettier help and error messages.
  • ⚑ Command-line autocompletion scripts.

Yapx is among several modern Python CLI frameworks, including Typer and Fire. Distinguishing characteristics of Yapx include:

  • πŸ“¦ No 3rd-party dependencies required (but can be opted into)
  • πŸ”’ Type-safe argument validation
  • πŸ•ΈοΈ Infinitely-nested commands
  • πŸ“Ί Display your CLI as a TUI
  • ❓ Handling of unknown arguments using *args and **kwargs
  • πŸ’‘ Most intuitive
  • πŸ˜“ Least documented

I'd appreciate a more analytical comparison between Yapx and the array of Python CLI frameworks, but that's too ambitious of a goal right now 😬

Install

pip install 'yapx[extras]'

Or, to install without 3rd-party dependencies:

pip install yapx

Use


License GitHub tag (with filter) GitHub last commit (branch) GitHub Repo stars

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.