Upload
sneridagh
View
339
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Talk performed at the Barcelona python meetup with the topic "Python web frameworks"
Citation preview
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
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
SimplicityAbout ~5000 lines of code
MinimalismTry to solve the fundamental problems
Mapping URLs to codeTemplatingSecurityServe static assets
DocumentationJust a word... awesome
Obsessively up-to-date
More than 800 printed pages
SpeedOptimized for fast code execution
Reliability100% obsessive tested
"If it ain’t tested, it’s broke"
and...Beautifuly pythonic
Pragmatism everywhere
Lots of: "Fuck, yeah!"
Heavy influence of ZopeChris McDonoughConfiguration via zcml (optional, not core)Component architecture (zope.component)ZODB (optional, not enforced)URL Traversal concept
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()
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')
Developer toolsSetuptools/Distribute compliantProject scaffoldingConvenience scriptsDebug toolbar
TemplatingChameleon (Zope Page Templates clone)MakoJinja2Virtually any other pythonic template system
PersistenceSQLAlchemy (OOTB)ZODB (OOTB)MongoDBVirtually any other persistence system or database
SecurityHigh level of granularityExtensiblePluggableLocal, LDAP, SQL, oAuth providers, etc.
MiscelaneousPastedeploy configurationi18nEvent systemHooksTweens conceptSession management
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]
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}
Resourceshttp://docs.pylonsproject.org/http://cornice.readthedocs.org/https://github.com/pylons
Sorry for theconvenience