Download - Introduction to Pyramid
![Page 2: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/2.jpg)
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íctor's Blog @sneridagh
![Page 3: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/3.jpg)
Brief historyPylons (2005-2010)
+
repoze.bfg (2008-2010)
=
Pyramid (2010- )
Joined under the same umbrella, the
TurboGears joined to the project few months later
Version 1.4 supports Python 2.6 ~ 3.x
Pylons Project
![Page 4: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/4.jpg)
SimplicityAbout ~5000 lines of code
![Page 5: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/5.jpg)
MinimalismTry to solve the fundamental problems
Mapping URLs to codeTemplatingSecurityServe static assets
![Page 6: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/6.jpg)
DocumentationJust a word... awesome
Obsessively up-to-date
More than 800 printed pages
![Page 7: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/7.jpg)
SpeedOptimized for fast code execution
![Page 8: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/8.jpg)
Reliability100% obsessive tested
"If it ain’t tested, it’s broke"
![Page 9: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/9.jpg)
and...Beautifuly pythonic
Pragmatism everywhere
Lots of: "Fuck, yeah!"
![Page 10: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/10.jpg)
Heavy influence of ZopeChris McDonoughConfiguration via zcml (optional, not core)Component architecture (zope.component)ZODB (optional, not enforced)URL Traversal concept
![Page 11: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/11.jpg)
Single file applicationfrom wsgiref.simple_server import make_serverfrom pyramid.config import Configuratorfrom pyramid.response import Response
def 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()
![Page 12: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/12.jpg)
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')
![Page 13: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/13.jpg)
Developer toolsSetuptools/Distribute compliantProject scaffoldingConvenience scriptsDebug toolbar
![Page 14: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/14.jpg)
TemplatingChameleon (Zope Page Templates clone)MakoJinja2Virtually any other pythonic template system
![Page 15: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/15.jpg)
PersistenceSQLAlchemy (OOTB)ZODB (OOTB)MongoDBVirtually any other persistence system or database
![Page 16: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/16.jpg)
SecurityHigh level of granularityExtensiblePluggableLocal, LDAP, SQL, oAuth providers, etc.
![Page 17: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/17.jpg)
MiscelaneousPastedeploy configurationi18nEvent systemHooksTweens conceptSession management
![Page 18: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/18.jpg)
Cornice: A REST framework forPyramid
[..]from cornice import Service
info_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]
![Page 19: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/19.jpg)
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_body return {'success': True}
![Page 20: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/20.jpg)
Resourceshttp://docs.pylonsproject.org/http://cornice.readthedocs.org/https://github.com/pylons
![Page 21: Introduction to Pyramid](https://reader031.vdocuments.net/reader031/viewer/2022020122/54ba1d624a7959320e8b45ff/html5/thumbnails/21.jpg)
Sorry for theconvenience