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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pockets-0.7.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pockets-0.7-py2.py3-none-any.whl (24.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pockets-0.7.tar.gz.

File metadata

  • Download URL: pockets-0.7.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.3

File hashes

Hashes for pockets-0.7.tar.gz
Algorithm Hash digest
SHA256 b25a81479f23219dea890414c70f9d69555633f2d46fc516a70826030d44f95e
MD5 7dee5950058a6518505f8a6f4992a93f
BLAKE2b-256 9174e4a2d5303560689416bb2be3fd9b2d6cb20b782ec369ac2df905d2914810

See more details on using hashes here.

File details

Details for the file pockets-0.7-py2.py3-none-any.whl.

File metadata

  • Download URL: pockets-0.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.3

File hashes

Hashes for pockets-0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ae6e0908907b5b79bc21e06d472aca403aa88c1a7128a5d3cca33bdfaf76c326
MD5 7d23c5799bcce59b063f1e51fb000510
BLAKE2b-256 ec3832fa34b6d222db3db3e8e206251b5b55ead643bd7ca4ceb651d3b29bdfc6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page