1.3 KiB
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.
It's also possible to add kk.Tag objects directly to the tags property, but they'll be treated as strings. To access the tag objects, do something like:
return [ta.tag_obj for ta in a.kk_tag_associations]
This will bypass the association proxy and return a list of Tag objects.
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 extremely 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.)