humane magica

Libbokka

Libbokka is a small package our python developers use on daily basis. Most of our web projects is built over libbokka. For example, L000T does so.

Libbokka is a pack of 4 script-files, which simplifies usage of

JSON converting

Simplejson is really simple. How can it be simplier? Look:

>>> import libbokka
>>> print libbokka.toJson( test=[1,2,3], str="string", dt=datetime.datetime.now()) )
>>> print libbokka.fromJson('{"t":6, "a":5}')

Libbokka json encoder is datetime-aware, it is small addendum to simplejson exceptional functionality.

SQL absctration

Web.py is good, we need only a unified way to:

TemplateEngine abstraction

Mako is fine, but complicated a bit to just call it directly. So:

>>> import libbokka
>>> print libbokka.tpl("test.html", param=value)

NB: templates must be located in "templates/" folder, but you can relocate it.

If you use web.py (as we do), you can find useful our Static controller.

XML converting to pythonic structures

We all love Elementtree.
We'ld love to receive simple python dicts from complicated XML.
So we configure ruleset:

>>> ruleset =  {
       "foaf:nick" : "text",
       "foaf:name" : "text",
       "foaf:dateOfBirth" : "text",
       "foaf:tagLine" : "text",
       "foaf:img" : "rdf:resource",
       "foaf:interest" : ["dc:title", "rdf:resource"],
    }

And then extract pythonic data from XML:

>>> print libbokka.dexml( person, p, none="", strip_shortcuts=True )

NB: "person" in our example contains very complicated FOAF XML from LiveJournal; it is prepared this way:

>>> data = openanything.fetch( "http://freeformfactor.livejournal.com/data/foaf" )["data"]
>>> feed = ET.XML(data)
>>> person = feed.find( libbokka.ns("foaf:Person") )



Check out current version

You can check out fresh and up-to-date version of libbokka from SVN repository:
http://svn.humanemagica.com/libbokka/trunk

NB: Contents of examples/libs are provided AS-IS from some other respected developers.
It contains:

Those packages are enlisted only for quick examples startup, they are not necessary for distribution of libbokka.

Moreover, libbokka is only contented folder with same name.