Libkosokoso -- simple tagging with sqlalchemy. ============================================== Libkosokoso provides compact and table-stingy tags to sqlalchemy-backed objects. Usage ----- :: import libkosokoso as kk class Foo(kk.Taggable): __tablename__ = 'foos' a = Foo() a.tags.append('tag1') a.tags.extend(['tag2', 'tag3']) and so forth. This will generate tables like this:: foos: db_id 1 kk_tag_associations: db_id tag_id target_table target_id 1 1 foos 1 2 2 foos 1 3 3 foos 1 kk_tags: db_id text 1 tag1 2 tag2 3 tag3 To access the tags:: for i in a.tags: print(i) tag1 tag2 tag3 The tags member gives you a list of tag strings. To access the tag objects, iterate the kk_tag_associations member:: return [ta.tag_obj for ta in a.kk_tag_associations] This will bypass the association proxy and return a list of Tag objects. It's also possible to add kk.Tag objects directly to the tags property on a taggable object, and they'll be handled correctly. Design considerations --------------------- My basic reasoning was that at some point I'd have to go and muck about in the database by hand, and I wanted a structure that was easy to perceive and modify. I explicitly did not aim for efficiency. The underlying code is object-happy and probably very inefficient. Why is it called that? ---------------------- "kosokoso" is Japanese onomatopoeia for sneaking or whispering secretly. I picked the name because tags always feel like a kind of buzzing side channel to me. (Originally, it was "guzuguzu", which is, like, slow. This took me way longer to write than I was expecting.)