skip to navigation
skip to content

Planet Python

Last update: February 14, 2012 08:46 PM

February 14, 2012


Mike Driscoll

wxPython: All about Menus

Menus are ubiquitous. They’re in almost all desktop programs. You use them for editing preferences or configuring your program. In wxPython, there are several menu options to choose from. The most familiar is probably wx.Menu. But there are are popup menus and a pure Python implementation known as FlatMenu. We will just be covering wx.Menu [...]

February 14, 2012 08:16 PM


Python Diary

Too many micro webframeworks

There is a large amount of Python micro web frameworks out in the wild, and some of them feel similar to eachother, at least when I first approach them. I plan on going through a few of these micro web frameworks to see what the exact differences are. I will not be comparing them to full frameworks such as Django or Web2py.

Bottle

First up, Bottle. It is very micro in that it comes in a single Py file and is very portable across platforms. If you need a simple Python web app running on say an embedded system with very low resources and disk space, this will be a good option for you. Here is a snippet of code from their home page of an example application:

from bottle import route, run

@route('/hello/:name')
def index(name='World'):
    return '<b>Hello %s!</b>' % name

run(host='localhost', port=8080)

Simple, is it not. One could deploy a Python console application which merely displays output for diagnose of a server or heartbeat in a matter of minutes. I wouldn't recommend it for full web applications, but no one is stopping you.

web.py

Next we have web.py. I have heard many good things about this micro framework, that doesn't make it sounds so micro. A good advantage of this web framework is the ability to separate the requests from both GET and POST. This is great when you need to develop an application which depends on the type of request coming through, such as a REST API. Here is a snippet from their home page:

import web
        
urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:        
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()

A little more complex than Bottle, but it's still simpler than say Django or Web2py.

Flask

Looking for something even simpler than Bottle? Try Flask, there are less imports to remember, but it is ever so similar to Bottle. But, it comes with more than bottle, so you will have more than a single file to work with. It comes with the Jinja2 template engine, RESTful dispatching, and other goodies that other micro frameworks lack. Here's a snippet from their homepage:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

Notice how similar this code is to Bottle's example code? If your looking for a little extra in a micro web framework, without all the extras of Django or Web2py, flask may be a good option for you.

CherryPy

Finally we get to CherryPy. I have heard many great things about this framework and many Python developers seem to favor it. I have not personally tried it myself, but I do plan on trying it out to see how it differs from other frameworks out there, micro and otherwise. They say the framework is a minimalistic one, but I still believe that Bottle is the smallest one around. It supports similar components to Django, such as caching, sessions, static files, and even authorization. It also appears to run on many platforms including Android. Here is the example code snippet from their home page:

import cherrypy
class HelloWorld(object):
    def index(self):
        return "Hello World!"
    index.exposed = True

cherrypy.quickstart(HelloWorld())

It does look fairly simple, but the last statement quickstart sort of scares me. This would imply that there are other methods of starting the application, in effect for larger applications, this simple code snippet above may not be the real deal. I will look into this one further and see how complex web applications are built and how it would differ from other micro frameworks listed here.

Final thoughts

Now that this entry is coming to a close, I would like to express my final thoughts on so-called micro frameworks. Are all of these micro frameworks truly needed? Does having this many cause fragmentation in how Python web development should be done? Does it cause developer confusion, on which one a developer should learn or avoid? Let me know what you think about this micro-framework situation us Python developers are faced with in the comments below.

February 14, 2012 06:41 PM


PyCon

PyCon 2012: New Relic, Loggly and Skullcandy party!

February 14, 2012 02:47 PM


Kristján Valur

Clearing weakrefs

I just had this problem which would have been elegantly solved with the ability to manually clear weak references pointing to an object. I am (for technical reasons) recycling an object, so instead of killing it and re-creating it, I … Continue reading

February 14, 2012 02:17 PM


Rob Galanakis

Large initializers/ctors?

With closures (and to some extent with runtime attribute assignments), I find the signatures of my UI types shrink and shrink. A lot of times we have code like this (python, but the same would apply to C#): class FooControl(Control): def __init__(self, value): super(FooControl).__init__() self.value = value self._InitButtons() def _InitButtons(self): self.button = Button('Press Me!', parent=self)

February 14, 2012 12:03 PM


PyCon

Need dinner plans? Yelp can help!

February 14, 2012 10:20 AM


Shannon -jj Behrens

Python Concurrency Spreadsheet

February 14, 2012 10:05 AM


PyCon

PyCon 2012: Want some business cards for PyCon 2012?

February 14, 2012 09:52 AM


Maciej Fijalkowsk

PyPy and it's future challenges

February 14, 2012 09:43 AM


Python Diary

First steps into Kivy

I just finished the Kivy tutorial on how to build a simple Pong Game. I must say, Kivy is a very interesting framework, and I plan on building some Android apps using it soon.

The framework makes heavy use of classes to describe each component of your application, and also has a simple language for rapidly building interfaces and binding them in Python. It has native support for multi-touch screens, which makes it an ideal platform to learn.

Tablets and smartphones are rather huge right now, and I don't see them going away anytime soon. Most users of a tablet or smartphone prefer an app over a website, I know I do. Kivy makes it relatively easy to create an app which is network connected, as it has native support for JSON calls, it manages the web request and decoding of the JSON object for you.

A small project I plan to implement using Kivy is a simple map viewer for the OHRRPGCE engine. I have previously created a full map editor in another language and understand the underlying file formats. I am curious how creating such an application in Kivy will fair. From what I have read in the documentations for Kivy, I will need to use a texture to map each map tileset onto. From these map tilesets, I would then blit the required tiles to a new texture for the actual map layers. I will use touch controls for panning the map around, similar to how Google maps works on a tablet. I hope to add features such as pinch to zoom and such, since Kivy does support scaling in OpenGL. I will explain the process throughout this blog for those who are interested in Kivy app development.

Another interesting project would be to create a Kivy app for this here blog, that way Android users can easily access this blog directly on their device using a nice user interface.

February 14, 2012 09:40 AM


Yaniv Aknin

nginx+gzip module might silently corrupt data upon backend failure

There are several elements that make absolutely certain the page you’re reading in your browser right now is actually an accurate representation of the resource the HTTP server holds in the URL you requested1. Disregarding caching for a minute, we have two elements making sure the representation you get is protected from errors. The first [...]

February 14, 2012 09:07 AM


Catherine Devlin

Growth in PyCon sponsorship

February 14, 2012 08:59 AM


S. Lott

Multiprocessing Goodness -- Part 2 -- Class Defintions

February 14, 2012 08:32 AM

TDRE - Test Driven Reverse Engineering Case Study

February 14, 2012 08:00 AM


Wallix

Announcing PyLogsParser 0.4

Wallix LogBox team is happy to announce version 0.4 of PyLogsParser. New normalizers Wallix AdminBastion authentication logs, written by Nassim Babaci Cisco ASA logs. Dansguardian logs. Features Adds Common Callbacks facility : a library of functions that are ready to … Continue reading

February 14, 2012 07:41 AM


Yuval Greenfield

Python isn’t English and iterator “labels”

Us python fanboys like to think of python as similar to English and thus more readable. Let’s examine a simple piece of code: for item in big_list:     if item.cost > 5:         continue     … Continue reading

February 14, 2012 07:41 AM


EmptysquarePython

Third Normal Form and Ultimate Truth

I have an opinion: most people learned about relational databases as if RDBMSes were designed to store the ultimate truth about some data. They figured that once the schema had been properly diagrammed and normalized, then they could load all their data into it, and finally, start doing some queries. To pick on an easy [...]

February 14, 2012 06:31 AM


ShiningPanda

Selenium, Python and Jenkins on Debian - 3/3

February 14, 2012 03:00 AM


Montreal Python User Group

Cloud Robotics Hackathon

Hello Montreal hackers The cloud robotics week-end is happening the 2nd, 3rd and 4th of March. Come hack on robots and web services to create cool projects in robotics. See   http://roboticshackathon.com/ for more information. We are waiting for you if you would like to create a team Montreal-Python and if you would like to join us [...]

February 14, 2012 02:38 AM


Stephen Ferg

Backing up your email

Just in case someone might find this useful … I recently had something bad happen to me. I use Thunderbird (on Windows Vista) as my email client. I asked Thunderbird to compact my email files, and it wiped out a bunch of my email messages. (I think that one of my email files must have [...]

February 14, 2012 02:17 AM

February 13, 2012


EmptysquarePython

Philly MongoDB User Group: Python, MongoDB, and Asynchronous Web Frameworks

Photo (C) Parent5446 I’ll be recapping last week’s talk on Python, MongoDB, and Asynchronous Web Frameworks this Thursday at 7pm, in Philadelphia, at the Philly MongoDB User Group’s inaugural meetup. We’ll be at the Devnuts office, at 908 North 3rd Street. We’ll have pizza, naturally. First Philly MongoDB User Group

February 13, 2012 08:26 PM


Cormoran Project

Continuous integration with Travis

February 13, 2012 06:42 PM


Jesse Noller

A letter to my love, my friend, my wife.

A letter to my love, my friend, my wife and my partner — Dusty: I know it’s the day before Valentines — some things can’t wait just for a day. Ten years — that’s how long we’ve been with one another. Ten years feels like a lifetime — so much has changed — our lives [...]

February 13, 2012 05:32 PM


PyPy Development

A Larger Example for the Flow Graph Language

February 13, 2012 03:50 PM


Matt Harrison

Amazon KDP Non-Fiction Week 2 Update

February 13, 2012 01:03 PM