Item Lookups¶
Looking Up Items¶
To look up an item, use one of the following methods:
get(): Look up an item, raising an exception if it could not be found.get_or_none(): Look up an item, returningNoneif it could not be found.
class MyNewItem(BaseItem):
my_id = 'new-item'
my_registry.register(MyNewItem)
# Look up by attribute value (if the registry only uses a single
# lookup attribute).
item = my_registry.get('new-item')
# Look up by a specific lookup attribute:
item = my_registry.get(my_id='new-item')
# Look up and return None if the attribute could not be found.
item = my_registry.get_or_none('new-item')
When looking up, the following exceptions can be raised:
BaseRegistryItemLookupError: Base class for any lookup errors.ItemNotFoundLookupError: The item could not be found.
Check Item Registration¶
To check if an item is in the registry:
if item in my_registry:
...
Iterating Through Items¶
You can iterate through all items in the registry:
for item in my_registry:
...