The big Python surprise: a culture of composable libraries, like Clojure

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

It is well known that Clojure has a culture best summarized as “Clojure developers prefer to assemble their own stack from small, composable libraries.

I have been working with Python lately. I am surprised by that it also has a culture of using small libraries. There have been 2 attempts at monolithic frameworks in Python: Zope and Django (maybe Pylons, though it is done as separate libraries, sort of like Symfony2 in PHP). But for the most part, Python goes for micro-frameworks, such as Flask (comparable to Ruby’s Sinatra) and Bottle and Bobo (read about 14 Python microframeworks). These micro-frameworks use the other libraries that the Python culture is built out of, so these micro-frameworks are comparable to the lightweight frameworks of the Clojure world.

It’s also common for Python developers to pull together a bunch of different libraries, to meet whatever their current needs happen to be. This too resembles Clojure. Here is a partial list of some popular libraries in different categories:

For Python templates:

Jinja

Pystache

Chameleon

Mako

Beautiful Soup

Scrapy

For authentication:

Flask Principal

Repoze.who

Authomatic

HTTP:

Requests

HTTPlib2

urllib

urllib2

unirest

Werkzeug

Serialization:

Pickle

JSON Pickle

Marshall

dfiance

Routing:

Routes

wheezy

Werkzeug

Database Migrations:

Alembic

Flask-Migrate

simple-db-migrate

ORMs:

SQLAlchemy dominates this category, but there are many competing libraries.

————————-

So, you get the idea. Lots of small libraries that are composed together into an ad-hoc framework that is suited to the task at hand. (I won’t even get into the math/science stuff, which made Python famous back in the 1990s.)

I find this surprising, because I have never heard of meta-programming being emphasized as a major part of Python, and you need a lot of meta-programming to have a culture of small, composable libraries. Developers don’t write long essays about meta-programming in Python, at least not to the extent that developers write about Ruby or Lisp. This presents us with something of a conundrum: how is it that Python manages a culture of small, composable libraries, when it doesn’t support the level of meta-programming that Ruby and Lisp support? This is a paradox.

Post external references

  1. 1
    http://adambard.com/blog/sinatra-docs-in-clojure/
  2. 2
    http://www.pylonsproject.org/
  3. 3
    http://flask.pocoo.org/
  4. 4
    http://bottlepy.org/docs/dev/index.html
  5. 5
    http://bobo.digicool.com/en/latest/index.html
  6. 6
    http://codecondo.com/14-minimal-web-frameworks-for-python/
  7. 7
    http://jinja.pocoo.org/
  8. 8
    https://github.com/defunkt/pystache
  9. 9
    http://chameleon.readthedocs.org/en/latest/
  10. 10
    http://www.makotemplates.org/
  11. 11
    http://www.crummy.com/software/BeautifulSoup/
  12. 12
    http://scrapy.org/
  13. 13
    https://pythonhosted.org/Flask-Principal/
  14. 14
    http://repozewho.readthedocs.org/en/latest/
  15. 15
    http://peterhudec.github.io/authomatic/
  16. 16
    http://docs.python-requests.org/en/latest/user/authentication/
  17. 17
    https://code.google.com/p/httplib2/
  18. 18
    https://docs.python.org/2/library/urllib.html
  19. 19
    https://docs.python.org/2/library/urllib2.html
  20. 20
    http://unirest.io/python.html
  21. 21
    http://werkzeug.pocoo.org/
  22. 22
    https://docs.python.org/2/library/pickle.html
  23. 23
    https://jsonpickle.github.io/
  24. 24
    https://docs.python.org/2/library/marshal.html
  25. 25
    https://github.com/dplepage/dfiance
  26. 26
    http://routes.readthedocs.org/en/latest/
  27. 27
    https://pypi.python.org/pypi/wheezy.routing
  28. 28
    https://pypi.python.org/pypi/alembic/0.7.1
  29. 29
    https://flask-migrate.readthedocs.org/en/latest/
  30. 30
    https://github.com/guilhermechapiewski/simple-db-migrate
  31. 31
    http://www.sqlalchemy.org/
  32. 32
    http://www.pythoncentral.io/sqlalchemy-vs-orms/
Source