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 from and to (using simplejson);
- SQL abstraction over web.py framework;
- TPL abstraction over mako;
- XML converting to custom python structures (using ElementTree toolkit).
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.
Web.py is good, we need only a unified way to:
- create tables
>>> print libbokka.create( 'users', '__ID__, name varchar(1), active INT, about TEXT' )
- workaround "random() or rand()"
>>> print libbokka.rand()
- workaround and datetime issues
>>> print libbokka.dtstr(datetime.datetime.now())
>>> print libbokka.dtstr('2008-01-08 00:00:12')
>>> print libbokka.dtobj(datetime.datetime.now())
>>> print libbokka.dtobj('2008-01-08 00:00:12')
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.
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") )
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:
- web.py framework (http://webpy.org) and flup
- mako templates engine (http://makotemplates.org)
- elementtree xml library (http://effbot.org/zone/element-index.htm)
- OpenAnything library (http://diveintopython.org/)
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.