Let me check my pockets…
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…
Convert underscore_separated string to CamelCase
>>> from pockets import camel
>>> camel("xml_http_request", upper_segments=[1])
'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']
Downloads and Docs
Full documentation is available on Read the Docs.
Built packages are available on PyPI.
Source code is available on GitHub. Feel free to:
Create an issue to request a feature or a report a bug.
Fork the repository and make changes to the master branch for next release.
Send a pull request and pester the maintainer until it’s merged. Make sure to add yourself to AUTHORS and update CHANGES.
Build Status
Release files for pockets 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pockets-0.2.2.tar.gz | 19.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pockets-0.2.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 42.2 kB
Release files / pockets-0.2.2.tar.gz
| Download URL | pockets-0.2.2.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4f5eb05da0e6f3277857cd14046253d6131d16d4cd966b3d7fee672683c48c3
|
|
BLAKE2b-256 checksum How to use checksums |
df67dcd0d299e9d6875ee72edaae7fc67706d5fb5110c0c1d71a0a554af11cdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pockets-0.2.2-py2.py3-none-any.whl
| Download URL | pockets-0.2.2-py2.py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a2e52aee33d7465f36638046920e849baab62f03453b63a2deeee709e34763b4
|
|
BLAKE2b-256 checksum How to use checksums |
835c3db6d845f4fd18a64957bcf606152e0e77c1346a1ef17437b5db29c61031
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |