Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Backport/clone of ChainMap for py26, py32, and pypy3.

Project description

PyPI Package latest release PyPI Package monthly downloads Supported versions Supported implementations Wheel packaging support Test line coverage

This module is a polyfill, implementing ChainMap for reasonably-recent versions of Python that do not have collections.ChainMap–namely, Python 2.6, Python 3.2, and PyPy3 releases based on Python 3.2.

It is closely derived from Python 3.5 source code at, (especially the collections and reprlib modules). Several changes have been made to ensure Python 2.6 compatibility, and tests and packaging have been added.

Typical usage:

    from collections import ChainMap
except ImportError:
    from chainmap import ChainMap

This preferentially imports from the Python standard library if available, using the chainmap only when it isn’t otherwise available.

Optionally, you may import it all of the time:

from chainmap import ChainMap

Please see the standard documentation for details on how to use ChainMap.

If you’re not sure why someone would use a ChainMap, they are useful for managing “nested” contexts and “overlays.” See e.g. my options and say, which use them quite extensively for flexible option handling. You can find similar uses in the Context class of Django’s template engine.


To install or upgrade to the latest version:

pip install -U chainmap

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

python3.3 -m easy_install --upgrade chainmap

(You may need to prefix these with sudo 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.)

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
chainmap-1.0.0-py2.py3-none-any.whl (6.8 kB) Copy SHA256 hash SHA256 Wheel 2.7
chainmap-1.0.0.tar.gz (5.9 kB) Copy SHA256 hash SHA256 Source None (11.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page