Commoner provides a set of common functions and classes for Python projects.
Project description
Commoner
Commoner provides a set of common functions and classes for Python projects.
Installation
Commoner is available on PyPI and can be installed with pip
:
Either run:
pip install commoner
or run:
python3 -m pip install commoner
Usage
Commoner is a collection of common functions and classes that can be used in any Python project. It is not meant to be used as a standalone library, but rather as a collection of useful functions and classes that can be imported into other projects. The following is a list of the modules and classes that are available in Commoner:
- println() - Prints a line of text and then prints a specified number of newlines.
- printsln() - Prints a line of text without a newline at the end.
- printx() - Prints a line of text a specified number of times.
- typewriter() - Prints a line of text with a typewriter effect (one character at a time).
- random_string() - Generates a random string of a specified length.
- sort_dict_keys() - Sorts a dictionary by its keys.
- sort_dict_values() - Sorts a dictionary by its values.
- swap_keys_values() - Swaps the keys and values of a dictionary.
- reverse() - Reverses a list, string, or dictionary.
Brush
The Brush class provides a set of methods for printing colored text to the console.
-
bold(text) - Prints bold text.
-
italic(text) - Prints italic text.
-
underline(text) - Prints underlined text.
-
red(text) - Prints red text.
-
yellow(text) - Prints yellow text.
-
green(text) - Prints green text.
-
cyan(text) - Prints cyan text.
-
blue(text) - Prints blue text.
-
magenta(text) - Prints magenta text.
-
white(text) - Prints white text.
-
black(text) - Prints black text.
-
set(color): Sets the text color to the specified color.
-
reset(): Resets the text color to the default color.
Wait
The Wait class provides a set of methods for printing a loading animation to the console.
- start() - Starts the loading animation.
- stop() - Stops the loading animation.
- wait(seconds): Waits for the specified amount of time.
- input(message, color): Waits for the user to press a key (with an optional message and optional color).
Progress
The Progress sub-class of Wait provides a set of methods for printing a progress bar to the console.
- Progress(total, character="#", reverse=False): Creates a new progress bar.
- Progress.start(message): Starts the progress bar (with an optional message).
- Progress.update(current, message): Updates the progress bar (with an optional message).
- Progress.finish(message): Finishes the progress bar (with an optional message).
- Progress.timed(seconds, character, message): Starts a progress bar that counts down from a specified amount of time.
For example:
my_progress = Wait.Progress(100)
my_progress.start()
for i in range(100):
run_some_code()
my_progress.update(i + 1)
my_progress.finish()
or for a timed progress bar:
my_progress = Wait.Progress.timed(10)
Shout
The Shout class provides a set of methods for printing preconfigured messages to the console.
- warning(message) - Prints a warning message to the console (yellow text).
- error(message) - Prints an error message to the console (red text).
- success(message) - Prints a success message to the console (green text).
- info(message) - Prints an info message to the console (blue text).
Text
The Text class is an extension of the str type with additional functionality.
- replace(old, new) - Replaces characters in the text.
- reverse() - Reverses the text.
- count(char) - Counts the number of times a character (or all characters) appear(s) in the text.
- to_snake() - Converts the text to snake case.
- to_camel() - Converts the text to camel case.
- to_pascal() - Converts the text to pascal case.
- to_kebab() - Converts the text to kebab case.
- to_actual_title() - Converts the text to an actual title (e.g. "this is a title" -> "This Is a Title").
- to_initials(case_sensitive) - Converts the text to initials (e.g. "this is a title" -> "T.I.a.T") (case sensitive by default).
Console
The Console class provides a set of methods for interacting with the console.
- clear() - Clears the console.
- format(style) - Sets the text color to the specified color.
License
Commoner is licensed under the MIT License. See the LICENSE file for more information.
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
Built Distribution
File details
Details for the file commoner-0.5.0.tar.gz
.
File metadata
- Download URL: commoner-0.5.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.11.2 Darwin/22.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 393ca78de24412b2f95e783950b4bc869410e756938894f132f8205fc5d1ab55 |
|
MD5 | 68a4a89128f5d8f0759b62944ecee9a1 |
|
BLAKE2b-256 | 5f738323f4eee33913f711df3b1bd0ed766114ce062e89537a94981991b02197 |
File details
Details for the file commoner-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: commoner-0.5.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.11.2 Darwin/22.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 580fc899f8417ecac18500f0c7d4cd687a7ad4e9c4c56cafed7914c2c28355eb |
|
MD5 | 598d72e7a81571822bca5639b88dba69 |
|
BLAKE2b-256 | ec93123ad01f32226318ec0a468b141401202730c969e894cd82203ddf9ebda5 |