user51710
user51710

Reputation: 1151

Python web framework with low barrier to entry

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?

Upvotes: 3

Views: 1416

Answers (7)

user242486
user242486

Reputation: 276

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

Upvotes: 1

hoju
hoju

Reputation: 29452

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

Upvotes: 0

Gregg Lind
Gregg Lind

Reputation: 21218

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

Upvotes: 5

Nat
Nat

Reputation: 9951

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

Upvotes: 1

Marquis Wang
Marquis Wang

Reputation: 11108

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.

Upvotes: 1

Alex Martelli
Alex Martelli

Reputation: 881457

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

Upvotes: 5

Pixy Misa
Pixy Misa

Reputation: 106

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.

Upvotes: 7

Related Questions