The big day is nearly over, I’ve said my last ‘so-longs’ to my many friends and colleagues and the obsessive techie in me is clamoring to be fed
. Over the past couple of weeks I’ve been setting up my delightful Mac iBook with Apache configured to communicate with the Python WebKit app server (part of the Python Webware suite). I’ve loaded up PostgreSQL with the very fine, free, pgAdmin tool as the front end to make visual browsing of db elements possible. I’ve run some basic tests with the SQLObject ORM solution and set up a simple Python servlet to ensure that I could make an insert happen from the web – (I’ll enhance this test app some more over the weekend). All the code I scripted was done either in the Eclipse PyDev plugin or in the Python Idle IDE.
There are some important points to make about the set up I’ve described:
- It is entirely, free, open source software.
- All this open source stuff runs on my Mac.
- The simplicity factor in the configuration effort was noteworthy (more on this in a bit).
- I felt no regret that I wasn’t doing all this in Java.
- The clarity and conciseness of the code was reassuringly Pythonic.
I’ve liked the Python language since my first encounter with it some years ago. It is clean and the feature set of the core language is robust and the add on libraries that are available are enormous. Internet behemoths such as IBM and Google use Python heavily and if you go to Python.org you’ll see other well-known organizations also understand that working in Python can boost developer productivity and reduce maintenance overhead over time.
The ‘simplicity factor’ is that Python now sports an easy install mechanism called – big surprise – ‘easy install‘. With easy_install – one simple command will download add on library modules and make them available in my default Python installation in much the same way that Perlish folk rely on CPAN. This tool is a real labor saver and if you’re at all interested in coding in Python I urge you to go to the Peak website and download it. The sense of minimalism and simplicity was enhanced by how relatively easy it was to link up the WebKit Python app server to Apache. Moreover, if I hadn’t wanted to have Apache handle the requests and forward the PyServlet stuff on I could have used the built-in HTTP service in WebKit. In this sense it is a bit like Rails that has WebBrick built-in for HTTP request handling.
Lastly, the number of lines of Python code required to accomplish this test scenario was very small indeed – excluding 5 lines of imports, the total was under 15 lines of code to set up an ORM call to insert a row into a database. I’m aware that a simple JDBC test harness would also be fairly small so here’s the code for comparison purposes. (Python formatting lost for now)
from WebKit.Page import Page
from sqlobject import *
from sys import *
from Person import Person
import os
connection_string = 'postgres://postgres@localhost/testdb?debug=true'
connection = connectionForURI(connection_string)
sqlhub.processConnection = connection
class Person(SQLObject):
firstName = StringCol()
middleInitial = StringCol(length=1, default=None)
lastName = StringCol()
class DoPerson(Page):
def title(self):
return 'DoPerson PyServlet'
def writeContent(self):
self.writeln('''<h1>Welcome to Doug's Person Page!</h1>''')
db_filename = os.path.abspath('/usr/local/pgsql/data.db')
if os.path.exists(db_filename):
os.unlink(db_filename)
self.writeln('''<h1>Imported Person</h1>''')
#Person.createTable(ifNotExists=True)
p = Person(firstName="Douglas", middleInitial="E", lastName="Tillman")
self.writeln('''<p>insert is done</p>''')
If you’re familiar with Java, I’d be surprised if the terseness and clarity of this snippet didn’t impress you (comment why please if it didn’t). Sure, languages are tools, not articles of faith to ride off on a holy war about (fashionable as holy wars sadly are these days) and one language doesn’t serve all needs. I had some concern that the Python ‘webby’ stuff was going to be convoluted, in other words, not like the Python scripting I knew and loved. I’m relieved to see that the ‘batteries are still included‘ when it comes to this web framework.
There’s some interesting activity in the Python web framework space spurred on by Ruby Rails successes. I plan to comment at a later date on the Webware framework and its various components as well as some of the other Python based frameworks. If you’re too impatient to wait you can check out TurboGears or the newer Django framework. The latter is actively being worked on by some Chicago people who I believe are with Thoughtworks (Martin Fowler’s gang – at least it was).
Viva el serpiente!
2 Comments
“Alan Fowler’s gang”
Do you mean Martin Fowler?
Couple of corrections: The Django open-source project is older than Turbogears, and none of us core Django developers are affiliated with ThoughtWorks.
Post a Comment