Setup
Installation
pip install zyte-common-items
Scrapy configuration
If you use Scrapy, zyte-common-items provides some functionality that needs configuring:
If using Scrapy 2.10 or higher, enable the add-on:
settings.pyADDONS = { "zyte_common_items.Addon": 400, }
The add-on:
Appends
ZyteItemAdapterto itemadapter.ItemAdapter.ADAPTER_CLASSES if neitherZyteItemAdapternorZyteItemKeepEmptyAdapterare already there.Sets
LOG_FORMATTERtoZyteLogFormatterif a custom log formatter is not already set (i.e. withaddonpriority, seeSETTINGS_PRIORITIES).
If using Scrapy 2.9 or lower, apply those configurations manually as needed.
itemadapter configuration
Tip
You do not need to set this manually if you are using the Scrapy add-on.
To allow itemadapter to interact with items, prepend
ZyteItemAdapter or
ZyteItemKeepEmptyAdapter to
itemadapter.ItemAdapter.ADAPTER_CLASSES as early as possible in your code:
from itemadapter import ItemAdapter
from zyte_common_items import ZyteItemAdapter
ItemAdapter.ADAPTER_CLASSES.appendleft(ZyteItemAdapter)
Alternatively, make your own subclass of itemadapter.ItemAdapter:
from collections import deque
from itemadapter import ItemAdapter
from zyte_common_items import ZyteItemAdapter
class MyItemAdapter(ItemAdapter):
ADAPTER_CLASSES = deque([ZyteItemAdapter]) + ItemAdapter.ADAPTER_CLASSES
Now you can use MyItemAdapter where you would use
itemadapter.ItemAdapter.