Registry / serialization / itemadapter

itemadapter

JSON →
library0.13.1pypypi✓ verified 30d ago

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.

pip install itemadapter
INSTALL
IMPORT
SIG · ITEMADAPTER
I
itemadapter
serializationpythonv0.13.1
Install
1.6s avg
Import
46ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.13.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.048s · 17.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.044s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ItemAdapter
✓ from itemadapter import ItemAdapter
AdapterError
✓ from itemadapter import AdapterError

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.

from dataclasses import dataclass from itemadapter import ItemAdapter # Define a simple dataclass item @dataclass class ProductItem: name: str price: float tags: list[str] # Create instances of different item types dataclass_item = ProductItem(name="Wireless Mouse", price=25.99, tags=["electronics", "peripherals"]) dict_item = {"name": "Mechanical Keyboard", "price": 120.00, "tags": ["gaming", "peripherals"]} # Use ItemAdapter to interact with items uniformly adapter_dc = ItemAdapter(dataclass_item) adapter_dict = ItemAdapter(dict_item) print(f"Dataclass Item (Type: {type(adapter_dc.item)}):") print(f" Field Names: {adapter_dc.field_names()}") print(f" Name: {adapter_dc['name']}") print(f" Price (get_value): {adapter_dc.get_value('price')}") print(f"\nDictionary Item (Type: {type(adapter_dict.item)}):") print(f" Field Names: {adapter_dict.field_names()}") print(f" Name: {adapter_dict['name']}") print(f" Price (get_value): {adapter_dict.get_value('price')}") # ItemAdapter also supports setting values if the underlying item is mutable if adapter_dc.is_mutable: adapter_dc['price'] = 22.99 print(f"\nUpdated dataclass item price: {adapter_dc['price']}")
Debug
Known issues
breakingItemAdapter 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).
fix
Upgrade your Python environment to 3.9 or higher if using itemadapter versions 0.10.0+.
affects: >=0.8.0
breakingThe 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.
fix
Remove any usage of these `itemadapter.utils` functions from your code. ItemAdapter's core functionality handles item type detection internally.
affects: >=0.11.0
gotchaVersions 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.
fix
If you are using Pydantic v2, ensure you upgrade itemadapter to v0.11.0 or newer for full compatibility.
affects: <0.11.0 when used with pydantic>=2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'itemadapter'
The 'itemadapter' library is not installed in the Python environment where the code is being executed.
fix
Install the library using pip: `pip install itemadapter`
TypeError: No adapter found for objects of type: <class 'itemadapter.adapter.ItemAdapter'>
You are attempting to create an `ItemAdapter` instance by passing an already existing `ItemAdapter` object to its constructor, instead of the original data item (e.g., a dictionary, a dataclass, or a Scrapy Item).
fix
Pass the actual data item to `ItemAdapter`, not an already-wrapped adapter. For example, if `adapter` is an `ItemAdapter` instance, use `adapter.item` to get the original item.
AttributeError: 'list' object has no attribute 'date'
A field accessed through `ItemAdapter` unexpectedly returned a list, and you attempted to call a method or access an attribute (like `.date()`) directly on that list, which is a common mistake when a field might contain single or multiple values.
fix
Before accessing attributes or methods, check if the retrieved value is a list. If it is, iterate through the list or access a specific element (e.g., `item_adapter['date_field'][0].date()` if you expect a single date within a list).
KeyError: 'field_name'
You are trying to access a field (key) on an `ItemAdapter` instance that does not exist in the underlying data item it wraps.
fix
Ensure the field name is correct and present in the item. Alternatively, use the `.get()` method (e.g., `adapter.get('field_name', default_value)`) to provide a default value if the field might be missing, preventing a `KeyError`.
Upgrade
Version history
0.13.1latest on PyPI · released Jan 8, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
itemadapter — pip install itemadapter · libregistry