README.rst
1Pockets full of useful Python tools!
2====================================
3
4*Let me check my pockets...*
5----------------------------
6
7The Pockets library pulls together many of the Python helper functions I've
8found useful over the years.
9
10If you've worked on a project that exports an API and accesses a data store,
11you've probably seen some code that looks like this::
12
13 # Receive a data type with underscores from some API
14 data_type = 'user_preference'
15
16 # Convert underscored data type to CamelCase to match the data model
17 model_name = camel(data_type)
18
19 # Resolve the model name into a model class
20 model_class = resolve(model_name, modules=["webapp.model.admin",
21 "webapp.model.user",
22 "webapp.model.businesslogic"]
23
24 # Instantiate the model class and do stuff with the instance...
25 instance = model_class()
26
27
28There's an impedance mismatch any time you work with two different frameworks;
29especially when you want to update your back-end while maintaining legacy
30compatibility with an external API.
31
32Pockets is full of highly tested, well maintained functions that help bridge
33the gap. Here are just a few examples...
34
35.. rubric :: Easily get the right logger no matter where you are
36
37::
38
39 >>> from pockets.autolog import log
40 >>> log.error("Always log from the correct module.Class!")
41 mymodule.MyClass: Always log from the correct module.Class!
42
43.. rubric :: Convert underscore_separated string to CamelCase
44
45::
46
47 >>> from pockets import camel
48 >>> camel("xml_http_request", upper_segments=[1])
49 'XmlHTTPRequest'
50
51.. rubric :: Convert CamelCase string to underscore_separated
52
53::
54
55 >>> from pockets import uncamel
56 >>> uncamel("XmlHTTPRequest")
57 'xml_http_request'
58
59.. rubric :: Resolve a string into an object
60
61::
62
63 >>> from pockets import resolve
64 >>> resolve("calendar.TextCalendar")
65 <class 'calendar.TextCalendar'>
66
67.. rubric :: Peek ahead iterator
68
69::
70
71 >>> from pockets import iterpeek
72 >>> p = iterpeek(["a", "b", "c", "d", "e"])
73 >>> p.peek()
74 'a'
75 >>> p.next()
76 'a'
77 >>> p.peek(3)
78 ['b', 'c', 'd']
79
80
81Downloads and Docs
82------------------
83
84Full documentation is available on `Read the Docs
85<http://pockets.readthedocs.org>`_.
86
87Built packages are available on `PyPI <https://pypi.python.org/pypi/pockets>`_.
88
89`Source code <https://github.com/RobRuana/pockets>`_ is available on `GitHub
90<https://github.com/RobRuana/pockets>`_. Feel free to:
91
92- `Create an issue <https://github.com/RobRuana/pockets/issues>`_ to request a
93 feature or a report a bug.
94- `Fork the repository <https://github.com/RobRuana/pockets/fork>`_ and make
95 changes to the **master** branch for next release.
96- Send a pull request and pester the maintainer until it's merged. Make sure
97 to add yourself to `AUTHORS
98 <https://github.com/RobRuana/pockets/blob/master/AUTHORS>`_ and update
99 `CHANGES <https://github.com/RobRuana/pockets/blob/master/CHANGES>`_.
100
101
102Build Status
103------------
104
105.. image:: https://travis-ci.org/RobRuana/pockets.svg
106 :target: https://travis-ci.org/RobRuana/pockets
107 :alt: Build Status
108
109
110.. image:: https://coveralls.io/repos/RobRuana/pockets/badge.svg
111 :target: https://coveralls.io/r/RobRuana/pockets
112 :alt: Coverage Status
113
114
115.. image:: https://readthedocs.org/projects/pockets/badge/?version=latest
116 :target: https://readthedocs.org/projects/pockets/?badge=latest
117 :alt: Documentation Status
118
119