views:

685

answers:

7

I am looking for a LAMPish/WAMPish experience.

Something very transparent. Write the script, hit F5 and see the results. Very little, if any abstraction. SQLAlchemy and (maybe) some simple templating engine will be used.

I need simple access to the environment - similar to the PHP way. Something like the COOKIE, SESSION, POST, GET objects.

I don't want to write a middleware layer just to get some web serving up and running. And I do not want to deal with specifics of CGI.

This is not meant for a very complex project and it is for beginning programmers and/or beginning Python programmers.

An MVC framework is not out of the question. ASP.NET MVC is nicely done IMO. One thing I liked is that POSTed data is automatically cast to data model objects if so desired.

Can you help me out here?

Thanks!

PS: I did not really find anything matching these criteria in older posts.

+1  A: 

Look at:

  • WSGI, the standard Python API for HTTP servers to call Python code.
  • Django, a popular, feature-rich, well documented Python web framework
  • web.py, a minimal Python web framework
Nat
I would vote up web.py if it was in a separate comment. I don't want to vote up Django, which is not simple to deploy at all, or low barrier to entry.
Gregg Lind
+1  A: 

Have you looked into the Django web framework? Its an MVC framework written in python, and is relatively simple to set up and get started. You can run it with nothing but python, as it can use SQLite and its own development server, or you can set it up to use MySQL and Apache if you'd like.

Pylons is another framework that supports SQLAlchemy for models. I've never used it but it seems promising.

Marquis Wang
We've invested some amount of work into SQLAlchemy so I'd like to use that. The problem with Django is that it does support that only experimentally afaik.
Edit: You can try Pylons if you would really like SQLAlchemy.
Marquis Wang
The investment in SQL Alchemy should apply to the Django ORM without too much trouble. There's rewriting, but it's syntactic and minor. Also, you'll be able to drop some stuff when moving from SA to Django.
S.Lott
Not so fast, S.Lott! What about compound primary keys and blobs in django?
pihentagy
"syntactic and minor" -- I guess it depends on what you're doing with SA. What I tend to do with SA doesn't usually fall into that category.
Gregg Lind
+6  A: 

CherryPy might be what you need. It transparently maps URLs onto Python functions, and handles all the cookie and session stuff (and of course the POST / GET parameters for you).

It's not a full-stack solution like Django or Rails. On the other hand, that means that it doesn't lump you with a template engine or ORM you don't like; you're free to use whatever you like.

It includes a WSGI compliant web server, so you don't even need Apache.

Pixy Misa
This combination works for me. In combination with SQLAlchemy, you have to be a little bit careful to get the multithreading right. You can lift this code http://code.google.com/p/webpyte/source/browse/trunk/webpyte/sqlalchemy%5Ftool.py to achieve this (or directly use webpyte)
stephan
+1 because it's not just a minimal-effort web app framework, it's also a great introduction to writing RESTful services.
Meredith L. Patterson
+5  A: 

What you're describing most resembles Pylons, it seems to me. However, the number of web frameworks in/for Python is huge -- see this page for an attempt to list and VERY briefly characterize each and every one of them!-)

Alex Martelli
+4  A: 

For low barrier to entry, web.py is very very light and simple.

Features:

  • easy (dev) deploy... copy web.py folder into your app directory, then start the server
  • regex-based url mapping
  • very simple class mappings
  • built-in server (most frameworks have this of course)
  • very thin (as measured by lines of code, at least) layer over python application code.

Here is its hello world:

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()

As much as I like Werkzeug conceptually, writing wsgi plumbing in the Hello, World! is deeply unpleasant, and totally gets in the way of actually demoing an app.

That said, web.py isn't perfect, and for big jobs, it's probably not the right tool, since:

  • routes style systems are (imho) better than pure regex ones
  • integrating web.py with other middlewares might be adventurous
Gregg Lind
All this said, web.py has *lots* of issues, which might bite when your application gets heavier, so be forewarned!
Gregg Lind
A: 

Check out web2py. It runs out of the box with no configuration - even from a USB stick. The template language is pure Python and you can develop your entire app through the browser editor (although I find vim faster ;)

Plumo
A: 

Don't forget Bottle. It is a single-file micro web framework with no dependencies and very easy to use. Here is an "Hello world" example:

from bottle import route, run
@route('/')
def index():
    return 'Hello World!'
run(host='localhost', port=8080)

And here an example for accessing POST variables (cookies and GET vars are similar)

from bottle import route, request
@route('/submit', method='POST')
def submit():
    name = request.POST.get('name', 'World')
    return 'Hello %s!' % name