Skip to main content

Let me check my pockets…

The Pockets library pulls together many of 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=[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 iterpeek
>>> p = iterpeek(["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

Build Status Coverage Status Documentation Status

Release files for pockets 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pockets 0.9.1
File Size Uploaded
pockets-0.9.1.tar.gz 25.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pockets 0.9.1
File Interpreter ABI Platform
pockets-0.9.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 51.3 kB

Release files / pockets-0.9.1.tar.gz

Download URL pockets-0.9.1.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9320f1a3c6f7a9133fe3b571f283bcf3353cd70249025ae8d618e40e9f7e92b3
BLAKE2b-256 checksum
How to use checksums
df8e0601097cfcce2e8c2297db5080e9719f549c2bd4b94420ddc8d3f848bbca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / pockets-0.9.1-py2.py3-none-any.whl

Download URL pockets-0.9.1-py2.py3-none-any.whl
Size 26.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
68597934193c08a08eb2bf6a1d85593f627c22f9b065cc727a4f03f669d96d86
BLAKE2b-256 checksum
How to use checksums
e92fa4583c70fbd8cd04910e2884bcc2bdd670e884061f7b4d70bc13e632a993
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9

2 release files

0.8

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7

2 release files

0.6.8

2 release files

0.6.7

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page