Wednesday, December 17, 2014

Tortilla, a Python API wrapper

By Vasudev Ram

tortilla is a Python library for wrapping APIs. It's headline says "Wrapping web APIs made easy."

It can be installed with:
pip install tortilla
I tried it out, and slightly modified an example given in its documentation, to give this:
import tortilla
github = tortilla.wrap('')
user = github.users.get('redodo')
for key in user:
    print key, ":", user[key]
That code uses the Github API (wrapped by tortilla) to get the information for user redodo, who is the creator of tortilla.
Here is the output of running:
bio : None
site_admin : False
updated_at : 2014-12-17T16:39:55Z
gravatar_id : 
hireable : True
id : 2227416
followers_url :
following_url :{/other_user}
blog : 
followers : 6
location : Kingdom of the Netherlands
type : User
email :
public_repos : 9
events_url :{/privacy}
company : 
gists_url :{/gist_id}
html_url :
subscriptions_url :
received_events_url :
starred_url :{/owner}{/repo}
public_gists : 0
name : Hidde Bultsma
organizations_url :
url :
created_at : 2012-08-27T13:03:15Z
avatar_url :
repos_url :
following : 2
login : redodo
print type(user)
to the end of, shows that the user object is of type bunch.Bunch.

Bunch is a Python module providing "a dictionary that supports attribute-style access, a la JavaScript."

Did you know that tortillas are roughly similar to rotis?

- Vasudev Ram - Dancing Bison Enterprises

Signup for news about new products from me.

Contact Page

Monday, December 15, 2014

Indian couple (1 Xoogler) buys small US bank, innovates online payments

By Vasudev Ram

Interesting story of innovation in the financial space, involving an Indian couple (of whom one is a Xoogler a.k.a ex-Googler), a small US bank, and cheaper / faster online money transfers / payments:

(Did you know that the English word bank supposedly comes from the old Italian word banca (for bench)?

An Indian couple has bought a small bank in Weir, Kansas, USA, and is using it to innovate in the online financial payments / money transfers space (while preserving and improving the existing brick-and-mortar business of the bank). The site through they allow faster / cheaper payments or money transfers from the US to India (and currently, or soon, other countries), is Their rate for sending a payment under $1000 USD is $2.50, which works out to 0.25 percent. For above $1000, it is free (disclaimer: all this is according to what I saw on the site recently).

Suresh Ramamurthi earlier worked at Google on the Checkout product, and Suchitra Padmanabhan earlier worked at Lehman Brothers and Bankers Trust.

I saw this news via this tweet by Quentin Hardy (@qhardy), Deputy Tech Editor, The New York Times. (Saw it from a retweet by Bernard Lunn.)

The tweet goes thusly:

"Guy from India learns payments at Google, buys tiny Kansas bank, transforms money. Great, from @nathanielpopper…"

And here is the New York Times article referred to in the tweet:

Small Bank in Kansas Is a Financial Testing Ground

- Vasudev Ram - Dancing Bison Enterprises

Signup for email about new products from Vasudev Ram.

Contact Page

Friday, December 12, 2014

Streem, new programming language by Ruby creator, Matz

By Vasudev Ram

Saw this thread on Hacker News today:

Streem – a new programming language from Matz (

Here's the Github project for the Streem language.

It says there that it is still in the design stage, and not working yet. But given that it is by Matz, creator of the Ruby language, it should be worth keeping an eye on. There is one example at the Streem site that is UNIX-like, and another that shows some influence of Ruby syntax.

- Vasudev Ram - Dancing Bison Enterprises

Click here for email about new products and services from me.

Contact Page

Project Enferno: RAD framework with Python / Flask / MongoDB / Redis

By Vasudev Ram

Just saw this via Python Weekly's email newsletter. Enferno seems to be a RAD (Rapid Application Development) framework of sorts, using Python, Flask, some Flask extensions, MongoDB AND MongoEngine, and Redis.

Enferno framework

I've worked on a project or two using Python, Flask and MongoDB (which is a NoSQL database), and found it a useful combination for developing apps relatively quickly. Enferno may be worth checking out, which I will do sometime later and may then blog about it.

Here is an article about NoSQL by Martin Fowler that may be of interest to newcomers to the field. Fowler and Pramod Sadalage have also written a book, NoSQL Distilled, which is linked to from Fowler's NoSQL article page. I've read Fowler's earlier book UML Distilled, a small and useful summary of UML, and it looks from the title that their NoSQL book may be on the same lines.

- Vasudev Ram - Dancing Bison Enterprises

Signup for email about interesting new stuff from me.

Contact Page

Other Python posts | Posts about xtopdf

Wednesday, December 10, 2014

Convert JSON to PDF with xtopdf

By Vasudev Ram

I added support for JSON as an input format to xtopdf, my Python toolkit for PDF creation.

Here is an example program,, that shows how to use xtopdf to convert JSON data to PDF:


# This program shows how to convert JSON input to PDF output.
# Author: Vasudev Ram -
# Copyright 2014 Vasudev Ram -
# This program is part of the xtopdf toolkit:

import sys
import json
from PDFWriter import PDFWriter

def error_exit(message):

def JSONtoPDF(json_data):
    # Get the data values from the JSON string json_data.
        data = json.loads(json_data)
        pdf_filename = data['pdf_filename']
        font_name = data['font_name']
        font_size = data['font_size']
        header = data['header']
        footer = data['footer']
        lines = data['lines']
    except Exception as e:
        error_exit("Invalid JSON data: {}".format(e.message))
    # Generate the PDF using the data values.
        with PDFWriter(pdf_filename) as pw:
            pw.setFont(font_name, font_size)
            for line in lines:
    except IOError as ioe:
        error_exit("IOError while generating PDF file: {}".format(ioe.message))
    except Exception as e:
        error_exit("Error while generating PDF file: {}".format(e.message))

def testJSONtoPDF():
    fil = open('the-man-in-the-arena.txt')
    lis = fil.readlines()
    data = { \
        'pdf_filename': 'the-man-in-the-arena.pdf', \
        'font_name': 'Courier', \
        'font_size': 12, \
        'header': 'The Man in the Arena', \
        'footer': 'Generated by xtopdf -', \
        'lines': lis \
    json_data = json.dumps(data)
def main():

if __name__ == '__main__':
In the example program, I used as input, the text of "The Man in the Arena", which is a well-known excerpt of a speech by Theodore Roosevelt, the 26th President of the United States.

Here is a screenshot of the PDF file created by

Here is the Wikipedia page about JSON, JavaScript Object Notation.

Here is the Wikipedia page about PDF, the Portable Document Format.
PDF became an ISO standard (ISO 32000) some years ago.

- Vasudev Ram - Dancing Bison Enterprises - Python training and consulting

Signup for email about new Python-related products from me.

Contact Page