October 11 2013

Get Nikola

I like static web-sites, always have. More than that I like blogging sites with lots of capability. Mostly I've rolled my own there and have done for some years now.

Best of all worlds for me would be a package that can produce a static blog site but with lots of capability, provided that same package can also easily produce without contortions web sites that aren't "blogs".


Get Nikola. It does all of the above and is under active development.

I've long seen Nikola mentioned in Roberto Alsina's posts that make their way through to Planet Python but only very recently have I taken the time to install it to a virtual environment and have a go. I like it so much I'm converting a bunch of static sites I host for various non-profit organizations and took on the task of developing a new site for another non-profit because I knew I had a useful tool in my back pocket.

Thanks Roberto and the greater Nikola universe for making my day (evening) a little easier.

August 22 2013

Evening, Nanaimo Estuary

View from the deck of the cafe at Living Forest Camp Ground.


In conjunction with BC Family French Camp held each summer (Nanaimo, Salmon Arm, Guillam Lake), we've been coming here for years. French camp or not, it's well worth a visit!

August 11 2013

Morning, Upper Joffre Lake

View out my tent Saturday morning...

Upper Joffre Lake, Joffre Lakes Provincial Park, BC

June 12 2013

Python Fastest Template Engine?

I've not written anything relating to Python for ages but today a two-fer with a post announcing (since the authors aren't publicity hounds) an update to DurusWorks, and this post on string templating in Python which came about only because Andriy Kornatskyy, the author of Wheezy.template, happened to update his results table.

Since I needed to test the new DurusWorks and the QPY templating package out anyway, I cooked up two entries for the bigtable.py benchmark. The first example utilizes QPY's smart-string escaping found in xml() and join_xml(), and, happily, this code looks almost identical (for a reason) to the standard lib inspired list_append "template" function found in bigtable.py:

from qpy import xml, join_xml
def test_qpy_list_append():
    b = []
    w = b.append
    table = ctx['table']
    for row in table:
        for key, value in row.items():
    return join_xml(b)

Look at the results table at the end of this post and you'll see QPY is pretty fast compared to plain-ol-string operations given smart XML escaping is going on too. QPY's xml type is a subclass of Python's string class; QPY provides a C extension module for performance.

So that was fast, but coding web applications that way gets ugly even faster. Fortunately for no pain and all the gain, you can rewrite the above as:

def test_qpy_template:xml ():
    table = ctx['table']
    for row in table:
        for key, value in row.items():

And even better, string substitutions don't get in the way of performance or smart escaping of untrusted input:

def test_qpy_template_sub:xml ():
    table = ctx['table']
    for row in table:
        for key, value in row.items():
            '<td>%s</td><td>%s</td>\n' % (key, value)

Or, if Python 3's .format() method turns your crank more:

def test_qpy_template_fmt:xml ():
    table = ctx['table']
    for row in table:
        for key, value in row.items():
            '<td>{}</td><td>{}</td>\n'.format(key, value)

Now we're talking. With these last two examples it becomes clearer that QPY templates turn traditional templating upside down in that QPY offers a sane mechanism to have content-in-code rather than code-in-content which is the common approach to HTML templating.

QPY's style will be an acquired taste for some, and is definitely not suitable for non-programmers.

Comparative results table:

Linux Mint Debian Edition, Virtual Machine on a high end Windows box
2 Cores configured, 4GB RAM

(wz)  % python3 bigtable.py

                    msec    rps  tcalls  funcs
chameleon          35.61  28.08  182033     25
cheetah                   not installed
django            504.84   1.98 1503067     51
jinja2             28.18  35.48   60020     27
list_append        33.07  30.24  103008     12
list_extend        32.96  30.34   63008     12
mako               24.24  41.26   93036     37
qpy_list_append    17.23  58.02   53008      9
qpy_template       17.06  58.63   53008      9
qpy_template_fmt   24.44  40.92   23008     10
qpy_template_sub   13.98  71.55   13008      9
tenjin             21.40  46.73  123012     16
tornado            76.35  13.10  353023     23
web2py                    not installed
wheezy_template    34.15  29.28  103010     14

In general the relative performance between tools looks to match Andriy's own results except for his own tool wheezy.template, and I can't account for why that would be so, but no doubt Andriy will sort things out soon.

The truly good news is there are a number of well-done, fast-enough templating solutions for Python web application developers to lean on so pick the one(s) that fit your head or project best and move on!

June 11 2013

DurusWorks 1.2, Dulcinea updates released

DurusWorks 1.2, born of QP, born of the venerable Quixote web framework, has been released. DW includes the Python object database Durus, a ZODB work-a-like with less complexity. Durus, like ZODB, has uses that go far beyond web development.

Dulcinea, a DW/QP centric package of objects, UI, and helpers, has also been updated.

QP, Durus, and DurusWorks have supported Python 2.x and Python 3.x from the same code base for years and can be found here: https://www.mems-exchange.org/software/

April 09 2013

Two Faces of Education Minister Don MacRae

For those who don't know who Don McRae is, he is the current in a long line of BC Education Ministers. The BC Liberal government has a habit of chewing through Education ministers which probably tells you they don't care much for the file.

You'd think Don's experience as a teacher would be useful in his ministerial role but since his appointment it has become quite clear that he can't, or isn't allowed to, think for himself. Instead all he spouts is party doctrine.

The video is a dramatization of an actual letter he wrote when he was a teacher, not a politician, to then education Shirley Bond, one of BC's worst-ever education ministers although Christy Clark and Margaret MacDiarmid were both awful too.

In the video teacher-McRae laments over class size and composition. As minister-McRae he tells teachers and parents that these aren't issues at all.

Which version of McRae do you believe?

February 20 2013



Christy Clark's B.C. Liberals may well be looking for the exit door soon.

Martyn Brown, former premier Gordon Campbell's chief of staff, doesn't think yesterday's budget holds good news for his party.

"I think the only ones jumping for joy today, really, will be the NDP because, effectively, this government has done the dirty work of saying it needs to increase corporate taxes, it needs to increase personal taxes on higher income earners, it's increasing MSP premiums."

Source: CBC, Liberal insider tears strip off B.C. budget

February 12 2013

Foggy Family Day


Thank you, B.C. government, for declaring a new stat holiday. We needed one in February and my family are fortunate enough that we all have a day off work and school and can be together with friends and family.

Bonus: Federal offices are open on B.C.'s family day, making it an ideal time to get your passport renewal taken care of. No lines, no waiting, same cheerful Service Canada folks!

No thank you Premier Christie Clark for granting your approval to the millions of dollars of pro-government pre-writ election-advertising-in-disguise. I don't watch a ton of television but every time I do I'm bombarded with your ads, paid for by our tax dollars.

Such obvious partisan spending should be made illegal.

Them watching me watching them


The above shot was made within a few hundred meters of a terrific view of The Lions - colour me blind but I prefer the image of the birds and fence and prefer it in black and white.


Just a pair of pigeons. Fowl vs Lions:


View of The Lions down the lake at Cleveland Dam, North Vancouver

What do our preferences for images say about us?

January 27 2013

Fire on Terminal Avenue


Vacant North-west Produce building on Terminal Avenue in Vancouver