Skip to main content

A simple interactive CLI builder

Project description

Paperplane

Documentation Status

Paperplane allows you to build interactive CLIs straight from a configuration file (or a Python dict) without having to write your own code for I/O.

Paperplane orchestrates I/O operations by delegating work to different backends. Supported backends:

  • click
  • More backends coming soon!

Currently supports:

  • Reading an int, string, boolean, one-of-many (choice) inputs.
  • Display a styled output (bold, foreground color, background color, etc)
    • The click integration backend automatically calls click.secho()

The I/O order and parameters (prompt, data type, available choices, default, etc) can be provided in the following formats:

  • YAML
  • JSON
  • Python dictionary

See Getting Started for more info!

Installation

Assuming you have Python (>= 3.6), run:

pip install paperplane

Documentation

Preliminary documentation is available at paperplane.readthedocs.io.

Detailed documentation coming soon!

Features

  • Collect interactive inputs and display styled output text based on simple configurations.
  • Dynamic defaults and prompts (the question/message shown to the user) via macros.
    • Use the value from one input to calculate the default value for subsequent inputs.
      • For example, collect a username input and use https://github.com/<io:username> to auto-compute the default value for the subsequent github_url input.
    • Use the <cwd> macro to get the current working directory
    • Use the <env:NAME> macro to fetch the value for an environment variable.
      • Using the macro <env:NAME1,NAME2> will fetch the first available environment variable. Useful if, for example, the environment variable names are different on Windows and Linux. Or simply, if you're unsure about which of them will be set.

See the example config.yml below for more awesome features!

Getting Started

Paperplane has a convenient paperplane collect CONFIG_FILE command that lets you run and test your config file. It triggers I/O operations based on the provided parameters and dumps the collected information to your terminal (Python dict format by default or alternatively, JSON) for debugging/verifying.

For usage inside a Python script, see here.

To get started, create a new YAML configuration file as follows:
config.yml

backend: click
io:
  - name:
      type: str
      prompt: Your name
  - username:
      type: str
      prompt: Your GitHub username
      default: <env:USER,USERNAME>
  - prompt1:
      type: echo
      prompt: |-
        Hello, <io:name> (<io:username>)!
        Your GitHub URL is https://github.com/<io:username>
        Your current working directory is '<cwd>'
      fg: green
  - project_dir:
      type: str
      prompt: Enter project directory
      default: <cwd>
  - prompt2:
      type: echo
      prompt: Enter a name for your new project. It will be created at <io:project_dir>/<project name>
      fg: blue
  - project_name:
      type: str
      prompt: Project name
  - feature_x:
      type: choice
      prompt: Do you want to enable feature X?
      choices:
        - 'Yes'
        - 'No'
      default: 'Yes'

To run and trigger I/O operations:

paperplane collect /path/to/config.yml

Result:
Sample Usage


If you want a JSON output (instead of the default Python dict dump):

paperplane collect /path/to/config.yml --json-out

If you have an input JSON config file instead of YAML:

paperplane collect /path/to/config.json --format=json

If you want DEBUG level logs:

paperplane --debug collect /path/to/config.yml

To see all available options:

paparplane --help
paparplane collect --help

Usage within a Python script

from paperplane import parse_and_execute

config = {
  'backend': 'click',
  'io': [{
      'name': {
        'type': 'str',
        'prompt': 'Your name'
      }
    },
    {
      'username': {
        'type': 'str',
        'prompt': 'Your GitHub username',
        'default': '<env:USER,USERNAME>'
      }
    },
    {
      'prompt1': {
        'type': 'echo',
        'prompt': "Hello, <io:name> (<io:username>)!\nYour GitHub URL is https://github.com/<io:username>\nYour current working directory is '<cwd>'",
        'fg': 'green'
      }
    },
    {
      'project_dir': {
        'type': 'str',
        'prompt': 'Enter project directory',
        'default': '<cwd>'
      }
    },
    {
      'prompt2': {
        'type': 'echo',
        'prompt': 'Enter a name for your new project. It will be created at <io:project_dir>/<project_name>',
        'fg': 'blue',
      }
    },
    {
      'project_name': {
        'type': 'str',
        'prompt': 'Project name'
      }
    },
    {
      'feature_x': {
        'type': 'choice',
        'prompt': 'Do you want to enable feature X?',
        'choices': ['Yes', 'No'],
        'default': 'Yes',
      }
    }
  ]
}

values = parse_and_execute(config)

# Do your own stuff with the collected values
print(values)

Coming soon

  • Tests
  • Input validators
  • Lazy Jinja2 template rendering in YAML config

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

paperplane-0.0.3.tar.gz (109.1 kB view details)

Uploaded Source

Built Distribution

paperplane-0.0.3-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file paperplane-0.0.3.tar.gz.

File metadata

  • Download URL: paperplane-0.0.3.tar.gz
  • Upload date:
  • Size: 109.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for paperplane-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f04e3fa3fa239e17f420f87e6480f159b79d6d198564a4cd925fdceac196310d
MD5 a0b2520c789606bb941941ecf576d440
BLAKE2b-256 74579090ef28354d99d75101272d084ed08d56a04e83c05ba5734def2dacbc67

See more details on using hashes here.

File details

Details for the file paperplane-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: paperplane-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for paperplane-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e413b65f5ee9667770982d5002fd18c15607f48ccc5a9a84704db5eae5f6f633
MD5 9d7c70eaf1aba3808caabc940b871f88
BLAKE2b-256 c3c749c6fcfd8d8219805e70158113ee139d1cdd997d19d1fa7ce44d17cbea20

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