Realtime Apps with Django
Renyi Khor
renyi.ace@gmail.com
– Renyi Khor
“Entrepreneur and CTO since 2012.
Djangonaut since 2009.
Progammer since 2006.
Programming since 1990s.”
Django
1.It’s a web framework.
2.It’s a heavy web framework (Batteries included).
3.It’s Secure - See No. 2.
4.It’s Python.
5.Large community.
6.It’s really good for prototyping and R&D.
Popular Django sites
• Disqus
• Bitbucket
• Instagram
• Pinterest
• Mozilla
• Nasa
• sentry.io, etc…
Django Channels
Django Channels
• ASGI - Asynchronous Server Gateway Interface
• Consumer-Producer Pattern
• Channels
• Worker and Background Tasks
Pros
• Easy to integrate with Django
• Django-ish routing
• Django ORM
• Customizable channel layers
• Make Django async
Cons
• Probably only heavy tested with Python and Django
users
• ASGI is quite new
• Too much work just to get websocket working
• Channels looks powerful, but complicated
Renyi’s Take
• Too complicated for prototyping
• May be good for R&D
• Yes or No ?
Tornado
Tornado
• Tornado is a Python web framework and asynchronous
networking library, originally developed at FriendFeed.
Pros
• Built with non-blocking IO in mind.
• Many async options, long polling, websockets,
coroutines, queues, multi-process, etc.
• Lots of batteries, non-blocking HTTP server, async http
client, ioloops, iostreams, net utilities, etc.
• Play well with others, wsgi (django), twisted, asyncio
(python3.5+).
• Facebook is among the core developers.
Cons
• It’s more complicated to setup
• It’s harder to design applications around it
• Batteries are pretty low level (could be a PRO)
• Almost nothing is out-of-the-box (may not be a bad
thing)
Renyi’s Take
• Easy integration with Django (FallbackHandler)
• Makes Django async (make it green)
• Easy Django + websocket (IOLoop)
• A good scalling option for Django projects
• Yes or No ?
asyncio
asyncio
• https://docs.python.org/3/library/asyncio.html
Pros
• Standard Library
Cons
• You really shouldn’t be bothered with this.
• If you do, it’s most likely out of the scope of this
talk, :p
Renyi’s Take
What you need to know
• Yes. If you have a choice, choose asyncio.
• It works well with most web/networking framework.
• If not, most popular python frameworks are going to
implement it soon.
• So, choose a good web framework that uses asyncio.
• If you are working on IO stuffs, yes asyncio is really good for
your sanity.
• Yes or No ?
Django + Tornado +
Websocket + AsyncIO
Questions ?