{"id":7477,"library":"ordereddict","title":"OrderedDict (Python 2.x Backport)","description":"The 'ordereddict' library provides a backport of the `collections.OrderedDict` class, originally introduced in Python 2.7 and 3.1, for use in older Python 2.x environments (specifically Python 2.4, 2.5, and 2.6). It enables maintaining the insertion order of keys in a dictionary-like structure. This package is no longer maintained and serves only historical compatibility purposes for very old Python 2 projects.","status":"abandoned","version":"1.1","language":"en","source_language":"en","source_url":"https://github.com/twitter-archive/commons/blob/master/src/python/twitter/common/collections/ordereddict.py","tags":["ordered dictionary","python 2","backport","collections","legacy"],"install":[{"cmd":"pip install ordereddict","lang":"bash","label":"Install for Python 2.x"}],"dependencies":[],"imports":[{"note":"The 'collections' module import is for Python 2.7+ and 3.x. This package provides the 'ordereddict' module for older Python 2 versions.","wrong":"from collections import OrderedDict","symbol":"OrderedDict","correct":"from ordereddict import OrderedDict"}],"quickstart":{"code":"import sys\n\n# This library is for Python 2.x <= 2.6\n# For Python 2.7+ or 3.x, use 'from collections import OrderedDict'\n\nif sys.version_info < (2, 7) and sys.version_info >= (2, 4):\n    from ordereddict import OrderedDict\n    print(\"Using ordereddict backport\")\n    od = OrderedDict()\n    od['first'] = 1\n    od['second'] = 2\n    od['third'] = 3\n    print(od.items())\nelse:\n    print(\"This library is not needed for your Python version.\")\n    print(\"Use 'from collections import OrderedDict' instead.\")\n","lang":"python","description":"Demonstrates importing and using the `OrderedDict` class from the backport for Python 2.4-2.6. It includes a version check to highlight the library's specific compatibility window."},"warnings":[{"fix":"For Python 2.7+, use `from collections import OrderedDict`. For Python 3.7+, a regular `dict` maintains insertion order, so `OrderedDict` might only be needed for specific API compatibility or advanced features like `move_to_end` or order-sensitive equality comparisons.","message":"This 'ordereddict' library is obsolete for modern Python versions. `collections.OrderedDict` is built into Python 2.7, Python 3.1, and later. Furthermore, standard Python dictionaries (`dict`) guarantee insertion order since Python 3.7.","severity":"breaking","affected_versions":"Python 2.7+, Python 3.x"},{"fix":"Avoid using this backport unless strictly required for compatibility with Python 2.4-2.6. Prioritize `collections.OrderedDict` or standard `dict` where possible.","message":"The performance characteristics of this Python-based backport `ordereddict.OrderedDict` may differ significantly from the C-optimized `collections.OrderedDict` in newer Python versions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"For Python 2.4-2.6, ensure `pip install ordereddict` is run. For Python 2.7+ or 3.x, use `from collections import OrderedDict`.","cause":"Attempting to import `ordereddict` in a Python 3.x environment or a Python 2.x environment where the package was not installed, or using the wrong import for `collections.OrderedDict`.","error":"ImportError: No module named ordereddict"},{"fix":"In Python 2.4-2.6, use `from ordereddict import OrderedDict` and explicitly create an `OrderedDict` if insertion order is critical. In Python 2.7-3.6, use `from collections import OrderedDict`. In Python 3.7+, a standard `dict` maintains insertion order.","cause":"Attempting to iterate over a standard `dict` in insertion order in Python versions older than 3.7, or treating a `dict` as an `OrderedDict`.","error":"AttributeError: 'dict' object has no attribute 'items' (or similar methods maintaining order)"}]}