Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dylan Jay: The myth of goldilocks and the three...

Dylan Jay: The myth of goldilocks and the three frameworks, Pyramid, Django and Plone

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Dylan Jay:
The myth of goldilocks and the three frameworks, Pyramid, Django and Plone
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
@ Kiwi PyCon 2013 - Saturday, 07 Sep 2013 - Track 1
http://nz.pycon.org/

**Audience level**

Intermediate

**Description**

Some people say micro-frameworks like pyramid are too small. Some people say CMS's like Plone are too big. Some people say django is juuuust right. They are all wrong. Come to this talk to find out the other hammers in the world, when you might use them, where I've used them to solve some hard problems and some of the clever ideas behind these technologies demystified.

**YouTube**

http://www.youtube.com/watch?v=XdKk5rrZG8E

New Zealand Python User Group

September 07, 2013
Tweet

More Decks by New Zealand Python User Group

Other Decks in Programming

Transcript

  1. Who am I? Dylan Jay Core Plone Contributor 1995 First

    web app (ISAPI) 1999 Built first e-commerce site (zope) 2003 Built first startup (IntroVino) 2004 Started PretaWeb/PretaGov (Plone0
  2. Reasons for this talk History "Those who don't learn from

    history are doomed to add it as a feature of their framework" Better choices There is no perfect framework, only a perfect mess when you pick wrong Reuse
  3. The goodies 1. Traversal 2. ZODB 3. ZTK Adapters 4.

    Sprints 5. Pyramid 6. Buildout 7. Plone + the customisation cliff 8. Diazo 9. RobotFramework - RobotSuite
  4. Python family tree(web) Zope (1996-) ZTK (BlueBream) (2004-) Pylons/TurboGears (2005-2010)

    Django (2005-) Flask (2010-) RoR (2004-) Plone (1999-) BFG (2008-2010) CGI (1993-) httpd (1990-) Nikola Pyramid (2010-)
  5. Zope - wtf was that about? Back in 1996 •

    webserver = path to file • cgi = path to script + args • OO - was very big • Jim Fulton was on a plane traversal = path to object + '/' + method zope = zope object publishing environment
  6. Goodie #1 - Traversal response = traverse(root, HTTP_PATH.split('/'), request) def

    traverse(context, path, request): if len(path) == 0: return context(request) elif len(path) == 1: view_method = getattr( context, path[0] ) return view_method(request) else: sub_context = context[ path[0] ] return traverse( sub_context, path[1:], request)
  7. Traversal - why? Good for CMS plugins cooperating webapps complex

    apps Traversal Routes /A/B/C/myaction /myaction/id123 distributed centrally defined Good for relational single use apps
  8. Goodie #2: ZODB • Want to store something non relational?

    • Want to store something non key-value? • Got complex object structures? Use Object persistence
  9. ZODB: The piss easy DB $ easyinstall ZODB db =

    DB( FileStorage.FileStorage('./Data.fs') ) connection = db.open() dbroot = connection.root() transaction.commit() db.close() dbroot['a_number'] = 3 dbroot['a_string'] = 'Gift' dbroot['a_list'] = [1, 2, 3, 5, 7, 12] dbroot['a_dictionary'] = { 1918: 'Red Sox', 1919: 'Reds' } dbroot['deeply_nested'] = { 1918: [ ('Red Sox', 4), ('Cubs', 2) ], 1919: [ ('Reds', 5), ('White Sox', 3) ], }
  10. ZODB: simple but powerful • transactions - multiversion concurrency control

    (MVCC) • scalability across a network (using ZEO) • replication (using ZRS or relstorage) • history/undo • transparently pluggable storage • built-in caching • Blob support
  11. Adapters: why? • Solves how to plug complex software together

    • Better than Object Orientation • Perfect for overridable software • Perfect for plugin architecture • ZTK - ZCA - Zope3 == Adapters
  12. ZTK Adapters class IUSPlug(zope.interface): prongs = Attribute("""number of prongs""") class

    Motox(object): implements(IUSPlug) prongs = 2 class INZPlug(zope.interface): prongs = Attribute("""number of prongs""")
  13. ZTK Adapters class ACPowerAdapter(object): implements(INZPlug) adapts(IUSPlug) def __init__(self, plug): self.prongs

    = plug.prongs + 1 self.voltage = 240 registry.registerAdapter(ACPowerAdapter)
  14. ZTK Adapters >>> myphone = MotoX() >>> myphone.prongs == 3

    False >>> adaptedphone = INZPlug(myphone) >>> adaptedphone.prongs == 3 True
  15. Sprints “The practice of using sprints for open source software

    development was pioneered by the Zope Corporation in the early days of the Zope 3 project. Between January 2002 and January 2006, more than 30 Zope 3 sprints had taken place.[citation needed]” Plone Pacific Rim Sprint 14-15 Sept
  16. Goodie #4 Pyramid Zope (1996-) ZTK (BlueBream) (2004-) Pylons/TurboGears (2005-2010)

    Django (2005-) Flask (2010-) RoR (2004-) Plone (1999-) BFG (2008-2010) CGI (1993-) httpd (1990-) Nikola Pyramid (2010-)
  17. Pyramid: It's micro! from wsgiref.simple_server import make_server from pyramid.view import

    view_config from pyramid.config import Configurator if __name__ == '__main__': config = Configurator() config.add_route('hello', '/hello/{name}') config.scan() app = config.make_wsgi_app() server = make_server('0.0.0.0', 8080, app) server.serve_forever() @view_config(route_name='hello', renderer='json') def hello_world(request): return {'content':'Hello %(name)s!' % request.matchdict}
  18. Pyramid: worst name ever Pyramid (the structure) Pyramid (the framework)

    Start big - End small Start small - End big Ancient Best of breed Unchanging over time Extensible & Flexible
  19. Pyramid: a "micro & more" Framework • a declarative authorization

    system • extensibility: aggregate Pyramid application configuration from multiple sources • separate I18N translation string factories • reuse: "Interface" based view/subscriber registrations • optionally map URLs to code using traversal
  20. Pyramid: routes vs. traversal: why not both? from wsgiref.simple_server import

    make_server from pyramid.config import Configurator from pyramid.response import Response class Resource(dict): pass def get_root(request): return Resource({'a': Resource({'b': Resource({'c': Resource()})})}) def hello_world_of_resources(context, request): output = "Here's a resource and its children: %s" % context return Response(output) if __name__ == '__main__': config = Configurator(root_factory=get_root) config.add_view(hello_world_of_resources, context=Resource) app = config.make_wsgi_app() server = make_server('0.0.0.0', 8080, app) server.serve_forever()
  21. Goodie #5: buildout buildout - what you get if you

    put make, puppet, python, pip, virtualenv into a blender
  22. Buildout • uses recipes - python packages that know how

    to build other things ◦ like puppet • automated dependencies ◦ like Make • recipes download and install python packages into your environment ◦ like PIP/easy_install • everything gets installed into a local directory isolated from your system ◦ like virtualenv
  23. Buildout is like... you need it when - you’re on

    tour (deploy different places) - very different components
  24. Goodie #6: Plone 300+ core contributors 400+ plugins 1000+ commits/month

    5-8 sprints per year 1 Plone foundation 1-2 CVE's/year
  25. Plone Plone step 1: Install wget --no-check-certificate https://launchpad. net/plone/4.3/4.3.1/+download/Plone-4.3.1- UnifiedInstaller.tgz

    # Extract the downloaded file tar -xf Plone-4.3-UnifiedInstaller.tgz # Go the folder containing installer script cd Plone-4.3-UnifiedInstaller # Run script ./install.sh standalone cd ~/Plone/zinstance bin/instance fg
  26. Plone Step 3: Add plugins $ nano buildout.cfg [instance] ...

    eggs = Products.PloneFormGen collective.recaptcha $ bin/buildout $ bin/instance fg
  27. Framework vs CMS start with a blank page start with

    fully featured site build up customise down good for "app" sites good for "content" sites others can edit Framework CMS startup tool agency tool risk reinventing the wheel risk hitting customisation cliff dev has full control shared control, editors, admin, dev, themer
  28. Large content site Plugins Themes Frontend dev / Themer Content

    Editor Site Admin Integrator Reviewer Enterprise CMS
  29. Goodie #7: Diazo - Ultimate in code - html seperation

    - templates without altering your html - allows designer to work on html while you work on the code - round trip
  30. Diazo.org 1. app with very simple html - "content" 2.

    create mockups in html of how you want the pages to really look - "theme" 3. create a rules.xml. 4. Compile it to single XSLT file, 5. execute it in middleware
  31. RobotFramework • Not invented by Plone/Zope (Nokia did) • but

    robotsuite was • Used to test Plone • Automated screenshots for user manuals
  32. Summary • CMS is good for content • CMS is

    good for non technical editors • Frameworks are good for unique apps • CMS is good for content and unique apps ◦ if you know what you're doing • Anything can do anything, if you know what you're doing • More complex the framework, the harder it is to know what you're doing • Trust me I'm a professional, I know what I'm doing • We're hiring (if you also know what you're doing) Thank you. - Dylan Jay (pretagov.com.au)
  33. Micro vs. Fw • Do you know a framework already?

    ◦ use that • Do you want the most developers/answers? ◦ use django • Do you need admin UI? ◦ use django (or CMS) • Do you want your own DB? ◦ use micro or django • What to go Micro? ◦ use pyramid. ◦ "the elevator that goes all the way up".
  34. ZODB: Summary Pros • Stores unstructured or structured • Stores

    complex relationships • ORM-less: Python objects == ZODB • Pure python (ish) • DB not CPU bound Cons • Can't inspect data without code • DB not CPU bound
  35. ZODB: Pythons piss easy database "A ZODB storage is basically

    a directed graph of (Python) objects pointing at each other, with a Python dictionary at the root. Objects are accessed by starting at the root, and following pointers until the target object. In this respect, ZODB can be seen as a sophisticated Python persistence layer." - Wikipedia