HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonCritical

What is the best project structure for a Python application?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
structureapplicationtheprojectpythonbestwhatfor

Problem

Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?

Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install packages.

In particular:

  • Where do you put the source?



  • Where do you put application startup scripts?



  • Where do you put the IDE project cruft?



  • Where do you put the unit/acceptance tests?



  • Where do you put non-Python data such as config files?



  • Where do you put non-Python sources such as C++ for pyd/so binary extension modules?

Solution

Doesn't too much matter. Whatever makes you happy will work. There aren't a lot of silly rules because Python projects can be simple.

  • /scripts or /bin for that kind of command-line interface stuff



  • /tests for your tests



  • /lib for your C-language libraries



  • /doc for most documentation



  • /apidoc for the Epydoc-generated API docs.



And the top-level directory can contain README's, Config's and whatnot.

The hard choice is whether or not to use a /src tree. Python doesn't have a distinction between /src, /lib, and /bin like Java or C has.

Since a top-level /src directory is seen by some as meaningless, your top-level directory can be the top-level architecture of your application.

  • /foo



  • /bar



  • /baz



I recommend putting all of this under the "name-of-my-product" directory. So, if you're writing an application named quux, the directory that contains all this stuff is named /quux.

Another project's PYTHONPATH, then, can include /path/to/quux/foo to reuse the QUUX.foo module.

In my case, since I use Komodo Edit, my IDE cuft is a single .KPF file. I actually put that in the top-level /quux directory, and omit adding it to SVN.

Context

Stack Overflow Q#193161, score: 522

Revisions (0)

No revisions yet.