Tag Archives: Python

Creating extendable Web Application with Pyramid, PCA and Jinja2

Pyramid is a great framework for developing web applications that also supports the development of “Extensible” and “Pluggable” ones based on certain rules. However, there is no much documentation on how to create such type of applications.

CKAN is an excellent example of a web application that can be extended or modified using plugins. It relies on PyUtilib Component Architecture (PCA) to declare a series of interfaces and extension points that then are used by plugins to hook in. It also implements a series of Jinja2 extension (notably CKAN_EXTENDS) that allows easily template inheritance between CKAN and connected plugins.

CKAN however is developed using Pylons which is now superseded by Pyramid and coupled to its complexity makes it difficult to grasp how to apply such extensibility to Pyramid web applications.

I took the time to look into the CKAN code, the PCA documentation and Jinja2 and I came with an example that applies a modified version of CKAN extensible system to a simple Pyramid application. It can be used as a starter to develop more complex extendable web applications. The example (pcaexample) is based on a “pyramid-cookiecutter-alchemy” Cookiecutter. The code also includes an example of a plugin that is based on a “pyramid-cookiecutter-starter”. It uses Pyramid 1.8.3 with PyUtilib 5.4.1.

You can get the code here.



Exporting Formhub data to JSON files

Few weeks ago we installed FormHub in one of our servers at ILRI. Formhub is an online system for aggregating ODK data coming from mobile devices. The data is stored in a Mongo Database. Although Formhub provides exporting features to CSV and Excel it does not provide exporting to more interoperable formats like JSON.

I created a small Python program that connects to a Formhub database and extracts survey data into a directory using the Survey ID as filter. Each data submission is exported as a JSON file using the UUID as file name.

You can get it from here