Skip to main content

Lightweight helper toolkit for building small CLI (command-line) applications in Python.

Project description

cli_tools_by_oleksa

Python Version License Version

Lightweight helper toolkit for building small CLI (command-line) applications in Python.

The library simplifies common CLI tasks such as:

  • handling user input,
  • validation and conversion,
  • safe execution and retry loops,
  • formatted console output.

It is ideal for educational scripts, training exercises, small utilities, and simple CLI apps where readability and robustness matter more than complex frameworks.


✨ Features

  • safe_run — context manager for safe execution with optional debug output
  • try_until_ok — repeat an operation until success, catching specified exceptions
  • valid_input — flexible input validation (regex + custom validator + conversion)
  • choose_from_list — select an item from a list by number or text
  • parse_list — split text into a list and optionally convert elements
  • 🖨print_iterable / print_zipped_iterable — neat console formatting of lists or zipped items
  • safe_int / safe_float — convert strings to numbers safely without raising exceptions
  • Predefined regex patterns — integers, floats, dates, usernames, emails, multi-item lists, etc.
  • Validator factories — range checks, list membership, numerical comparisons (>, >=, <, <=)

Zero external dependencies — just Python 3.10+.


📦 Installation

pip install --upgrade --index-url https://test.pypi.org/simple/ --no-deps cli_tools_by_oleksa

🛠️ Usage Example

from cli_tools import safe_run, try_until_ok, valid_input, choose_from_list, print_iterable, print_zipped_iterable
from cli_tools.validators import is_in_range

with safe_run(debug=True, exit_on_error=False):
    name = valid_input("Enter your name: ", converter= lambda x: x.strip().capitalize())
    print(f"Hello, {name}!")
    age = try_until_ok(
        valid_input,
        prompt="Enter your age: ",
        validator=is_in_range(1, 100),
        converter=int,
        on_exception="Be serious :)"
    )

    options = ["A", "B", "C"]
    print_iterable(options, item_pattern='{}', join_by=' | ', start='[ ', end=' ]')
    option = choose_from_list(options, by_number=False, prompt='Choose: ')

    data = {
        'name': name,
        'age': age,
        'option': option,
    }

    print_zipped_iterable(data.items(), '| {: <10}|{: >10} |',
                          join_by='\n'+'—'*25+'\n', start='_'*25+'\n', end='\n'+'‾'*25)

Output:

Enter your name:     oLEkSa
Hello, Oleksa!
Enter your age: 1000
Be serious :)
Enter your age: 19
[ A | B | C ]
Choose: D
Incorrect option!
Choose: A
_________________________
| name      |    Oleksa |
—————————————————————————
| age       |        19 |
—————————————————————————
| option    |         A |
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

Process finished with exit code 0

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

cli_tools_by_oleksa-1.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

cli_tools_by_oleksa-1.0.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file cli_tools_by_oleksa-1.0.0.tar.gz.

File metadata

  • Download URL: cli_tools_by_oleksa-1.0.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for cli_tools_by_oleksa-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ddf22ca45cdb348c1d51477c4b7c044e2827010ecb0dfc2789a241bc50f586c1
MD5 f8f1ee26ab217e377471abb03587df31
BLAKE2b-256 5a038be0dc1d2a8be20a0321337a8864c54ddfb4eb290e3522c5c395c23fa3a6

See more details on using hashes here.

File details

Details for the file cli_tools_by_oleksa-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cli_tools_by_oleksa-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2786e30ba98b3ad92b8227145c90403e88e9b64948cff89b3583985105cf154
MD5 02a0caefc80c609fb31f891ab473aa80
BLAKE2b-256 d5edc479780eb39d65ec7fc5ff639f652e79f961082dce5f2f60648e5e66e92b

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