Lightweight helper toolkit for building small CLI (command-line) applications in Python.
Project description
cli_tools_by_oleksa
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
Stable:
pip install --upgrade cli_tools_by_oleksa
Test:
pip install --upgrade --index-url https://test.pypi.org/simple/ 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, print_header)
from cli_tools.validators import is_in_range
with safe_run(debug=True, exit_on_error=False):
print_header(' Some example ')
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:
~~~~~~~~~~~~~~
Some example
~~~~~~~~~~~~~~
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cli_tools_by_oleksa-1.0.1.tar.gz.
File metadata
- Download URL: cli_tools_by_oleksa-1.0.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dad809ccd81bbd7229f1453310f603812dcdd44d97875a2a020282509915df56
|
|
| MD5 |
1ea0f4863c8478009a854c364e97ed8c
|
|
| BLAKE2b-256 |
a918188369dff69c14efa6ea15bcc32db50ff5cfcfdbf9433f9684c308af444c
|
File details
Details for the file cli_tools_by_oleksa-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cli_tools_by_oleksa-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aae560ef2e36756d8ac18112f6a92d8ed4af717b41e03d40a1d68919e1e869d5
|
|
| MD5 |
45911750e6297c4e7b652fbcae6f48c1
|
|
| BLAKE2b-256 |
4f49f517d2b51b9f15279b199ce645c51355811e4b66e7269dd79c57df24ccf6
|