python project directory structure

directory organization

There are already some agreed-upon directory structures on how to organize a good Python project directory structure. In this question on Stackoverflow , you can see everyone talking about the Python directory structure.

It's been said very well here, and I don't plan to reinvent the wheel to list all kinds of different ways. Here I'll talk about my understanding and experience.

Assuming your project is named foo, the most convenient and quick directory structure I suggest is enough:

Foo/
|-- bin/
|   |-- foo
|
|-- foo/
|   |-- tests/
|   |   |-- __init__.py
|   |   |-- test_main.py
|   |
|   |-- __init__.py
|   |-- main.py
|
|-- docs/
|   |-- conf.py
|   |-- abc.rst
|
|-- setup.py
|-- requirements.txt
|-- README

Briefly explain:

  1. bin/: Store some executable files of the project, of course, you can name script/it and so on.
  2. foo/: holds all the source code of the project. (1) All modules and packages in the source code should be placed in this directory. Don't put it in the top-level directory. (2) Its subdirectory tests/stores unit test code; (3) The entry of the program is best named main.py.
  3. docs/: Store some documents.
  4. setup.py: Scripts for installation, deployment, packaging.
  5. requirements.txt: A list of external Python packages that store software dependencies.
  6. README: Project description file.

In addition, there are some programs that give more content. For example LICENSE.txt, ChangeLog.txtfiles, etc., I did not list here, because these things are mainly used when the project is open source. If you want to write an open source software, how to organize the directory, you can refer to https://jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325118751&siteId=291194637