Skip to main content
PyPI Package latest release PyPI Package monthly downloads Supported versions Supported implementations

Just about all programs process “items” of one sort or another. That’s what loops are for, right?

But with the exception of the current loop value or index, programming languages don’t help track how processing is going. How many items have been successfully processed? How many errors are there? How far along the total job are we right now? Which items had problems that need to be looked at later?

Even though these bookkeeping tasks are essential to just about every program, they’re “left to the reader.” “Here are some basic loops. Have fun!” So developers “reinvent the wheel,” tracking status with ad hoc containers, counters, and status flags for every new program. Not so high-level after all, huh?

chores fights needless this complexity, errors, and effort by providing a simple, repeatable pattern for processing items and tracking their status.

The documentation can be found at Read the Docs.

Usage

from chores import Chores

chores = Chores('Jones able baker charlie 8348 Smith Brown Davis'.split())

for c in chores:
    status = 'name' if c.istitle() else 'other'
    chores.mark(c, status)

print chores.count('name'), "names,", \
      chores.count('^name'), "others"

Yields:

4 names, 4 others

Or if you decide you actually want more information, change just the output statements:

print todos.count('name'),  "names:", todos.marked('name')
print todos.count('^name'), "others:", todos.marked('^name')

Now you get:

4 names: ['Jones', 'Smith', 'Brown', 'Davis']
4 others: ['able', 'baker', 'charlie', '8348']

Discussion

Many programs track the status of items being processed with various lists, dictionaries, sets, counters, and status flags. chores might not seem a great advance at first, since it has the same kind of initialization and looping.

But it gets more interesting at the end of the processing loop, where the summary or report of what was processed, the disposition of each item worked on, what items yielded errors or other conditions, and what special cases were handled is produced.

In the examples above, we never had to keep a counter of how many names were found, or how many non-names. When we decided we wanted to change the output from summary counts to a full listing, we didn’t have go back and collect different information. We just differently displayed information already at at hand. Also note that the order of the results is nicely maintained. When we’re reviewing reports about “what transpired,” we don’t have to work very hard to correlate the results with the inputs; unlike when using dict and set structures, items are reported on in the same order they arrived.

Typically a developer will start with only a little thought about various dispositions for each item being processed. Over time, she’ll start to realize: “I need to count those cases, so I can report on them!” Or, “I kept an error counter, but I really should have been keeping a list of which items broke, because I now have to tell the user not just how many went wrong, but which ones in particular.” Or “I need to keep track of which ones failed the main processing so that I can do more intensive processing on just those special cases.” Then she’ll go back and add counters, collection lists, and so on–adding a fair amount of ad hoc code that must be built, tested, and debugged.

This is especially tricky for data that needs to move through multiple stages or phases of work. The developer then has to add structures to communicate from earlier processing steps to later ones.

With chores, there’s no need for such custom work. It takes over tracking which items led to which outcomes. It’s always ready to render quality information, either for reporting or for managing subsequent processing. Bookkeeping information is readily available in a tidy, logical format, with no additional development effort.

chores especially shows its virtues as processing code becomes more intricate and as program needs evolve over time.

Additional information can be found at Read the Docs.

Notes

  • I’ve successfully used chores in my own projects, and it has a real test suite. But realistically it should be considered “early beta” code. It’s explicitly part of experiment to up-level development tasks, so its API and mode of use will evolve.

  • chores is an example of “cross-cutting”–dealing with several apparently disconnected concerns in a concerted way because they are, in fact, connected, and need to be handled systematically.

  • Automated multi-version testing managed with the wonderful pytest and tox. Successfully packaged for, and tested against, all late-model versions of Python: 2.6, 2.7, 3.2, 3.3, and 3.4, as well as PyPy 2.6.0 (based on 2.7.9) and PyPy3 2.4.0 (based on 3.2.5). Should run fine on Python 3.5, though py.test is broken on its pre-release iterations.

  • The author, Jonathan Eunice or @jeunice on Twitter welcomes your comments and suggestions.

Installation

To install or upgrade to the latest version:

pip install -U chores

To easy_install under a specific Python version (3.3 in this example):

python3.3 -m easy_install --upgrade chores

(You may need to prefix these with sudo command to authorize installation. In environments without super-user privileges, you may want to use pip’s --user option, to install only for a single user, rather than system-wide.)

Metadata

Release files for chores 0.6.3

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

Source distributions (sdists)

Source distribution for chores 0.6.3
File Size Uploaded
chores-0.6.3.zip 20.6 kB Details
chores-0.6.3.tar.gz 11.6 kB Details

Release files / chores-0.6.3.zip

Download URL chores-0.6.3.zip
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
aa97e3fa7174d17264b617721ad36a2d506954977ac3f9b370796531a5898f05
BLAKE2b-256 checksum
How to use checksums
c5a1929f240f0dbec1f1d589f422a323f396875d98b2d13b94c602015cacc1b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / chores-0.6.3.tar.gz

Download URL chores-0.6.3.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b5e3f7181c19615ece95bf44baa10491b9524e9853ab01453bc59dac9d397c5b
BLAKE2b-256 checksum
How to use checksums
1cdad555c2ad3df0b0b544c6c8d569790bcd4f3d6ef32aed8266d8ec74d9cea5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6.3 This release

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6

2 release files

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