DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Languages
  4. Python Community Update - Libraries Galore!

Python Community Update - Libraries Galore!

Chris Smith user avatar by
Chris Smith
·
Mar. 14, 12 · Interview
Like (1)
Save
Tweet
Share
3.75K Views

Join the DZone community and get the full member experience.

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

Python-Modernize

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()

setup(
    name='modernize',
    author='Armin Ronacher',
    author_email='armin.ronacher@active-4.com',
    version='0.1',
    url='http://github.com/mitsuhiko/python-modernize',
    packages=['libmodernize', 'libmodernize.fixes'],
    description='A hack on top of 2to3 for modernizing code for '
                'hybrid codebases.',
    long_description=readme,
    entry_points={
        'console_scripts': [
            'python-modernize = libmodernize.main:main'
        ]
    },
    zip_safe=False,
    test_suite='tests',
    classifiers=[
        'License :: OSI Approved :: BSD License',
        'Programming Language :: PHP',
        'Programming Language :: Python',
        'Programming Language :: Python :: 3'
    ]
)

gluino

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__)
app.config.from_object(__name__)

# create database and table
db=DAL('sqlite://storage.sqlite')
db.define_table('person',Field('name',requires=IS_NOT_EMPTY()))

# define action
@app.route('/index',methods=['GET','POST'])
@wrapper(view='templates/index.html',dbs=[db])
def index():
    vars = wrapper.extract_vars(request.form)
    form = SQLFORM(db.person)
    if form.accepts(vars):
        message = 'hello %s' % form.vars.name
    else:
        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...'
    app.run(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:




Python (language) Library

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Build a Spring Boot GraalVM Image
  • Real-Time Analytics for IoT
  • Introduction To OpenSSH
  • Rust vs Go: Which Is Better?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: