Posts Tagged ‘Python’

Kyle Waremburg

Tuesday, September 2nd, 2008

When I worked at Tremont Community Schools, Kyle was still a student, but he helped build Firewall Admin, a Linux desktop that spanned 9 monitors, and many robots. He’s now blogging, and I can almost guarantee he’ll always be doing something wilder and more interesting than me!

Introducing Hzzah!

Tuesday, July 15th, 2008

from the I-can-haz-a-search-engine department…

Update: Sorry about the tacky donate link all. I tried to hide it from feed readers with WordPress’s <!–more> feature, but evidently that doesn’t apply to feeds. :(

When it comes to market share, Google is to Searching as Microsoft is to Operating Systems. Thankfully Google has won their dominant position by creating a really amazing product (you can find plenty of discussions on why Microsoft is on top elsewhere).

Recently Yahoo! opened up their search APIs for anyone to use along with a handy Python library. In a time when Yahoo’s very existence is being threatened, I felt a pang of nostalgia for the search engine that fed me decent results for “free dos games” throughout the mid-90s.

So last night I whipped up a little search engine called Hzzah!*

 
BSDtastic!

Features:

  • Simple
  • No ads, cookies, or even JavaScript (at the moment at least)
  • Open Source! BSD to be precise.
  • Did I mention simple? That’s really all it has going for it…

(more…)

WordPress Rocks at Updates

Tuesday, July 15th, 2008

I feel I owe it to my friends who put up with my senseless Python fanboying to admit WordPress is not only a great blog engine, but rocks at updates.

I just upgraded from 2.5 to 2.6 by doing a simple svn switch http://... and then logging into the web admin interface. It took about 30 seconds to complete.

Now compare that to my last experience upgrading Trac from 0.10 to 0.11… ugh.

I love you Trac. Python just lacks an easy and efficient web app deployment method.

Common Django Typo in URLconf

Monday, March 10th, 2008

If you’re hacking Django and get this…

ImproperlyConfigured: Error while importing URLconf 'proj.app.urls': 'tuple' object is not callable

…you’re probably missing a comma in your URL configuration as Rajesh Dhawan pointed out.

Django pros can move along, I know you never make typos. ;)

Fun with Django and modwsgi

Tuesday, February 5th, 2008

Today I deployed my first Django application for a client. Its yet-another-blog, so I’ll refrain from posting the code and cluttering up the django-*blog* namespace on Google Code. Before you roll your eyes and complain about why I didn’t use an existing solution, I think I have 2 somewhat valid reasons:

  1. The client actually needed a subset of the features most blogs offer, so I wouldn’t really have anything to contribute back to an existing project.
  2. Blogs are one of the simplest content driven web applications in existence. Wikis are just a bit simpler perhaps. At any rate, creating a blog app is an excellent way to learn a framework.

Python Deployment Decisions

In the past I’ve used CherryPy as my framework and a simple mod_proxy configuration to run the applications behind Apache. Django considers its built-in web server a development tool only, so I figured it was time to explore the myriad of Python web app deployment alternatives: mod_python, FastCGI, modwsgi. I’m sure there are many more, but I’d say those are the big 3.

I had tried to deploy Python web applications on DreamHost using FastCGI before and entered the hell that is deploying Python web apps on shared hosts. So FastCGI wasn’t my first choice this time.

I had also tried mod_python for deploying CherryPy apps on my Linode before and for whatever reason just found mod_proxy to be much easier to setup and manage.

I was kind of eager to try out modwsgi because its been getting a lot of attention lately, so I downloaded the source and compiled it on my Debian Etch server.

Deploying a Django App via modwsgi

modwsgi was quite easy to setup as long as you follow the instructions in their wiki for Django integration. I was hit by bug #3762, but the modwsgi documentation got me through it. (For what its worth the attached wsgi.patch also worked, but I don’t really want to run a patched version of Django.)

One big problem I ran into was sqlite3 gave me OperationalError: unable to open database file whenever I did anything that would write to the database. My database file was owned by www-data (the Apache process owner) and had the permissions 664.

I switched to PostgreSQL, ran syncdb, and everything worked beautifully.

My wsgi script file /srv/spam/eggs/eggs.wsgi:

import os, sys
sys.path.append('/srv/spam')
sys.path.append('/srv/spam/eggs')
os.environ['DJANGO_SETTINGS_MODULE'] = 'eggs.wsgi_settings'
 
import django.core.handlers.wsgi
 
_application = django.core.handlers.wsgi.WSGIHandler()
 
def application(environ, start_response):
    environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
    return _application(environ, start_response)

Note I use wsgi_settings instead of my usual settings file. wsgi_settings just imports my main settings file and changes some to their production values.

My Django application actually drops into the /blog/ and /accounts/ folders under a VirtualHost otherwise occupied by static files and some PHP scripts. modwsgi made this easy by putting this in my existing VirtualHost:

WSGIScriptAliasMatch /(blog|accounts)/.* /srv/spam/eggs/eggs.wsgi
 
# A simple Alias directive handles my static files
Alias /static/ /srv/spam/eggs/static/

Bottom Line

I highly recommend using modwsgi for deploying Python web applications. sqlite3 may work for you. In my case its probably best I use PostgreSQL for a number of reasons.

Fun with SQLObject and mxDateTime

Thursday, November 29th, 2007

I’m working on a small CherryPy web service that among other things saves timestamps to a database. The timestamp is in RFC 3339 format (like 2007-07-31T16:05:00.000-05:00), and I needed to store the timezone.

Luckily mxDateTime and SQLObject’s DateTimeCol both support full dates with times and time zone. Unfortunately its not immediately obvious from SQLObject’s lackluster documentation how to use mxDateTime instead of Python’s built-in datetime.

A little searching brought me to a mailing list post about how to use mxDateTime by default in SQLObject. (I don’t know why the sample code includes the conditional as I would think you’d want your code to outright fail if you’re unable to use the datetime library you expect.)

So my model’s code looks something like this:

from sqlobject import *
from sqlobject import col
 
col.default_datetime_implementation = MXDATETIME_IMPLEMENTATION
 
class Foo(SQLObject):
    timestamp = DateTimeCol(default=DateTimeCol.now)

Then my parsing code looks something like this:

import model
from mx import DateTime
 
timestamp = '2007-07-31T16:05:00.000-05:00'
bar = model.Foo(timestamp=DateTime.DateTimeFrom(timestamp))
print 'UTC Timestamp:', bar.timestamp
print 'Local Timestamp:', bar.timestamp.localtime()

Basically once you use the magic line col.default_datetime_implementation = MXDATETIME_IMPLEMENTATION, everything Just Works.