Skip to main content

PyMsgPrompt is a python module to embed prompt functionality in your code. Current Version of the module is 1.3.0

Project description

PyMsgPrompt

PyMsgPrompt is a python module to embed prompt functionality in your code.

Version

The current version of this module is 1.3.0 and this is the third BETA release after first BETA version 1.2.2, however, you can run the below command to check the version of the module.

python -m pymsgprompt.version

Platform Supports

This is a cross platform module and supported both in python 2 and 3.

Installation

To install this module you can use clone with git or just simply run pip install command.

Using git

git clone https://github.com/antaripchatterjee/PyMsgPrompt.git
cd PyMsgPrompt
python setup.py install

Using pip

pip install pymsgprompt

Uninstallation

Uninstallation can be done by running pip uninstall command.

pip uninstall pymsgpropmt

Usage

To test this module, you can run the below simple code.

from pymsgprompt.prompt import ask, log
from pymsgprompt.logger import perror, pinfo, pwarn
import time
if __name__ == '__main__':
    answer = ask('Do you want to close?', choices=['yes', 'no', 'not sure'], default='yes', timestamp=True, regexp=True, ignore_case=False)
    # with open('test.txt', 'w') as test:
    #     print (log('Answer is %s'%answer, logtype='error', timestamp=True, file=test))
    if answer.startswith('n'):
        log('Answer is %s'%answer, logtype='error', timestamp=False, reset=True)
    else:
        log('Answer is %s'%answer, logtype='info', timestamp=False, reset=True)
    for i in range(1000, 0, -1):
        log('The message is %d'%i, timestamp=True, end=None if i > 1 else '\n', reset=i==1)
        time.sleep(0.01)

    pinfo('I am a Python Developer')
    pwarn('Some kind of warning message')
    perror('Some kind of error message')

Below is the output,

[QUES] 2021-Apr-01 22:27:50: Do you want to close? (yes/ no/ not sure)[yes]not
not sure
Answer is not sure
[INFO] 2021-Apr-01 22:28:11: The message is 1   
[INFO] 2021-Apr-01 22:28:11: I am a Python Developer
[WARN] 2021-Apr-01 22:28:11: Some kind of warning message
[ERROR] 2021-Apr-01 22:28:11: Some kind of error message

API Reference

pymsgprompt.prompt.ask function takes two positional arguments on_success and on_error, and they expect two callback functions, which will be called after validating the answer. The default value of them are pymsgprompt.handler.default_on_success and pymsgprompt.handler.default_on_error respectively.

The callback function for on_success takes three arguments, which are question, actual_answer and original_answer. The ask function returns the same value, actually returned by the callback function. The default function returns the original_answer.

The callback function for on_error takes four arguments, which are question, choices, default, and error. This value must return either True, means the question should be reasked, or False, means no need to ask the question again. The default function returns the False.

A good documentation, specially for the developers, will be provided later.

License

This module is licensed under MIT License.

Contribution

Pull requests are always awesome, but please make sure of raising request, before making any changes.

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

PyMsgPrompt-1.3.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

PyMsgPrompt-1.3.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file PyMsgPrompt-1.3.0.tar.gz.

File metadata

  • Download URL: PyMsgPrompt-1.3.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/54.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for PyMsgPrompt-1.3.0.tar.gz
Algorithm Hash digest
SHA256 a7da7032f87aa51d8fb360430bf6e5a605430fd85a6283f56cb02d5f5d7ef852
MD5 fa4bda8d8703253387d4fa56bab91947
BLAKE2b-256 3dd997df6a117cb523427f9c78b4140d5db689bc7bc9a59b11b7f098cfb9c1b8

See more details on using hashes here.

File details

Details for the file PyMsgPrompt-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: PyMsgPrompt-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/54.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for PyMsgPrompt-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b496785c6aaf115756ef2eb4904463b0b3c44840515c2f99d3daa6fdb9b2064
MD5 6bf093c05462745df4bdc2ff289bbb1c
BLAKE2b-256 eab086e8dbe340631a6da605170d92f2889a14ad141b30bed8cd5075196b718c

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