Pyramid is Awesome for Beginners

by Ruslan Spivak on February 5, 2012

I know some people think that Pyramid is a complex framework and that aspiring Python web developers should start with something else and maybe come back to Pyramid later.

But I truly believe that even if you’re a total beginner Pyramid can serve you really well and once you grow more experienced, you’ll appreciate the power that you get with the Pyramid framework.

Take a look at this “hello world” application in hello.py:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator

def hello(request):
   return 'Hello %(name)s!' % request.matchdict

if __name__ == '__main__':
    config = Configurator()
    config.add_route('main', '/hello/{name}')
    config.add_view(hello, route_name='main', renderer='string')
    server = make_server('', 8080, config.make_wsgi_app())
    server.serve_forever()

It wasn’t that difficult.

And this is how to install and run it:

$ pip install pyramid
$ python hello.py

Then in your browser type http://localhost:8080/hello/fred and see the result. Easy peasy.

So what are you waiting for? :) Grab it here and give it a try!

If you enjoyed this post why not subscribe via email or my RSS feed and get the latest updates immediately. You can also follow me on GitHub or Twitter.

{ 9 comments… read them below or add one }

flabber February 5, 2012 at 3:52 PM

I would say bottle is the simplest framework for a beginner. It is a bit less magic – being a single file and all.
The same hello world in bottle is
from bottle import route, run

@route(‘/hello/’)
def index(name=’World’):
return ‘Hello %s!‘ % name

run(host=’localhost’, port=8080)
I agree, Pyramid has more to offer than bottle, but for a beginner, I would recommend bottle.

Reply

Ruslan Spivak February 5, 2012 at 8:15 PM

Looks like there is now a whole thread on reddit about this: http://www.reddit.com/r/Python/comments/pc7en/pyramid_is_awesome_for_beginners/

Reply

Tom Willis August 12, 2012 at 5:33 PM

you don’t think that decorator is magic for a beginner?

Reply

timkofu August 21, 2013 at 4:17 AM

A beginner should atleast have read the enter Python tutorial from python.org

Reply

Tom February 5, 2012 at 4:04 PM

If I’m starting a new database-backed website, what are the reasons to choose Pyramid over Django?

Reply

Ruslan Spivak February 5, 2012 at 8:13 PM

I would start with usual – try both and see what fits you best, but I understand that we all have just so much time to do our stuff.
So I’ll just say that it depends on your requirements. If all you need is a Django admin interface to access your database through the Web from the get-go then I guess Django is a an obvious choice here.
If that’s not the case and you anticipate that you could benefit from SQLAlchemy for accessing your database then give Pyramid a try. Hope that helps.

Reply

Adil February 11, 2012 at 7:17 AM

For me, for example, one of the best killer feature of Pyramid is speed in comparison with Django. If you try to search for different benchmarks, you’ll find that Pyramid approximately 1000 times faster in terms of working with SQL-based databases.

Django is awesome, but its ORM really sucks if you try to build medium-size web app

Reply

Ben May 9, 2012 at 9:51 AM

Hey, take a look at wheezy.web: https://bitbucket.org/akorn/wheezy.web.

Reply

Roberto Jovana June 29, 2013 at 2:36 AM

I found wheezy.web recently… the content caching solution with dependencies is quite amazing. Would be interesting to hear your thoughts on this web framework should the time permit.
http://mindref.blogspot.com/2013/01/wheezy-web-quick-start-empty-project.html

Reply

Speak your mind

Previous post:

Next post: