Skip to main content

A microscopic library to turn any function into a CLI.

Project description

uPyCLI

A microscopic library to turn any function into a CLI.

Takes some inspiration from pycli although I didn't know this existed before starting. This lib is even smaller than pycli and does not require any setup and has no dependencies.

The good thing about this is, you don't need to write or maintain any code for the CLI, all your types, variables, descriptions are introspected from the code itself, so all you do is throw on a decorator.

Usage

ucli path.to.your.function --help

For this to work, all you need to do is have a function in the module with the right type-annotations and all optional values should have a default value.

# Here model_name is required and data_path is optional
def train(
        model_name: str, 
        data_path: str = "./path/to/data"):
    ...

Alternatively, the command decorator can be used to directly turn the function into a CLI command

# main.py
from upycli.decorator import command

@command
def train(model_name: str, data_path: str = "./path/to/data"):
    """
    A function to train a model
    """
    ...
python main.py train --help
>>> usage: main.py [-h] --model_name MODEL_NAME [--data_path DATA_PATH]

A function to train a model

options:
  -h, --help               show this help message and exit
  --model_name MODEL_NAME  str
  --data_path DATA_PATH    str (default ./path/to/data)

Your variables, types, required values and description are introspected from the code itself, so all you do is throw on the decorator.

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

upycli-0.2.10.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

upycli-0.2.10-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file upycli-0.2.10.tar.gz.

File metadata

  • Download URL: upycli-0.2.10.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for upycli-0.2.10.tar.gz
Algorithm Hash digest
SHA256 70eac7d43fb6edc424040709ecfb06427ec059ccf57987959a3ba9572b08b123
MD5 52a0fb6fb380bb3b9c7ff84c0be87848
BLAKE2b-256 00f99107b91b2b9280d1041d002d0164251985d10901f88b857802bf2fe51d68

See more details on using hashes here.

File details

Details for the file upycli-0.2.10-py3-none-any.whl.

File metadata

  • Download URL: upycli-0.2.10-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for upycli-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 af723eeadb46614bb7a7f46b69c271c677efc4333d204c9bf895285e9ef25845
MD5 7e7c245231cfd36bd75dc31dfb987950
BLAKE2b-256 ae753a4f5c1aaf57d46e530a4e1fe88048923cee0f1b54736be1ac72d28fd398

See more details on using hashes here.

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