{"id":7865,"library":"wimpy","title":"Wimpy","description":"Wimpy is a Python utility library (anti-copy-pasta) containing commonly used helper functions that the author extracted to avoid repeatedly copying them into new projects. It provides a collection of small, general-purpose utilities for everyday Python programming tasks. The library is currently at version 0.6 and is actively maintained, with releases focusing on adding new features and improving existing ones.","status":"active","version":"0.6","language":"en","source_language":"en","source_url":"https://github.com/wimglenn/wimpy","tags":["utility","helpers","string-manipulation","iterable-processing"],"install":[{"cmd":"pip install wimpy","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"symbol":"strip_prefix","correct":"from wimpy import strip_prefix"},{"symbol":"strip_suffix","correct":"from wimpy import strip_suffix"},{"symbol":"is_subsequence","correct":"from wimpy import is_subsequence"},{"symbol":"chunks","correct":"from wimpy import chunks"},{"symbol":"grouper","correct":"from wimpy import grouper"},{"symbol":"ceiling_division","correct":"from wimpy import ceiling_division"},{"note":"WimpyError resides in the 'exceptions' submodule, not directly under 'wimpy'.","wrong":"from wimpy import WimpyError","symbol":"WimpyError","correct":"from wimpy.exceptions import WimpyError"}],"quickstart":{"code":"from wimpy import strip_prefix, is_subsequence, chunks\n\n# Example 1: Stripping prefixes\ntext = \"hello_world\"\nstripped_text = strip_prefix(text, \"hello_\")\nprint(f\"Original: {text}, Stripped: {stripped_text}\")\n\n# Example 2: Checking for subsequence\nsequence = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\nsub = [2, 5, 8]\nis_sub = is_subsequence(sub, sequence)\nprint(f\"Is {sub} a subsequence of {sequence}? {is_sub}\")\n\n# Example 3: Chunking an iterable\ndata = list(range(10))\nchunk_size = 3\noverlap = 1\nresult_chunks = list(chunks(data, chunk_size, overlap))\nprint(f\"Original data: {data}, Chunks (size={chunk_size}, overlap={overlap}): {result_chunks}\")\n","lang":"python","description":"Demonstrates stripping prefixes, checking for subsequences, and creating overlapping chunks from an iterable, which are core utilities provided by the library."},"warnings":[{"fix":"If you require an error for missing prefixes/suffixes, explicitly set `strict=True`. Otherwise, the default behavior of returning the original string when not found remains.","message":"The `strip_prefix` and `strip_suffix` functions in v0.6+ introduce a `strict` parameter (default `False`). If `strict=True`, the function will raise a `WimpyError` if the prefix/suffix is not found. Prior to v0.6, there was no `strict` option, and missing prefixes/suffixes would simply return the original string.","severity":"gotcha","affected_versions":"0.6 and later"},{"fix":"Upgrade to wimpy v0.6 or later to ensure correct handling of all `overlap` values, including negative ones.","message":"The `chunks` function had a bug in versions prior to v0.6 where negative `overlap` values were not handled correctly and could lead to unexpected results. This was fixed in v0.6.","severity":"gotcha","affected_versions":"Prior to 0.6"},{"fix":"Always check the return value, or for versions 0.6+, use `strict=True` if you prefer an explicit error when the prefix/suffix is absent.","message":"The `strip_prefix` and `strip_suffix` functions by default will silently return the original string if the specified prefix or suffix is not found. This might be unexpected if you anticipated an empty string or an error.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change the import statement to `from wimpy.exceptions import WimpyError`.","cause":"The `WimpyError` exception is located in the `wimpy.exceptions` submodule, not directly in the top-level `wimpy` module.","error":"from wimpy import WimpyError\nModuleNotFoundError: No module named 'WimpyError'"},{"fix":"Either ensure the prefix/suffix always exists, or handle the `wimpy.exceptions.WimpyError` exception, or remove `strict=True` to revert to the default behavior of returning the original string when the prefix/suffix is missing.","cause":"You are using `strip_prefix` or `strip_suffix` with `strict=True`, and the specified prefix/suffix was not present in the target string.","error":"wimpy.exceptions.WimpyError: Prefix 'non_existent_' not found in 'hello_world'"}]}