Git Product home page Git Product logo

typed-argparse's Introduction

PyPI version Build Status codecov Code style: black mypy license



๐Ÿ’ก write type-safe and elegant CLIs with a clear separation of concerns.

Features

  • Argument parsing based on type annotation (including runtime validation).
  • Support for many common types.
  • Clear separation of concern between argument parsing and business logic.
  • Support for super-low-latency shell auto-completions.
  • Great for writing sub-command CLIs.
  • Very lightweight.
  • No dependencies.
  • Fully typed itself, no extra type stubs required.
  • Offers both a high-level and a low-level API. The high-level API generally requires less code to write, is fully based on type annotations, and is the preferred way for writing new CLIs. The low-level API is mainly a low-effort migration path for incorporating type-safety into existing CLIs based on argparse.

Install

$ pip install typed-argparse

The only requirement is a modern Python (3.8+).

Basic Usage

import typed_argparse as tap


# 1. Argument definition
class Args(tap.TypedArgs):
    my_arg: str = tap.arg(help="some help")
    number_a: int = tap.arg(default=42, help="some help")
    number_b: Optional[int] = tap.arg(help="some help")
    verbose: bool = tap.arg(help="some help")
    names: List[str] = tap.arg(help="some help")


# 2. Business logic
def runner(args: Args):
    print(f"Running my app with args:\n{args}")


# 3. Bind argument definition + business logic & run
def main() -> None:
    tap.Parser(Args).bind(runner).run()

Documentation

See full documentation.

Changes

See change log.

License

This project is licensed under the terms of the MIT license.

typed-argparse's People

Contributors

bluenote10 avatar kianmeng avatar kopp avatar shmuel44 avatar

Watchers

 avatar

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.