pockets
The Pockets library is a collection of Python helper functions that streamline common development tasks. It provides utilities for logging, collections, datetime manipulation, object inspection, string operations, and iterators. The current version is 0.9.1, last updated in November 2019, suggesting a maintenance or slow release cadence.
Warnings
- breaking The library's last update was in November 2019. While it aims for Python 2/3 compatibility, this old version may have compatibility issues or lack features with newer Python 3.x releases (e.g., Python 3.10+).
- gotcha The `resolve` function, which converts a string name into a Python object, can be a security risk if the input string is from an untrusted source. Malicious input could lead to arbitrary code execution.
- deprecated Some classes in `pockets.iterators` were renamed in version 0.9 (e.g., `modify_iter` to `itermod`, `peek_iter` to `iterpeek`). While original names are still exported for backwards compatibility, relying on them might lead to issues in future versions if they are eventually removed.
- gotcha The library's reliance on `six` and notes about Python 2.6 specific behaviors (e.g., `groupify` returning regular dicts instead of OrderedDicts) suggest it was developed with older Python versions in mind. Using it in a modern Python 3-only project might introduce unnecessary overhead or less Pythonic patterns.
Install
-
pip install pockets
Imports
- log
from pockets.autolog import log
- camel
from pockets import camel
- uncamel
from pockets import uncamel
- resolve
from pockets import resolve
- iterpeek
from pockets import iterpeek
- groupify
from pockets.collections import groupify
Quickstart
from pockets import camel, uncamel, resolve, iterpeek
# String utilities
camel_case_str = camel("xml_http_request", upper_segments=[1])
print(f"Camel case: {camel_case_str}")
underscore_str = uncamel("XmlHTTPRequest")
print(f"Underscore case: {underscore_str}")
# Object resolution
list_class = resolve("builtins.list")
print(f"Resolved object: {list_class}")
# Iterator peeking
p = iterpeek(["a", "b", "c", "d", "e"])
print(f"Peek next: {p.peek()}")
print(f"Next item: {next(p)}")
print(f"Peek 3 items: {p.peek(3)}")