Question

I have started learning Python by writing a small application using Python 3.1 and py-postgresql. Now I want to turn it into a web application.

But it seems that most frameworks such as web-py, django, zope are still based on Python 2.x. Unfortunately py-postgresql is incompatible with Python 2.x.

Do I have to rewrite all my classes and replace py-postgresql with something supported by web-py etc., or is there a framework compatible with Python 3.1?

Or maybe py-postgresql is compatible with 2.x but I did not figure it out?

Was it helpful?

Solution

Update: this answer is out of date in 2011.

Unless you are interested in blazing a new trail while trying to learn Python at all, I'd recommend converting your project to Python 2.x. Hopefully your code doesn't use too many py-postgresql features not found in the widely supported DB-API interface.

You should look at psycopg2 for a Python 2.x DB-API compatible interface or if you want to go higher-level SQLAlchemy which in the svn release can use psycopg2 or py-postgresql interchangeably.

You might also be interested in 3to2 which automatically converts Python 3.x code to Python 2.x code when possible.

Duplicate of #373945 What web development frameworks support Python 3?

OTHER TIPS

I have just found out about WSGI: a WSGI compatible app can also be written in Python 3.1. The following code runs just fine in Python 3.1:

def webapp(environment, start_response):
    start_response('200 OK', [('content-type', 'text/html')])
    return ['Hello, World!']

if __name__ == '__main__':
    from wsgiref import simple_server
    simple_server.make_server('', 8080, webapp).serve_forever()

The WSGI website has lots of pointers to frameworks. The Bottle framework claims "Bottle runs with Python 2.5+ and 3.x (using 2to3)" so I will give that a try.

Here's a simplified version of tornado's WSGI server implemented in python 3.

http://code.activestate.com/recipes/576906/

probably has some bugs, but can get you started

Even though it's not officially released yet, I am currently 'playing around' with CherryPy 3.2.0rc1 with Python 3.1.1 and have had no problems yet. Haven't used it with py-postgresql, but I don't see why it shouldn't work.

Hope this helps, Alan

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top