SlideShare a Scribd company logo
gargant.dispatch
a flexible dispatcher for WSGI
@hirokiky
@hirokiky
Contributing to Django, django-localflavor
Admin of djangoproject.jp
BePROUD Inc
Talk about pure WSGI library
Not Django
Pure WSGI dispatcher
urlrelay
example code by WSGI.org
WebDispatch
gargant.dispatch
A dispatcher for WSGI application.
now available on PyPI
2.7, 3.3 support
Basic usage
Creating tree
>>> from gargant.dispatch import Node, path_matching
>>> from path.to.yours import wsgi_app
>>> tree = Node((path_matching(['']),),
...             case=wsgi_app,
...             name='first')
            
Base setting (a.k.a Routing)
path.to.yours.wsgi_app will be called when PATH_INFO='/'
Basic usage
And creating WSGI app
>>> from wsgiref.simple_server import make_server
>>> from gargant.dispatch import make_wsgi_app
>>> app = make_wsgi_app(tree)
>>> httpd = make_server('', 8000, app)
>>> httpb.serve_forever()
            
Node
gargant.dispatch.Node is not just for creating a WSGI application.
>>> tree = Node((path_matching(['']),),
...             case='dolls')
>>> node = tree({'PATH_INFO': '/'})
>>> node.case  # 'dolls'
            
Hierarchy
>>> tree = Node((path_matching(['']),),
...             case='dolls',
...             children=(
...                 Node((path_matching['fifth']),
...                      case='shinku'),
...             ))
>>>
>>> node = tree({'PATH_INFO': '/fifth'})
>>> node.case  # 'shinku'
>>> node = tree({'PATH_INFO': '/'})
>>> node.case  # 'dolls'
            
Matching
matchings is not only path_matching
>>> tree = Node((path_matching(['']),
...             method_matching('get'),
...             lambda environ: True),
...             case='dolls',
...             )
>>>
>>> node = tree({'PATH_INFO': '/',
...              'REQUEST_METHOD': 'GET'})
>>> node.case  # 'dolls'
            
matchings return function handling environ
All of matchings return values (as bool True), the node will be
matched
URL args
node.metched is values returned by matchings
>>> tree = Node((path_matching(['']),),
...             case='doll_list',
...             children=(
...                 Node((path_matching(['{doll}']),),
...                       case='doll_detail',
...                 ),
...             ))
>>>
>>> node = tree({'PATH_INFO': '/first'})
>>> node.case  # 'doll_detail'
>>> node.matched[0]['doll']  # 'first'
            
and more...
Adaptation of each path
iteration leaf node to root node
Getting URL from node.name (future)
Let's write dispatcher
gargant.dispach is experimental/for education project
please give me your feedback
gargant.dispatch, a flexible dispatcher for WSGI
thanks
gargant.dispatch
@hirokiky

More Related Content

PDF
AnyMQ, Hippie, and the real-time web
KEY
Plack - LPW 2009
KEY
Psgi Plack Sfpm
KEY
ISUCONアプリを Pythonで書いてみた
PPSX
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
PDF
Fabric for fun_and_profit
PDF
A Gentle Introduction to Event Loops
PDF
Django最速デバッグ指南 PyConAPAC 2013
AnyMQ, Hippie, and the real-time web
Plack - LPW 2009
Psgi Plack Sfpm
ISUCONアプリを Pythonで書いてみた
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
Fabric for fun_and_profit
A Gentle Introduction to Event Loops
Django最速デバッグ指南 PyConAPAC 2013

Viewers also liked (13)

PDF
Pycon2014 django performance
PDF
django-websettingsの紹介
PDF
pyramid_layoutと僕と、ときどきzope.interface
PPTX
LLoT ランゲージアップデート Python
PDF
軽量のススメ
PDF
Useful Django 1.4
PDF
My pyhack 1301
PDF
価値を届ける技術 #bpstudy 96
PDF
Djangoフレームワークの紹介 OSC2015北海道
ODP
Djangoアプリの実践的設計手法
PDF
How we realized SOA by Python at PyCon JP 2015
PDF
Djangoのススメ
PDF
Pythonによるwebアプリケーション入門 - Django編-
Pycon2014 django performance
django-websettingsの紹介
pyramid_layoutと僕と、ときどきzope.interface
LLoT ランゲージアップデート Python
軽量のススメ
Useful Django 1.4
My pyhack 1301
価値を届ける技術 #bpstudy 96
Djangoフレームワークの紹介 OSC2015北海道
Djangoアプリの実践的設計手法
How we realized SOA by Python at PyCon JP 2015
Djangoのススメ
Pythonによるwebアプリケーション入門 - Django編-
Ad

More from hirokiky (8)

PDF
簡単な算数でできる文章校正
PDF
エンジニアが起業のアイディアを見つける方法
PDF
それ、公開しちゃおうよ - みんなのPython勉強会63登壇
PDF
プロダクト開発してわかったDjangoの深〜いパーミッション管理の話 @ PyconJP2017
PDF
営業も広報もいない僕たちが11年間やってきたこと
PDF
使えるDjango1.4
PDF
個人の嗜好を学習し記事を推奨するフィードリーダ
PDF
卒研中間発表資料:個人に最適化したフィードリーダの構築
簡単な算数でできる文章校正
エンジニアが起業のアイディアを見つける方法
それ、公開しちゃおうよ - みんなのPython勉強会63登壇
プロダクト開発してわかったDjangoの深〜いパーミッション管理の話 @ PyconJP2017
営業も広報もいない僕たちが11年間やってきたこと
使えるDjango1.4
個人の嗜好を学習し記事を推奨するフィードリーダ
卒研中間発表資料:個人に最適化したフィードリーダの構築
Ad

Recently uploaded (20)

PPTX
Understanding Colour Prediction Games – Explained Simply
PDF
My Oxford Year- A Love Story Set in the Halls of Oxford
PDF
WKA #29: "FALLING FOR CUPID" TRANSCRIPT.pdf
PDF
Between the Reels and the Revolution Enzo Zelocchi’s Unscripted Path Through ...
PPTX
just letters randomized coz i need to up
DOCX
Nina Volyanska Controversy in Fishtank Live_ Unraveling the Mystery Behind th...
PDF
Keanu Reeves Beyond the Legendary Hollywood Movie Star.pdf
PDF
WKA #29: "FALLING FOR CUPID" TRANSCRIPT.pdf
PDF
Ct.pdffffffffffffffffffffffffffffffffffff
PPTX
Other Dance Forms - G10 MAPEH Reporting.pptx
PPTX
What Makes an Entertainment App Addictive?
PDF
Songlyrics.net-website for lyrics song download
PDF
EVs U-5 ONE SHOT Notes_c49f9e68-5eac-4201-bf86-b314ef5930ba.pdf
PPTX
Safety_Pharmacology_Tier2_Edibbbbbbbbbbbbbbbable.pptx
PDF
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...
PPTX
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
PDF
Apresentação2 analise estrutual.hhjghjpdf
PDF
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
PPTX
providenetworksystemadministration.pptxhnnhgcbdjckk
PPTX
The story of Nomuzi and the way she was living
Understanding Colour Prediction Games – Explained Simply
My Oxford Year- A Love Story Set in the Halls of Oxford
WKA #29: "FALLING FOR CUPID" TRANSCRIPT.pdf
Between the Reels and the Revolution Enzo Zelocchi’s Unscripted Path Through ...
just letters randomized coz i need to up
Nina Volyanska Controversy in Fishtank Live_ Unraveling the Mystery Behind th...
Keanu Reeves Beyond the Legendary Hollywood Movie Star.pdf
WKA #29: "FALLING FOR CUPID" TRANSCRIPT.pdf
Ct.pdffffffffffffffffffffffffffffffffffff
Other Dance Forms - G10 MAPEH Reporting.pptx
What Makes an Entertainment App Addictive?
Songlyrics.net-website for lyrics song download
EVs U-5 ONE SHOT Notes_c49f9e68-5eac-4201-bf86-b314ef5930ba.pdf
Safety_Pharmacology_Tier2_Edibbbbbbbbbbbbbbbable.pptx
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
Apresentação2 analise estrutual.hhjghjpdf
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
providenetworksystemadministration.pptxhnnhgcbdjckk
The story of Nomuzi and the way she was living

gargant.dispatch, a flexible dispatcher for WSGI