Wed, 07 Jan 2009

What's a good Python code base?


A friend asks,

i'm going to be recoding <x> from scratch starting next week, in python.
what codebase would you recommend as good to model after?

Any thoughts on a well-formed, reasonably sized (yet not huge), and simple Python code base?

There have to be some examples somewhere! I'd suggest something in the stdlib, but nothing is coming to mind right now -- and there are some real stinkers in there, too.

For now, I've pointed my friend towards PEP 8 and the Python Cookbook. Very unsatisfying.

--titus

posted at: 12:11 | path: /jan-08 | 13 comments

Tags:


Comments:

Posted by Greg Wilson at Wed Jan 7 12:54:33 2009:
If you find one, please let me know --- my students would want to see it too.

Posted by Joseph Lisee at Wed Jan 7 14:03:59 2009:
Trac: http://trac.edgewall.org/browser/trunk/trac

Its on the bigger size, but they use a very neat extension point and plugin system which makes modifying and expanding Trac very easy and powerful.  I built a similar plugin/extension point system myself based on some of the "magic" Trac uses to make there's work.  Trac also has decent package organization and testing.

Posted by Brett at Wed Jan 7 14:13:08 2009:
Typically the newer modules in the standard library that were specifically for the stdlib and not imported from external use tend to be very good. I remember thinking at one point that the heapq module was of high quality, for instance.

Posted by Jonathan Ellis at Wed Jan 7 14:18:27 2009:
I guess your objection to the Cookbook (dead trees version) is that the projects are too small?  Other than that I thought the commentary was quite good.

Posted by Titus Brown at Wed Jan 7 14:31:56 2009:
Jonathan -- exactly.

Joseph, Trac is big enough that I worry it's got its whole own set of conventions.  It's definitely hard to grok.  I guess I'm looking for something in the "sweet spot" between a single module and a large-ish program: small enough to understand, big enough to have to confront some real problems.

I'd offer up twill, but it's just a wrapper around mechanize, really.

Posted by hads at Wed Jan 7 14:35:18 2009:
Check out Zine; http://zine.pocoo.org/ - it's a pretty new project but the guys behind it write nice code in my opinion.

Posted by Rene Dudfield at Wed Jan 7 14:47:24 2009:
hi,

great question.

I wouldn't recommend the stdlib modules... often they are only written for the latest version of python - and are made for distribution with python - not for external distribution.

There are *many* things you need to do for high quality external packages that you don't need to do with stdlib modules.

Good python modules often need to work with older releases of python.

You'll probably need to make heaps of hacks/extensions to distutils, have automated bots building and testing it all the time, plus all sorts of other things.

You need to have it packagable for the various OS distributions, like debian, freebsd, macports, windows installers, mac OSX installers etc etc.  Not to mention setting it up in pypi, easy_install, and buildout.

A good small software needs to have it all in one file with tests and all :)  Then people can just copy that file into their project and they are done.

Then there is building a community around the project... which is often very important.  So there are lots of examples available, and posts about how to do things.  Can people easily contribute?  Can people test the software on their platform easily?

There is also promotion -- where to announce the project?  Documentation about why the software is useful, it's pros and cons.

Also, applications have many different requirements compared to frameworks, or libraries.

I guess it really depends on the type, and size of the software, and the distribution needs.

For big projects, I'd look at cherrypy, twisted, pygame, moinmoin, trac, and numpy.  Each project has different requirements and needs.  I'd call each of these projects good for their requirements.


... anyway, there's some rambling thoughts on the matter for you... I'm very interested in what others have to say about the question.

Posted by Giulio Piancastelli at Wed Jan 7 16:35:48 2009:
I'm in a similar position as your friend. I had a look at html5lib (http://code.google.com/p/html5lib/): I found some inspiring bits, but I am really a newbie at Python coding and code base structuring, so I'm not in the best position to judge html5lib's quality.

If you look at it, I'd be interested in reading your thoughts.

Posted by Ben at Thu Jan 8 04:03:40 2009:
web.py

Posted by Tom at Thu Jan 8 16:55:37 2009:
It is by no means small, but one of the best I've seen is Twisted. Religious about TDD, automated builds, etc. The codebase is pretty enormous, but you could probably showcase any individual module for a smaller slice.

http://twistedmatrix.com

Posted by Chris Perkins at Fri Jan 9 16:15:37 2009:
I think the sqlalchemy codebase is a work of art.

Twisted codebase is good, but it does not follow pep-8.

The Pylons codebase is nice, as are Formencode, and PasteScript.

Posted by Yi Qiang at Sat Jan 10 20:38:45 2009:
Another vote for Twisted, some of the best code I've had a chance to work with yet.

Posted by Yi Qiang at Sat Jan 10 20:38:53 2009:
Another vote for Twisted, some of the best code I've had a chance to work with yet.

Post a new comment:

Name:


E-mail:


URL:


Comment:


Note that comments must be manually approved; e-mail titus@idyll.org if your comment doesn't show up quickly.