Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Cython implementation of Python's collections.OrderedDict

Project Description

**This library is obsolete!** Python 3.5's ``collections.OrderedDict`` was `rewritten in C`_, and is now significantly faster than ``cyordereddict.OrderedDict`` for almost all operations.

.. _rewritten in C:


.. image::

.. image::

The Python standard library's ``OrderedDict`` ported to Cython. A drop-in
replacement that is 2-6x faster.

``pip install cyordereddict``

CPython (2.6, 2.7, 3.3 or 3.4) and a C compiler. Cython is only required
for the dev version.

.. code-block:: python

from cyordereddict import OrderedDict

Python 2.7:

================== ================================= =========================
Test Code Ratio (stdlib / cython)
================== ================================= =========================
``__init__`` empty ``OrderedDict()`` 1.8
``__init__`` list ``OrderedDict(list_data)`` 4.8
``__init__`` dict ``OrderedDict(dict_data)`` 4.6
``__setitem__`` ``ordereddict[0] = 0`` 8.6
``__getitem__`` ``ordereddict[0]`` 3
``update`` ``ordereddict.update(dict_data)`` 5.5
``__iter__`` ``list(ordereddict)`` 5.6
``items`` ``ordereddict.items()`` 5.9
``__contains__`` ``0 in ordereddict`` 2.3
================== ================================= =========================

Python 3.4:

================== ================================= =========================
Test Code Ratio (stdlib / cython)
================== ================================= =========================
``__init__`` empty ``OrderedDict()`` 1.5
``__init__`` list ``OrderedDict(list_data)`` 3.9
``__init__`` dict ``OrderedDict(dict_data)`` 4.2
``__setitem__`` ``ordereddict[0] = 0`` 8.4
``__getitem__`` ``ordereddict[0]`` 2.9
``update`` ``ordereddict.update(dict_data)`` 6.5
``__iter__`` ``list(ordereddict)`` 2.3
``items`` ``list(ordereddict.items())`` 2.1
``__contains__`` ``0 in ordereddict`` 2.3
================== ================================= =========================
To run these yourself, use ``cyordereddict.benchmark()``

``cyorderedddict.OrderedDict`` is an extension type (similar to the
built-in ``dict``) instead of a Python class. This is necessary for speed,
but means that in a few pathological cases its behavior will differ from

* The ``inspect`` module does not work on ``cyorderedddict.OrderedDict``
* Extension types use slots instead of dictionaries, so you cannot add
custom attributes without making a subclass (e.g.,
`` = 'bar'`` will fail).

You can do anything else you might do with an OrderedDict, including
subclassing: everything else passes the ``collections.OrderedDict`` test
suite. We based the Cython code directly on the Python standard library,
and thus use separate code bases for Python 2 and 3, specifically to
reduce the potential for introducing new bugs or performance regressions.

MIT. Based on the Python standard library, which is under the Python
Software Foundation License.

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


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
(138.2 kB) Copy SHA256 Hash SHA256
Source None Feb 5, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting