Skip to main content

Argparse Code Generator

A simple utility meant to generate the skeleton for the argparse interface of your CLI scripts.

Content

  1. Intro
  2. Installation
  3. Usage
  4. CLI arguments

Intro

This package provides a simple utility to generate basic argparse interface for CLI scripts. It works by analysing the callable that you wish your script to call based on CLI arguments.

More precisely, it gets:

  1. the list of arguments from callable's signature;

  2. help hints from the callable's docstring;

  3. types, if possible, from callable's type annotation.

In some cases, it can do a bit more. For example, if the type of an argument is bool, the script will add action to its add_argument call, and if it is a Literal or an enum.Enum, it will create choices.

Installation

Just install it from PyPI:

$ pip install argparse_gen

This'll make argparse_gen script and package available to you.

Usage

If you run

$ argparse_gen -h

you'll get the full help for it, but essentially, it's used by calling

$ argparse_gen path/to/your/package/ name_of_callable_in_that_package

or

$ argparse_gen path/to/your/module.py name_of_callable_in_that_module

The output of the script is Python code that you can copy paste to your script's main file, and then adjust to your needs (the autogenerated version is unlikely to be perfect, except maybe for really trivial stuff).

If you wish to create your own custom scripts to prepare this code, use the package argparse_gen which exposes ArgparseGen class (which implements the whole thing), ParamDef (which implements one parameter), and main function (which wraps the class for convenient calls).

CLI arguments

The script recognizes the following CLI arguments:

  • -p PARAM_REGEX, --param_regex PARAM_REGEX: A regular expression to recognise parameters in the callable's docstring. The default recognizes rST (reStructuredText) format.
  • -i INDENT, --indent INDENT: Additional indentation for the generated code.
  • -s, --skip_private: Skip private (those with names starting with an underscore) arguments.
  • -c, --call_args: Instead of generating a call with all of the available arguments, use call_args (from the call-args package). This loses some transparency, but it's quite convenient if you frequently change the arguments.

Metadata

Release files for argparse_gen 1.0.1

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

Source distribution (sdist)

Source distribution for argparse_gen 1.0.1
File Size Uploaded Provenance Actions
argparse_gen-1.0.1.tar.gz 8.6 kB Without provenance Details for argparse_gen-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for argparse_gen 1.0.1
File Interpreter ABI Platform Actions
argparse_gen-1.0.1-py3-none-any.whl Python 3 none any Details for argparse_gen-1.0.1-py3-none-any.whl

Total release size: 17.7 kB

Release files / argparse_gen-1.0.1.tar.gz

Download URL argparse_gen-1.0.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f6956326589f1603b819bfe0b466bd9c2d11c0532223b8d08a839c92b3f47e79
BLAKE2b-256 checksum
How to use checksums
d2e40b889365813e198897767eaa0f5bcdb0595df858bd3c8c4885f7c952ede2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Release files / argparse_gen-1.0.1-py3-none-any.whl

Download URL argparse_gen-1.0.1-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d5abbd96c58ef99da44d1ab122880ad2201583ae2da792653556319d8a2945e
BLAKE2b-256 checksum
How to use checksums
e3b7e068de17f51d1761841a1cc15ab7b97e12923a3ebd10ecd7074b1d10ec82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Security for argparse_gen 1.0.1

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.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

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