Intro to the Python Framework Pyramid
sixfeetup.com
sixfeetup.com
I used to think getting a site up and running in ten minutes meant something bu I tend to believe it is usually teaching bad habits or allowin untrue mental models to develop
Dammit we need developer education. !:-)
After reading about it from a couple of places and writing a blog about it[1], I finally understood my entire infrastructure. While it hasnt served any practical knowledge yet, I feel much more confident about my ability to handle any error or optimizations in that area.
That being said, if I had started reading about WSGI as soon as I started , I most probably would have been lost. I think while getting a website up in 15 minutes gives a sense of accomplishment to someone getting started, it might make sense to make them aware of the underlying technologies beneath the stack once they are comfortable with the framework.
[1]http://siddharthsarda.tumblr.com/post/41369795330/analyzing-...
I don't have much knowledge of WSGI internals, apart that it passes urls in one direction and responses in the other. I suppose when I hit performances bottlenecks, it might be worth it to dive into the details, but I'm not there yet.
Knowing what is going on at a higher level, the role of the reverse proxy, the app server, the database, and who talks to who is important, but most frameworks (with, maybe, the exception of Rails) don't really abstract that away from you so much.
Now in my opinion the right place to do authorisation is earlier in the wsgi chain - using say repoze.who.
But now someone coming along sees the framework can do this and instead of learning how to chain wsgi apps they just take Armins excellent skeleton code and hey presto Flask starts to bloat.
This is not a complaint about Flask per se (I think Armin is doing a Stirling job promoting a smaller way) but it is about a chain that was supposed to mean we could pick best of breed middleware and yet we are still in which framework is best debates
It should never be how to learn pyramid / flask / django in one day but should be how to deploy a micro-service and chain it in front of authentication middleware and hey presto a working API. Stuff your templates.
Flask had less than 1000 lines when it begun, but werkzeug is much bigger than that.
> Except that it had let's say OpenId added to the framework.
Is that supposed to be a hypothetical example? Because Flask framework doesn't have openid added to it. Flask extensions for it exist, just the way it should. The users can write whatever extensions they want - that shouldn't concern framework developer or other users.
> Now in my opinion the right place to do authorisation is earlier in the wsgi chain - using say repoze.who.
I don't know what repoze is. But if you want to insert a wsgi middleware, you can easily do it in flask.
> But now someone coming along sees the framework can do this
The framework doesn't do auth.
> they just take Armins excellent skeleton code
I don't know which snippet you are talking about, but I believe that's about how to use Flask-OpenId extension.
> but it is about a chain that was supposed to mean we could pick best of breed middleware and yet we are still in which framework is best debates
Flask-openid is a wsgi chain. Flask app object is a wsgi object, and openid extension wraps it. Also, my concern would be ease of integration and extensiblity, not what level it works at.
How long have you been mentoring that dev and how does he/she feel about this bottom-up take to understanding WSGI development?
I think there is easily a place for getting something running quickly with Flask. But going to a growing codebase with flask or any frameworks with understanding the underlying mechanisms and options is pretty silly.
So I think get that out of the way early.
FWIW I have actually written a literate testing tool so I can actually write notes and code examples - https://github.com/mikadosoftware/doctest2 ... doclit It may be useful for this kind of thing.
I've always found django (for example I'm not specifically down on django) to be quick to get up and running but to lead you gently down a path that ends with a very high brick wall.
Pyramid on the other hand is so flexible that pretty much any part of the framework can be swapped out for something else and you can abstract the important parts of your app into a mini-framework for yourself. An example of this: The code I have <100 lines of code in a file called rest_traversal.py that maps SQLAlchemy mapped tables to urls like:
/db/Model -> all instances of Model /db/Model/1 -> model 1 /db/Model/1/relationship -> all members of model 1's relationship
I'm currently using Pyramid to build the real time front end to an algorithmic trading system and it's been the perfect balance for me.
I know that's a bit vague - really I am asking is your hundred lines in the public domain?
Here's the bulk of the code in a gist, with a little example of usage:
https://gist.github.com/boothead/5108455
Be happy to answer any questions if it's unclear.
The great thing about pyramid that this code might not really indicate if you're not familiar with it, is that you can attach instances of these traversal classes anywhere in your tree and the views will still do the right thing. Likewise, using the model_is predicate lets you override the default json renderer for specific classes if you need to.
Or does your experience say otherwise? If one were to build something that would need to be immediately scalable, don't even think of Django and head towards something like Pyramid and Flask?
Also if you are interested, make sure you check out the Pyramid app on github (linked from the article, http://www.sixfeetup.com/blog/intro-to-the-python-framework-...) to see step by step how we built the todo app.
At Six Feet Up we love Python and spend most of our time building enterprise & higher ed CMS and intranet solutions along with Pyramid or Sencha apps. We are also really interested in understanding how others are using Python in startups and the enterprise.
[1] http://cornice.readthedocs.org/en/latest/quickstart.html
> Pyramid is based on Zope, Pylons, and Django.
It is? Explain.