Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Well written open source Python apps

12 views
Skip to first unread message

Ben

unread,
Oct 13, 2005, 10:43:12 AM10/13/05
to
Could anyone suggest an open source project that has particularly well
written Python? I am especially looking for code that people would
describe as "very Python-ic". (Not trying to start any kind of war -
just wanted some good examples of a well written Python app to read.)

Thanks!
-Ben

P.S. - Sorry if this has been discussed at length before - I searched
the group before I posted, but didn't come up with what I was looking
for.

Michael Ekstrand

unread,
Oct 13, 2005, 11:29:35 AM10/13/05
to pytho...@python.org
On Thursday 13 October 2005 09:43, Ben wrote:
> Could anyone suggest an open source project that has particularly
> well written Python? I am especially looking for code that people
> would describe as "very Python-ic". (Not trying to start any kind of
> war - just wanted some good examples of a well written Python app to
> read.)

The Python Standard Library. Thousands of lines of quite good Python
code. It might not use all the latest features, and there might be a
few dark corners here and there, but it's still solid. And quite easy
to understand (I had no difficulty understanding and modifying
httplib).

- Michael

Micah Elliott

unread,
Oct 13, 2005, 12:04:40 PM10/13/05
to Ben, pytho...@python.org
On Oct 13, Ben wrote:
> Could anyone suggest an open source project that has particularly well
> written Python? I am especially looking for code that people would
> describe as "very Python-ic". (Not trying to start any kind of war -
> just wanted some good examples of a well written Python app to read.)

The Python Package Index (PyPI, or cheeseshop)
<http://www.python.org/pypi> has pointers to a lot of packages that are
likely mostly pythonic.

I don't know if this is spelled out more precisely somewhere, but here
is my notion of a pythonic distribution:

* Has modules grouped into packages, all are cohesive, loosely
coupled, and reasonable length

* Largely follows PEP <http://www.python.org/peps/> conventions

* Avoids reinventing any wheels by using as many Python-provided modules
as possible

* Well documented for users (manpages or other) and developers
(docstrings), yet self-documenting with minimal inline commenting

* Uses distutils for ease of distribution

* Contains standard informational files such as:
BUGS.txt COPYING.txt FAQ.txt HISTORY.txt README.txt THANKS.txt

* Contains standard directory structure such as:
doc/ tools/ (or scripts/ or bin/) packageX/ packageY/ test/

* Clean UI, easy to use, probably relying on optparse or getopt

* Has many unit tests that are trivial to run, and code is structured to
facilitate building of tests

The first example of a pythonic package that comes to my mind is
docutils <http://docutils.sourceforge.net/>.

--
Micah Elliott
<m...@micah.elliott.name>

Steve M

unread,
Oct 13, 2005, 2:00:17 PM10/13/05
to
Here is an article discussing the coding style of BitTorrent.

http://www.onlamp.com/pub/a/python/2003/7/17/pythonnews.html

Maybe that code is worth looking at.

Grig Gheorghiu

unread,
Oct 13, 2005, 2:57:19 PM10/13/05
to
This is really synchronicity in action! I started to think yesterday
about putting together a project that measures the 'goodness' of Python
packages in the PyPI Cheese Shop repository. I call it the "Cheesecake"
project. I took the liberty of citing Micah's post in a blog entry that
I just posted:
<http://agiletesting.blogspot.com/2005/10/cheesecake-how-tasty-is-your-code.html>

Comments/suggestions welcome!

Grig

John J. Lee

unread,
Oct 13, 2005, 3:01:13 PM10/13/05
to pytho...@python.org
"Ben" <bwsa...@gmail.com> writes:

> Could anyone suggest an open source project that has particularly well
> written Python? I am especially looking for code that people would
> describe as "very Python-ic". (Not trying to start any kind of war -
> just wanted some good examples of a well written Python app to read.)

[...]

At the time I looked at it I thought this was nice, though that was
some time ago (it was still 'sketch' then) so I wonder if I'd still
have the same opinion if I looked now (due to me changing my view of
"good code", not the skencil source code changing!):

http://www.nongnu.org/skencil/


John

Micah Elliott

unread,
Oct 13, 2005, 5:19:37 PM10/13/05
to Grig Gheorghiu, pytho...@python.org

Grig, I think you're onto something here; good idea. I have no
experience with CPANTS, and I'm not sure how many of my ideals could be
checked programmatically. But if your Cheesecake tool comes into
fruition, here are some things that I would personally find useful:

* A command-line version that I could easily run on my projects.

* An output that gives more than just an index/score; maybe a bunch of
stats/indicators like pylint. I.e., it would be say "pypkglint" or
"pydistchecker", a higher level lint that operates on packages instead
of just source files.

* Some checks that might be useful

- Module and package naming conventions. (PEP-8 describes
module-naming, but I see this broken more often than followed in
practice. And it is silent on package names, but the tutorial uses
capitalized names.) Some consistency here would be nice.

- Existence of standard files. ESR goes into detail on this in his
"Art of UNIX Programming" book (pp 452).

- Existence of standard directories (those I mentioned before).

- Output of checkee "--help" should satisfy some standards. I presently
check my own tools by running "help2man" which forces me to setup
optparse to follow a strict format. I have some active RFEs on
optik (optparse) to address this.

- Use of distutils. Maybe just a check for setup.py ?

- Consistency of module length. Not sure about this one, but you
might lower the score if some package modules are 10 lines while
others are 10KLOC.

- Number of modules per package. Maybe 4..20 is a good amount?

- Extra points for existence of something like "api.html", which
indicates that epydoc/pydoc generated API info.

- Extra points for .svn/CVS/RCS directories indicating that version
control is in place. Maybe even glarking of version numbers where
high numbers indicate that code is checked in frequently.

- Use of ReST in documentation, or even in docstrings.

- Count of unit tests. Do module names map to test_<modulename> in
test directory? How many testXXX functions exist?

- A summary calculation of pylint/pychecker scores for each module.

- Point deduction (or fail!) if any .doc/.xls, etc. files included in
distribution.

- Extra points for use of modules that indicate extra usability was
incorporated, such as: gettext (multi-language), optparse (clean
UI), configparser (fine control), etc.

* A PEP describing the conventions (though some will argue that PEPs
should be enforcable by the compiler, so maybe just a "Cheesecake
Convention" document).

* And of course anything that CPANTS offers :-)

I'm sure people here have more ideas for quality indicators...

--
Micah Elliott
<m...@micah.elliott.name>

Peter Hansen

unread,
Oct 13, 2005, 8:04:28 PM10/13/05
to
Ben wrote:
> Could anyone suggest an open source project that has particularly well
> written Python? I am especially looking for code that people would
> describe as "very Python-ic". (Not trying to start any kind of war -
> just wanted some good examples of a well written Python app to read.)

I'm sorry I can't speak on its "pythonicity" (my memory sucks), but I
did find Roger Binns' BitPim program (http://bitpim.sourceforge.net/) to
be an excellent source of ideas (steal steal steal) for wxPython code,
and I do remember it struck me as being exceptionally well commented and
well structured. I suspect it's pretty Pythonic, too, since Roger seems
pretty brilliant from where I sit. :-)

-Peter

B Mahoney

unread,
Oct 14, 2005, 2:58:16 AM10/14/05
to
The paper on BitPim http://bitpim.sourceforge.net/papers/baypiggies/
lists and describes programs and ideas used for the project. Some of
it is just bullet-points, but everything seems to be well chosen. I've
swiped a lot of these ideas.

Michele Simionato

unread,
Oct 14, 2005, 3:44:45 AM10/14/05
to
> Could anyone suggest an open source project that has particularly well
> written Python? I am especially looking for code that people would
> describe as "very Python-ic".

I vote for the "doctest" code in the standard library.

Michele Simionato

Gerrit Holl

unread,
Oct 14, 2005, 4:23:45 AM10/14/05
to pytho...@python.org
Ben wrote:
> Could anyone suggest an open source project that has particularly well
> written Python? I am especially looking for code that people would
> describe as "very Python-ic". (Not trying to start any kind of war -
> just wanted some good examples of a well written Python app to read.)

Mailman - http://www.list.org/
Spambayes - http://www.spambayes.org

Those are written by experienced Python programmers, some of them Python
developers. It looks like well written code to me.

Gerrit.

--
Temperature in Luleå, Norrbotten, Sweden:
| Current temperature 05-10-14 10:19:49 8.3 degrees Celsius ( 47.0F) |
--
Det finns inte dåligt väder, bara dåliga kläder.

dave....@gmail.com

unread,
Oct 17, 2005, 2:15:16 PM10/17/05
to

[didn't read this thread or that article until I saw the summary in Dr.
Dobb's Python-URL]

FWIW, the BitTorrent code seemed like an incredible hack to me. The
above article tries to put a positive spin on it, but seriously, the
code was a mess. Hats off to Mr. Cohen for creating BitTorrent in the
first place, but I wouldn't go looking at that code for any "best
practices".

It took several days of head scratching to figure out what was really
going on because the code is almost *completely* devoid of comments -
even high level stuff like "this module is for X" or "this class does
Y", not to mention comments to clarify code that was obscure or trying
to be too cute.

A day or so into it I discovered that there were two different public
classes with the exact same name, so anytime you saw it used elsewhere
you had to dig around to figure out which class was being used.

There were also lots of more subjective things that were pretty
annoying - state was passed around in various dictionaries (they were
begging to be refactored into classes), a lot of the variable names
seemed like misnomers, values were passed out from functions via 1-item
lists, etc. - drove me nuts. :)

To be clear, I'm not trying to rag on BitTorrent, just pointing out
that it is probably not at all what the OP is looking for (well-written
Python, stuff that is generally considered "very Pythonic").

-Dave

Paulo Eduardo Neves

unread,
Oct 18, 2005, 1:25:50 PM10/18/05
to

Misto .

unread,
Oct 19, 2005, 5:49:16 AM10/19/05
to pytho...@python.org
I suggest also these:

Spark:
-----------------
http://pages.cpsc.ucalgary.ca/~aycock/spark/

Few files.
I like how doc strings are used for handling the grammar.


Twisted:
----------------
http://twistedmatrix.com/

I like everything, from test to comments! (many are funny)


Misto

0 new messages