Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-argparse

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-argparse

Write type-safe and elegant CLIs with a clear separation of concerns.

  • 0.3.1
  • Source
  • PyPI
  • Socket score

Maintainers
1

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.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc