Snakes on the Web; Developing web applications in python
1. Snakes on the web!
an overview of developing web
applications in .!
2014 kickstart Tech-Talks @kudanai!
2. hi…sssssss…!
• Naail Abdul Rahman!
– a.k.a. @kudanai (http://kudanai.com)!
• Freelance developer!
– Specializing in!
• back-end systems!
• Mobile applications!
• Web applications!
• … in that order!
– not so much!
• UI/design/front-end stuff…!
• …and part time lecturer!
– Villa college, Clique College.!
2014 Kickstart Tech-Talks @kudanai!
3. – B.Sc (Physics, Math, CS)!
– M.Sc (Software Engineering)!
– Plenty of non-formal education!
– … been around for a while now.!
2014 Kickstart Tech-Talks @kudanai!
4. Full Disclosure!
• I love Python!
– Use it for practically everything!
• … IF I can get away with it.!
• BUT…!
– no delusions here!
• Python has its moments!
• It’s a choice!
• After years of messing around with other languages.!
• …also!
– By “web”, I don’t necessarily mean the world-
wide-web.!
2014 Kickstart Tech-Talks @kudanai!
6. Python!
• 1989 as a successor to ABC!
– Guido Van Rossum!
– It’s been around for a while.!
• Philosophy (Zen of Python, PEP 20)!
- Beautiful is better than ugly!
- Explicit is better than implicit!
- Simple is better than complex!
- Complex is better than complicated!
- Flat is better than nested!
- Sparse is better than dense!
- Readability counts!
- …!
2014 Kickstart Tech-Talks @kudanai!
7. Python!
• What it has going for it…!
– Really easy to learn!
– Good for pretty much anything, really!
– General purpose programming!
– Really descriptive!
– Good congruence with mathematical conventions!
– Excellent data structures!
– Really good standard library!
– Excellent, beautiful documentation!
– Awesome community!
– Python3 and its break from backwards compatibility.!
2014 Kickstart Tech-Talks @kudanai!
8. Python!
– Excellent package management!
– Alternative interpreters!
• Jython, Iron Python etc…!
• What’s not so good about it!
– Interpretation lag!
– Speed, in certain situations!
– Was never really designed for web stuff anyway…!
• Hosting support and stuff is limited, but on the rise.!
– A bit harder to deploy (as opposed to, say, PHP)!
– Direct database interactions can be a bit clunky!
– Not so great (right now) for real-time stuff!
2014 Kickstart Tech-Talks @kudanai!
9. Python!
• Who uses it?!
– Google!
• A large part of Google internals are written on python, like Groups,
Maps, Gmail, Blogger!
– Reddit!
• Rebuilt on python ~2005!
– Youtube!
– Digg!
– Dropbox!
– Instagram!
– Pinterest!
– FriendFeed!
– Quora!
– … to name a few!
2014 Kickstart Tech-Talks @kudanai!
10. Python for the web!
• What’s available?!
– DBAPI, libraries, ORM’s, template engines and
so forth…!
– Frameworks and stuff!
• Zope3, Pyramid/Pylons, Django, Flask, Bottle, web2py,
Grok, so on and so forth…!
• Hosting support and stuff!
– OOTB Support!
• Support on Apache, Nginx!
– PAAS support!
• Start a flame war…!
2014 Kickstart Tech-Talks @kudanai!
11. What’s available!
• Databases!
– Backbone of most modern web applications!
– Support is pretty great.!
– Supported databases!
• Postgres!
• MySQL!
• IBM DB2!
• MSSSQL!
• Oracle!
• SAP DB!
• ODBC Stuff!
• ADO Stuff!
• SQLite!
• BerkeleyDB!
• MongoDB!
2014 Kickstart Tech-Talks @kudanai!
12. What’s available!
• Libraries!
– Extensive Python library set!
• Can be installed locally as part of the project itself!
– Package management via pip!
– Isolate environments via Virtualenv!
• Keep packages and even interpreter independent
for multiple deployments!
• Built-in to Python3!
2014 Kickstart Tech-Talks @kudanai!
13. What’s available!
• Template engines!
– Mako, Chameleon, Cheetah, Wheezy, Genshi,
Jinja…!
– Django template engine!
• Inspired Jinja!
• Also inspired things like AngularJS!
– Very similar.!
– There are literally hundreds out there.!
• Other stuff!
– LESS/SASS compilers!
2014 Kickstart Tech-Talks @kudanai!
15. What’s available!
• SQLAlchemy!
– One of the best out there!
– Used by:!
• Reddit!
• Yelp!!
• Mozilla!
• OpenStack!
• Fedora!
• Dropbox!
• Surveymonkey!
• Sourceforge!
– Never touch SQL stuff…!
2014 Kickstart Tech-Talks @kudanai!
16. Frameworks!
• Zope3!
– The granddaddy of python frameworks!
– Been around since 1999!
– Batteries included!
• Provides configurable modules for!
– Authentication!
– Templating!
– DB handling!
– Routing etc…!
– I8n!
– ZODB!
2014 Kickstart Tech-Talks @kudanai!
17. Frameworks!
• Pylons/Pyramid!
– Pylons!
• Collection of tools rather than particular tech!
• Pyramid is one of these!
– Pyramid!
• Minimalist framework inspired by Zope, Django
and Pylons (the original)!
• Designed to be modular!
– Pick which engines to use!
– Eg: popular config is Pyramid + SQLAlchemy + Jinja2!
2014 Kickstart Tech-Talks @kudanai!
18. Frameworks!
• Flask!
– “micro” framework!
– plug in what you need!
• By default uses jinj2 for templating!
• Free to pick DB interaction!
– SQLAlchemy is popular!
– Really good at doing RESTful stuff!
– Integrated unit-testing (nose)!
– Very little overhead, so will fit pretty much
anywhere where python can run!
2014 Kickstart Tech-Talks @kudanai!
19. Frameworks!
• Django!
– By far the most popular!
– Seriously batteries included!
– HUGE community!
• Massive library of drop-in modules!
– ORM (which inspired SQLAlchemy)!
• Can support SQLite, Postgres, MySQL, MSSQL!
– Automatic, customizable admin!
• Can handle CRUD on models!
• Manage users, permissions on a per model basis!
– Template engine (inspired Jinja, AngularJS)!
2014 Kickstart Tech-Talks @kudanai!
20. Frameworks!
• Tie-in with the front-end!
– Almost all these are MVC style applications!
– Front-end is defined by the templates (usually)!
– Relies on Apache/Nginx etc… to serve static
media!
• Can leverage this for very robust rich applications!
– Rapidly deploy REST back-ends using Flask/Django etc..!
– REST drop-ins can leverage model definitions quite nicely!
– Deploy Single Page apps over static channels!
2014 Kickstart Tech-Talks @kudanai!
21. Deployment!
• Python Support!
– Hosts that provide VPS and a Python install!
• Configure through CGI/FastCGI!
– Not optimal, but possible!
– Python friendly hosts are increasing!
• Site5, BlueHost, HostMonster, etc… work well!
– PAAS!
• Heroko, DotCloud, Pythonanywhere!
!
2014 Kickstart Tech-Talks @kudanai!
22. Deployment!
• Apache / Nginx!
– Support python deployments through!
• fastCGI!
• WSGI interface via mod_wsgi!
– Web Server Gateway Interface!
– Communication between server and Python framework!
– Recommended!
– … Synchronous!
2014 Kickstart Tech-Talks @kudanai!
23. Deployment!
• Real-Time apps become messy!
– WSGI is blocking, and synchronous by
definition.!
– uWSGI (and other implementations) are
coming around to it.!
2014 Kickstart Tech-Talks @kudanai!
24. Deployment!
• Asynchronous stuff!
– Greenlets!
• Combining WSGI with Gevent!
• A bit “hackish” TBH!
– Tornado!
• Developed by FriendFeed, maintained by
Facebook!
• Very robust!
2014 Kickstart Tech-Talks @kudanai!