{"id":2542,"library":"itemadapter","title":"ItemAdapter","description":"ItemAdapter provides a common interface for various data container classes like dictionaries, dataclasses, attrs, Pydantic models, and Scrapy Items. It allows uniform access and manipulation of fields across different item types, simplifying data processing logic. The library is actively maintained by the Scrapy project, with frequent minor releases (roughly every 1-3 months) to keep up with Python versions and dependency updates. The current version is 0.13.1.","status":"active","version":"0.13.1","language":"en","source_language":"en","source_url":"https://github.com/scrapy/itemadapter","tags":["data structures","adapter","scrapy","dataclasses","attrs","pydantic"],"install":[{"cmd":"pip install itemadapter","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"ItemAdapter","correct":"from itemadapter import ItemAdapter"},{"symbol":"AdapterError","correct":"from itemadapter import AdapterError"}],"quickstart":{"code":"from dataclasses import dataclass\nfrom itemadapter import ItemAdapter\n\n# Define a simple dataclass item\n@dataclass\nclass ProductItem:\n    name: str\n    price: float\n    tags: list[str]\n\n# Create instances of different item types\ndataclass_item = ProductItem(name=\"Wireless Mouse\", price=25.99, tags=[\"electronics\", \"peripherals\"])\ndict_item = {\"name\": \"Mechanical Keyboard\", \"price\": 120.00, \"tags\": [\"gaming\", \"peripherals\"]}\n\n# Use ItemAdapter to interact with items uniformly\nadapter_dc = ItemAdapter(dataclass_item)\nadapter_dict = ItemAdapter(dict_item)\n\nprint(f\"Dataclass Item (Type: {type(adapter_dc.item)}):\")\nprint(f\"  Field Names: {adapter_dc.field_names()}\")\nprint(f\"  Name: {adapter_dc['name']}\")\nprint(f\"  Price (get_value): {adapter_dc.get_value('price')}\")\n\nprint(f\"\\nDictionary Item (Type: {type(adapter_dict.item)}):\")\nprint(f\"  Field Names: {adapter_dict.field_names()}\")\nprint(f\"  Name: {adapter_dict['name']}\")\nprint(f\"  Price (get_value): {adapter_dict.get_value('price')}\")\n\n# ItemAdapter also supports setting values if the underlying item is mutable\nif adapter_dc.is_mutable:\n    adapter_dc['price'] = 22.99\n    print(f\"\\nUpdated dataclass item price: {adapter_dc['price']}\")","lang":"python","description":"This quickstart demonstrates how to use `ItemAdapter` to create a unified interface for different item types, specifically a Python dataclass and a dictionary. It shows how to access field names and values using both dictionary-like access and `get_value()`, and how to check if an item is mutable for value assignment."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher if using itemadapter versions 0.10.0+.","message":"ItemAdapter has progressively dropped support for older Python versions. As of v0.10.0, Python 3.8 is no longer supported. Prior to this, v0.9.0 dropped 3.7, and v0.8.0 dropped 3.6. Ensure your Python environment meets the minimum requirement (Python 3.9+ for versions >=0.10.0).","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Remove any usage of these `itemadapter.utils` functions from your code. ItemAdapter's core functionality handles item type detection internally.","message":"The undocumented predicate functions `is_attrs_instance()`, `is_dataclass_instance()`, `is_pydantic_instance()`, and `is_scrapy_item()` from the `itemadapter.utils` module were deprecated in v0.5.0 and completely removed in v0.11.0.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"If you are using Pydantic v2, ensure you upgrade itemadapter to v0.11.0 or newer for full compatibility.","message":"Versions of itemadapter prior to v0.11.0 (e.g., v0.9.0 explicitly stated Pydantic >= 2 was not supported) do not properly support Pydantic v2 models. Using Pydantic v2 with older itemadapter versions will lead to incorrect behavior or errors.","severity":"gotcha","affected_versions":"<0.11.0 when used with pydantic>=2"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}