Introduction to Pyramid

743 views

Published on

Talk performed at the Barcelona python meetup with the topic "Python web frameworks"

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
743
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to Pyramid

  1. 1. Pyramid"Pay only for what you eat"http://bit.ly/bcnmeetup-pyramid
  2. 2. Víctor Fernández de AlbaLead web developer at Barcelona Tech UniversityAuthor of Plone 3 Intranets (2010, PacktPub)Developing Plone sites since 2004Developing Pyramid applications since its early betas- /Víctors Blog @sneridagh
  3. 3. Brief historyPylons (2005-2010)+repoze.bfg (2008-2010)=Pyramid (2010- )Joined under the same umbrella, theTurboGears joined to the project few months laterVersion 1.4 supports Python 2.6 ~ 3.xPylons Project
  4. 4. SimplicityAbout ~5000 lines of code
  5. 5. MinimalismTry to solve the fundamental problemsMapping URLs to codeTemplatingSecurityServe static assets
  6. 6. DocumentationJust a word... awesomeObsessively up-to-dateMore than 800 printed pages
  7. 7. SpeedOptimized for fast code execution
  8. 8. Reliability100% obsessive tested"If it ain’t tested, it’s broke"
  9. 9. and...Beautifuly pythonicPragmatism everywhereLots of: "Fuck, yeah!"
  10. 10. Heavy influence of ZopeChris McDonoughConfiguration via zcml (optional, not core)Component architecture (zope.component)ZODB (optional, not enforced)URL Traversal concept
  11. 11. Single file applicationfrom wsgiref.simple_server import make_serverfrom pyramid.config import Configuratorfrom pyramid.response import Responsedef hello_world(request):return Response(Hello %(name)s! % request.matchdict)if __name__ == __main__:config = Configurator()config.add_route(hello, /hello/{name})config.add_view(hello_world, route_name=hello)app = config.make_wsgi_app()server = make_server(0.0.0.0, 8080, app)server.serve_forever()
  12. 12. Application configurationDeclarative (previous example)Imperative (via decorators)from pyramid.response import Responsefrom pyramid.view import view_config@view_config(name=hello, request_method=GET)def hello(request):return Response(Hello)
  13. 13. Developer toolsSetuptools/Distribute compliantProject scaffoldingConvenience scriptsDebug toolbar
  14. 14. TemplatingChameleon (Zope Page Templates clone)MakoJinja2Virtually any other pythonic template system
  15. 15. PersistenceSQLAlchemy (OOTB)ZODB (OOTB)MongoDBVirtually any other persistence system or database
  16. 16. SecurityHigh level of granularityExtensiblePluggableLocal, LDAP, SQL, oAuth providers, etc.
  17. 17. MiscelaneousPastedeploy configurationi18nEvent systemHooksTweens conceptSession management
  18. 18. Cornice: A REST framework forPyramid[..]from cornice import Serviceinfo_desc = """This service is useful to get and set data for a user."""user_info = Service(name=users, path=/{username}/info,description=info_desc)_USERS = defaultdict(dict)@user_info.get()def get_info(request):"""Returns the public information about a **user**.If the user does not exists, returns an empty dataset."""username = request.matchdict[username]return _USERS[username]
  19. 19. Cornice: A REST framework forPyramid (II)@user_info.post()def set_info(request):"""Set the public information for a **user**.You have to be that user, and *authenticated*.Returns *True* or *False*."""username = authenticated_userid(request)if request.matchdict["username"] != username:raise Forbidden()_USERS[username] = request.json_bodyreturn {success: True}
  20. 20. Resourceshttp://docs.pylonsproject.org/http://cornice.readthedocs.org/https://github.com/pylons
  21. 21. Sorry for theconvenience

×