0

Is there a convention(or even a PEP) on how to structure a python project for example on GitHub? More specifically python-specific files(I know about the README.md, licence, .gitignore-files).

I've googled the whole morning and found different approaches. Most of them use:

  • a requirements.txt file
  • a setup.py file

One used a makefile some other added a .travis.yml for travis and so on... . And they split their project directories in different folders like data and APP.

My Questions:

  1. What files should I include in a python-project? What files would be nice to have?
  2. Is there a convention how I should arrange different folders like data and APP or is it up to me how I want to split, name and organize the different parts of my program?

Thank you in advance for your help

123
  • 58
  • 1
  • 8
  • Does [this](https://realpython.com/python-application-layouts/) take from Real Python help? – General4077 Nov 04 '21 at 15:55
  • Does "Github" really matter? It's just a project. Shouldn't matter where it is stored... My recommendation would be to start with `poetry` projects or `cookiecutter` templates. Obviously [packaging matters](https://packaging.python.org/), but CI/CD scripts are highly dependent on what you use – OneCricketeer Nov 04 '21 at 16:15
  • Does this answer your question? [What is the best project structure for a Python application?](https://stackoverflow.com/questions/193161/what-is-the-best-project-structure-for-a-python-application) – bad_coder Nov 05 '21 at 02:40

1 Answers1

2

This is likely dependent on what you are building. The article I linked in my comment breaks out different layouts like so:

CLI Layouts:

  • One-Off Script
  • Installable Single Package
  • Application with Internal Packages

Web App Layouts:

  • Django
  • Flask

While link only answers are discouraged here, I think its counter productive to rehash the whole article but the "Installable Single Package" layout has worked for me and looks like this (borrowed from the same article):

helloworld/
│
├── helloworld/
│   ├── __init__.py
│   ├── helloworld.py
│   └── helpers.py
│
├── tests/
│   ├── helloworld_tests.py
│   └── helpers_tests.py
│
├── .gitignore
├── LICENSE
├── README.md
├── requirements.txt
└── setup.py

NOTE: If you have a data directory, I would put it at the same level as tests

General4077
  • 435
  • 1
  • 8
  • 17
  • Thanks the article on realpython really helped(but took me some time to read)! I really like that it takes other examples and provides a good solid overview. To your NOTE, if the data is only for testing I would put it also at the same level as tests. But if I should have data, that is changeable and still needs to be present after a reboot I should save it in a file under a data directory? – 123 Nov 04 '21 at 16:31
  • @123 I don't have much a strong opinion here but under `Application with Internal Packages` Real Python states of the data directory: **_Having this directory is helpful for testing. It’s a central location for any files that your application will ingest or produce. Depending on how you deploy your application, you can keep “production-level” inputs and outputs pointed to this directory, or only use it for internal testing._** I take that to be data should always have its own directory – General4077 Nov 04 '21 at 16:43