Over a million developers have joined DZone.

Python Community Update - Libraries Galore!

DZone's Guide to

Python Community Update - Libraries Galore!

· Web Dev Zone ·
Free Resource

A true open source, API-first CMS — giving you the power to think outside the webpage. Try it for free.

Today I've got a couple of useful libraries for Python:


Armin Ronacher has put together Python-Modernize, a library that is essentially a thin wrapper around lib2to3 to modernize Python 2 code with the goal of porting it to Python 3.  Here's a look at the Unicode Literal Control:

  • By default modernize will wrap literals with the six helpers.  This is useful if you want to support Python 3.1 and Python 3.2 without bigger changes.
  • Alternatively there is the ``--compat-unicode`` flag which does not change unicode literals at all which means that you can take advantage of PEP 414.
  • The last alternative is the ``--future-unicode`` flag which imports the ``unicode_literals`` from the ``__future__`` module.  This requires Python 2.6 and later and will require that you mark bytestrings with ``b''`` and native strings in ``str(b'')`` or something similar that survives the transformation.

Here is the setup code for Python-modernize:
import os
from setuptools import setup

readme = open(os.path.join(os.path.dirname(__file__), 'README'), 'r').read()

    author='Armin Ronacher',
    packages=['libmodernize', 'libmodernize.fixes'],
    description='A hack on top of 2to3 for modernizing code for '
                'hybrid codebases.',
        'console_scripts': [
            'python-modernize = libmodernize.main:main'
        'License :: OSI Approved :: BSD License',
        'Programming Language :: PHP',
        'Programming Language :: Python',
        'Programming Language :: Python :: 3'


Another useful library is Massimo Di Pierro's glunio, which began during the PyCon 2012 sprint.  Gluino is a port of web2py libraries to number a of frameworks, including:

  • Bottle
  • Flask
  • Pyramid
  • Tornado
  • Wsgiref

The port is offered under the Web2py license, though it is still lacking some key features when compared to web2py, including:

  • mulit-app suport
  • web based IDE
  • CRON and Scheduler

The github page offers a litany of documentation, with samples for each framework containing the same common code and executing the same template, generating the same output on each of the frameworks:

Flask Example Code

from flask import Flask, request, session, redirect
from gluino import *
import time

# configure the gluino wrapper                                                  wrapper.debug = True
wrapper.redirect = lambda status, url: redirect(url)

# initialize flask
app = Flask(__name__)

# create database and table

# define action
def index():
    vars = wrapper.extract_vars(request.form)
    form = SQLFORM(db.person)
    if form.accepts(vars):
        message = 'hello %s' % form.vars.name
        message = 'hello anonymous'
    people = db(db.person).select()
    now  = cache.ram('time',lambda:time.ctime(),10)
    return locals()

# start web server
if __name__=='__main__':
    print 'serving from port 8080...'

And here is the output generated by each framework:

In case you missed it, Massimo Di Pierro gave this presentation at PyCon 2012:

The New Standard for a Hybrid CMS: GraphQL Support, Scripting as a Service, SPA Support. Watch on-demand now.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}