views:

827

answers:

4

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?

+1  A: 

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?

joeforker
+1  A: 

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.

nn4l
No update has been made to WSGI to define how it should operate under Python 3.X. Any Python framework claiming compliance with WSGI on Python 3.X in all probability will need to be changed when any update to WSGI comes out. Whether that means user code will need to change, will depend on how well the framework isolates user code from the underlying WSGI interface. As such, one needs to be cautious at this point in doing anything related to WSGI on Python 3.X.
Graham Dumpleton
A: 

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

poops mcgee
A: 

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

Alan Harris-Reid