Are there any tools which generate a project layout for python specific projects, much similar to what maven accomplishes with mvn archetype:generate
for java projects.

- 60,022
- 51
- 208
- 332

- 24,861
- 26
- 62
- 81
-
1See also: http://stackoverflow.com/questions/193161/what-is-the-best-project-structure-for-a-python-application and http://guide.python-distribute.org/ – Daenyth Apr 03 '12 at 19:52
4 Answers
It is the good news: you do not need any tool. You can organise your source code in any way you want.
Let recap why we need tools in the java world:
In java you want to generate directories upfront because the namespace system dictates that each class must live in one file in a directory structure that reflects that package hierarchy. As a consequence you have a deep folder structure. Maven enforces an additional set of convention for file location. You want to have tools to automate this.
Secondly, different artefacts require use of different goals and even additional maven projects (e.g. a ear project requires a few jars and war artefacts). There are so many files to create you want to have tools to automate this.
The complexity makes tools like mvn archetype:generate
not just helpful. It is almost indispensable.
In python land, we just do not have these complexity in the language.
If my project is small, I can put all my classes and functions in a single file (if it makes sense)
If my project is of a bigger size (LOC or team size), it makes sense to group .py
files into modules in whatever way makes sense to you and your peers.
At the end of the days, it is about striking a balance between ease of maintenance and readability.

- 37,791
- 46
- 172
- 304
-
4I agree, but given that Maven likes to enforce a folder structure, I'm guessing the original author really wants some consistency with that. And probably wants the answer "src/main/python" or "src/main/py" confirmed to them! – JeeBee Nov 22 '13 at 17:49
-
3The fact that you can organize your code any way you want in Python does not mean you should. Being able to generate structure upfront make sense. Projects like scaffold-py show that there is a need for this also in Python (or in any language). – Guillaume Nov 02 '16 at 15:36
-
but if you want a template project for serverless, lambda and python? My impression is that there are configuration not matter what language you choose. – Elias Mar 01 '21 at 06:49
In Python (just as in any language) there are a lot of pieces to configure if you want to make all of them play nicely together. Documentation, testing, virtual envs, packaging, ...
You can add those configuration along the way, when you actually need them, or when your project starts growing. Having a tool that can configure all that for you and just let you fill the blanks does help quite a bit.
A few projects to look at:

- 18,494
- 8
- 53
- 74
The following few bash commands work pretty well for me:
mkdir myproject
cd myproject
mkdir docs
mkdir tests
touch tests/__init__.py
With python, unlike java or c, you generally don't need much more than this. See the answers to a related question. If you think you need more, you're going to have to be more specific about your requirements.
-
but if you want a template project for serverless, lambda and python? My impression is that there are configuration not matter what language you choose. – Elias Mar 01 '21 at 06:48
For Python and maven, as initially asked (i.e. Java use as well), you can use
https://github.com/paulvi/java-python-graalvm-template
Standard maven folder layout would imply something like this
src
|---main
| |---java (Keep your java files here)
| |---resources
| |---python (You can keep you python files here)
|
|---test
| |---java (Keep your java unit test files here)
| |---resources (If you have any resources test specific)
| |---python (for python test here)
|
but I bet it would make things easier instead of src/test/python
to use src/main/python/test
and exclude test
subfolder from copying into resulted jar/war distribution.
Ref: https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

- 1,815
- 5
- 30
- 54

- 60,022
- 51
- 208
- 332