A collection of helpful Python tools!
The Pockets library pulls together all the Python helper functions I’ve found useful over the years.
If you’ve worked on a project that exports an API and accesses a data store, you’ve probably seen some code that looks like this:
# Receive a data type with underscores from some API data_type = 'user_preference' # Convert underscored data type to CamelCase to match the data model model_name = camel(data_type) # Resolve the model name into a model class model_class = resolve(model_name, modules=["webapp.model.admin", "webapp.model.user", "webapp.model.businesslogic"] # Instantiate the model class and do stuff with the instance... instance = model_class()
There’s an impedance mismatch any time you work with two different frameworks; especially when you want to update your back-end while maintaining legacy compatibility with an external API.
Pockets is full of highly tested, well maintained functions that help bridge the gap. Here are just a few examples…
Easily get the right logger no matter where you are
>>> from pockets.autolog import log >>> log.error("Always log from the correct module.Class!") mymodule.MyClass: Always log from the correct module.Class!
Convert underscore_separated string to CamelCase
>>> from pockets import camel >>> camel("xml_http_request", upper_segments=) 'XmlHTTPRequest'
Convert CamelCase string to underscore_separated
>>> from pockets import uncamel >>> uncamel("XmlHTTPRequest") 'xml_http_request'
Resolve a string into an object
>>> from pockets import resolve >>> resolve("calendar.TextCalendar") <class 'calendar.TextCalendar'>
Peek ahead iterator
>>> from pockets import peek_iter >>> p = peek_iter(["a", "b", "c", "d", "e"]) >>> p.peek() 'a' >>> p.next() 'a' >>> p.peek(3) ['b', 'c', 'd']
Full documentation is available on Read the Docs.
Built packages are available on PyPI.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|pockets-0.5.1-py2.py3-none-any.whl (20.8 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||May 2, 2017|
|pockets-0.5.1.tar.gz (18.4 kB) Copy SHA256 Checksum SHA256||–||Source||May 2, 2017|