Chandler supports adding keywords (AKA tags) to items using the Keyword class and ItemKeywords add-on.
>>> from chandler.core import *
>>> from chandler.keyword import *
>>> item = Item()
Keyword objects are Collections.
>>> dog = Keyword('dog')
>>> dog
<Keyword: dog>
>>> dog.add(item)
>>> item in dog.items
True
>>> dog.title
'Tag: dog'
There will be one global Keyword for any given word.
>>> dog == Keyword('dog')
True
Adding or removing an item from a Keyword adds the word to ItemKeywords.keyword_strings
>>> item_keywords = ItemKeywords(item)
>>> item_keywords.keyword_strings
Set(['dog'])
>>> dog.remove(item)
>>> item_keywords.keyword_strings
Set([])
Similarly you can add a word (really, any string) to keyword_strings and the related Keyword will be updated.
>>> item_keywords.keyword_strings.add('dog')
>>> item in dog.items
True