Skip to main content

Advanced Prompts

Reason this release was yanked:

Library now has slightly different usage and entirely different syntax.

Project description

aprompt

aprompt (short for advanced prompt) is a library to create input prompts in the console easily. Most use cases are for forms and setups.

Installation

pip install aprompt

Quickstart

import aprompt as ap

@ap.prompt()
def prompt(age: int):
    """
    How old are you?
    """
    if age < 18:
        return ap.Err("You are too young!")
    
    else:
        print("Thanks for joining our community!")

age = prompt()

This is a basic example on how to request the user's age. The function takes one positional argument, which - in this case - requires type annotation. By default, everything is interpreted as a string. Here however we need an integer.

Example

import json
from pathlib import Path
import aprompt

manifest = {}


@aprompt.prompt()
def prompt(_):
    """
    Enter your name
    """

manifest["author"] = prompt()


@aprompt.option("1.0", "1.1", "1.2", default = 1)
def prompt(_):
    """
    What version do you want to use?
    """

manifest["version"] = prompt()


@aprompt.yesno()
def prompt(use_icon: bool):
    """
    Do you want to include an icon?
    """
    if use_icon:
        @aprompt.prompt()
        def prompt(path: Path):
            """
            Enter the path to the file
            """
            if not path.is_file():
                return aprompt.Err(f"{path} is not a file")
        
        manifest["icon"] = prompt()
    
    else:
        manifest["icon"] = None

prompt()


@aprompt.confirm()
def prompt(_):
    """
    Your manifest will be generated. Hit Enter
    to continue or quit with Ctrl + C or Ctrl + Z.
    """
    with open("manifest.json", "w") as f:
        json.dump(manifest, f)
    print("File has been generated")

prompt()

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

aprompt-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aprompt-0.1.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file aprompt-0.1.1.tar.gz.

File metadata

  • Download URL: aprompt-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for aprompt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6e0ff9d52a2f6aa1a17c2879bf340d6e7d58a17cde02c88ded724475ac983803
MD5 529511ca06bc3087f8cc72bf2132c05b
BLAKE2b-256 9ce67adae66542f71a79f11ec76db68a8d99e4d8a021f7a8d8cfa97165dc9664

See more details on using hashes here.

File details

Details for the file aprompt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: aprompt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for aprompt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df03ea94e78dff6cf0b6982198d9b0616f356b0a2f0568c996da8523cca9a4db
MD5 37e34cbb877d6d628d63af72a6563d99
BLAKE2b-256 3075b786012e5d32e81853875b5fcb7b58a0181109915a37cde63e09e65451de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page