Pockets full of Python tools!
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs Bumps version to 0.6. Updates copyright date to 2018. Feb 15, 2018
pockets
tests Adds "key" parameter to pockets.collections.uniquify() Sep 29, 2018
.gitignore Adds datetime module, plus a bunch of new functions: Feb 15, 2018
.travis.yml Drops py33 from Travis matrix Sep 18, 2018
AUTHORS Bumps version to 4.0. Adds collections.uniquify, autolog and logging … Apr 29, 2017
CHANGES Bumps version to 0.7.1 Sep 29, 2018
LICENSE Bumps version to 0.6. Updates copyright date to 2018. Feb 15, 2018
MANIFEST.in Adds AUTHORS file and updates copyright notices Feb 19, 2015
README.rst
requirements.txt Lowers required version for six==1.5.2 Mar 23, 2015
requirements_docs.txt
requirements_test.txt Adds datetime module, plus a bunch of new functions: Feb 15, 2018
setup.cfg Better exception reporting in pockets.inspect.resolve(), pockets.insp… Sep 21, 2018
setup.py Bumps version to 0.6. Updates copyright date to 2018. Feb 15, 2018
tox.ini flake8 Sep 21, 2018

README.rst

Pockets full of useful Python tools!

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