Skip to main content

Reptile is a command-line interface for Python. Specifically, Reptile helps with producing interactive REPL-like software.

Project description

The Reptile image is created by Chill Desk.

Reptile

Reptile is a command-line interface for Python. Specifically, Reptile helps with producing interactive REPL-like software. With Reptile, you can easily create different prompts depending on the specific type of question you want the user to respond to (input, list, checkbox, etc.).

The design of Reptile is heavily based on PyInquirer, which in turn is heavily based on Inquirer.js. Compared to PyInquirer, Reptile features tow major improvements:

  • It's based on the latest version of prompt_toolkit (3.0+), rather than 1.0.
  • The code is well formatted, commented and documented.

To create prompts with Reptile is as simple as:

import reptile

# Single-question prompt.
question = {
    "Type": "List",
    "Name": "Movie",
    "Message": "What's your favourite movie?",
    "Choices": ["Into the Wild", "Fight Club", "Casablanca"]
}
answers = reptile.prompt(question)

# {"Movie": "Casablanca"}
import reptile

# Multiple-questions prompt.
questions = [
   {
       "Type": "Checkbox",
       "Name": "Books",
       "Message": "What books have you read?",
       "Choices": ["Infinite Jest", "The Little Prince", "The Hobbit"]
   },
   {
       "Type": "Confirm",
       "Name": "Confirmed",
       "Message": "Do you agree Parasite was a masterpiece?",
   },
   {
       "Type": "Input",
       "Name": "Name",
       "Message": "What's your name?",
   },
   {
       "Type": "List",
       "Name": "Movie",
       "Message": "What's your favourite movie?",
       "Choices": ["Into the Wild", "Fight Club", "Casablanca"]
   },
]
answers = reptile.prompt(question)

# {
#   "Checkbox": ["Infinite Jest", "The Little Prince", "The Hobbit"],
#   "Confirmed": False,
#   "Name": "Alessandro",
#   "Movie": "Casablanca",
# }

The Prompts

Checkbox

A checkbox is a prompt that allows the user to select zero, one or more options. It offers two shortcuts: <a> to select all options and <i> to invert the selections.

Options:

  • Name: str → The name of the question. It's then used as key in the output dictionary (answer = reptile.prompt(question)).
  • Message: str → The message to display to the user (the question itself).
  • Choices: list → The options available to be selected.
  • Values: list → A list of the same length of Choices. If available, the corresponded value(s) in Values is returned instead of the choice(s) selected by the user.
  • Default: Any → The value to return if the output is empty.
  • Validate: function → A function that takes the output of the prompt as input and returns either True (if validated) or a string (if not validated; the string is used as error message).
  • Transform: function → A function that takes the output of the prompt and replaces it with something else.
  • When: function → Used to create conditional flows of questions. It's a function that takes the whole answers dictionary and returns either True (if the question has to be asked) or False (if it's to be skiped).

Confirm

Confirm is a prompt that allows the user to respond to a Yes or No question. It only accepts y/Y and n/N. The output value is True for Yes and False for No.

Options:

  • Name: str → The name of the question. It's then used as key in the output dictionary (answer = reptile.prompt(question)).
  • Message: str → The message to display to the user (the question itself).
  • Transform: function → A function that takes the output of the prompt and replaces it with something else.
  • When: function → Used to create conditional flows of questions. It's a function that takes the whole answers dictionary and returns either True (if the question has to be asked) or False (if it's to be skiped).

Input

An input is a prompt that allows the user input its own value as text.

Options:

  • Name: str → The name of the question. It's then used as key in the output dictionary (answer = reptile.prompt(question)).
  • Message: str → The message to display to the user (the question itself).
  • Default: Any → The value to return if the output is empty.
  • Validate: function → A function that takes the output of the prompt as input and returns either True (if validated) or a string (if not validated; the string is used as error message).
  • Transform: function → A function that takes the output of the prompt and replaces it with something else.
  • When: function → Used to create conditional flows of questions. It's a function that takes the whole answers dictionary and returns either True (if the question has to be asked) or False (if it's to be skiped).

List

A list is a prompt that allows the user to select one out of many options (but one and only one).

Options:

  • Name: str → The name of the question. It's then used as key in the output dictionary (answer = reptile.prompt(question)).
  • Message: str → The message to display to the user (the question itself).
  • Choices: list → The options available to be selected.
  • Values: list → A list of the same length of Choices. If available, the corresponded value(s) in Values is returned instead of the choice(s) selected by the user.
  • Transform: function → A function that takes the output of the prompt and replaces it with something else.
  • When: function → Used to create conditional flows of questions. It's a function that takes the whole answers dictionary and returns either True (if the question has to be asked) or False (if it's to be skiped).

Development

Tests

You can run the unit tests via PyTest. After you've activated the virtual environment (pipenv shell), just execute:

python -m pytest

Reptile also comes with a handy manual test module, so that the interactions with the shell can be tested as well. To execute the module, activate the virtual environment and install Reptile from the local files themselves (rather than downloading the build from PyPI). An explanation of why this step is necessary can be found here. Once you've activated the virtual environment (again, pipenv shell), to install Reptile locally simply navigate to the folder containing the setup.py file and execute:

pipenv install -e .

The dot (.) means here and the -e flag signifies the package should be installed in editable mode, meaning all changes to the raw files will be reflected in the installed package live (this is only necessary if you inteded to make changes to Reptile).

Once Reptile has been installed locally, you can execute:

python tests/manual/manual.py

Just follow the instructions as they appear on-screen to complete the test.

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

reptile-1.0.2.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

reptile-1.0.2-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file reptile-1.0.2.tar.gz.

File metadata

  • Download URL: reptile-1.0.2.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/46.3.1 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for reptile-1.0.2.tar.gz
Algorithm Hash digest
SHA256 006aa3fa76a4fca2a8618a468ce0b29497ff27105795b58a221c3d6a8a1015c7
MD5 fc2e2449298f268c28fea0c85ac97cfa
BLAKE2b-256 cc84e71d0685d5043d111cb73505a6d492bd2969684ca2a91b1ef35c6f27acef

See more details on using hashes here.

File details

Details for the file reptile-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: reptile-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/46.3.1 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for reptile-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 951be2b1d09d2543105e973c6ee3be31b5cd406149ac3e7b85389e80c19d360b
MD5 5893335b36489146659c17dc8c906f94
BLAKE2b-256 a4899a837c8a626f55491aaefd68c2a928acf00e591b4d2df5083d6ff6c0a189

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