libkosokoso -- a python/sqlalchemy tagging library
Go to file
chris t 04d4bbe556 minor cleanup 2020-07-19 15:07:01 -07:00
tests implement base merging 2020-07-19 15:02:58 -07:00
Readme.rst small fixes. 2018-12-11 00:42:49 -08:00
__init__.py initial commit, before cleanup. 2018-04-08 00:03:34 -07:00
kosokoso.py minor cleanup 2020-07-19 15:07:01 -07:00

Readme.rst

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head>

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. The tag object has a useful member, "collection", which provides direct access to the objects with this tag.

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.)

</html>