Trickkiste: Random Useful Utilities
Trickkiste is a Python library (v0.3.7) offering a collection of miscellaneous utility functions for string manipulation, list operations, system info, web scraping, and more. It aims to provide quick, ready-to-use solutions for common programming tasks. Releases are generally infrequent, focusing on adding new utilities rather than frequent breaking changes.
Common errors
-
ModuleNotFoundError: No module named 'trickkiste.string'
cause Attempting to import a submodule directly as if it were a top-level package, or a typo in the import path.fixEnsure correct import syntax like `from trickkiste.string import get_random_string`. -
AttributeError: module 'trickkiste' has no attribute 'get_random_string'
cause Trying to access a function directly from the top-level `trickkiste` package instead of its specific submodule.fixImport the function from its submodule: `from trickkiste.string import get_random_string`. -
pip._internal.exceptions.UnsupportedPythonVersion: Package 'trickkiste' requires a Python version less than 4, >=3.10.4 but you have Python X.Y.Z.
cause The Python environment's version does not meet the strict requirements of `trickkiste`.fixUse a Python version between 3.10.4 and 3.99.x (exclusive of 4.0). Consider using `pyenv` or `conda` to manage Python versions and virtual environments. -
RuntimeError: Working outside of request context.
cause Calling `trickkiste.web.get_request_data()` outside of an active Flask HTTP request context.fixEnsure `get_request_data` is only called when a Flask application is running and processing an HTTP request.
Warnings
- breaking The library has a strict Python version requirement, explicitly forbidding Python 4.0+ and requiring Python >= 3.10.4.
- gotcha Functions are organized into submodules (e.g., `string`, `list`, `web`). You must import directly from the submodule, not the top-level `trickkiste` package.
- gotcha The `web.get_request_data` function is specifically designed to work within a Flask application's request context. Calling it outside this context will result in a runtime error.
- gotcha The `web` module functions (e.g., `get_html_soup`, `get_request_data`) have external dependencies (`beautifulsoup4`, `requests`, `flask`) that are installed with `trickkiste`. Be aware of these if you only intend to use other utility functions.
Install
-
pip install trickkiste
Imports
- get_random_string
import trickkiste.string.get_random_string
from trickkiste.string import get_random_string
- get_random_item
import trickkiste.list
from trickkiste.list import get_random_item
- get_os_info
from trickkiste import system
from trickkiste.system import get_os_info
Quickstart
from trickkiste.string import get_random_string
from trickkiste.list import get_random_item
# Generate a random string of a specified length
random_str = get_random_string(length=10, alphabet='ascii_lowercase')
print(f"Random String: {random_str}")
# Get a random item from a list
my_list = ['apple', 'banana', 'cherry', 'date']
random_item = get_random_item(my_list)
print(f"Random Item from list: {random_item}")