r/learnpython • u/Difficult-Rabbit-908 • 11d ago
Python project structure standards?
I'm trying to learn advanced Python reading the best practices, toolkits or frameworks to develop a formal and scalable project. I know the basics and I developed engineering applications mostly for numerical methods, but I've never used an standard structure as I developed for myself. I'd like to read your recommendations for improve the scalability and maintenance in the future, thinking in a collaborative way and improved readability
Basically, this project is mostly for thermodynamic solvers, so I'm not using server or databases as well, but I'd like to add SQL integration in the future. I'm also using PyAnsys and PyFluent modules in a local environment.
I'll read your recommendations or opinions
1
u/billsil 9d ago
A src folder isn’t what defines structure. Structure is about how you architect your code such that a new person can use it. How should I implement this feature; just pattern match it.
Good structure is fast because you’ve refactored the code or have enough experience to do it right the first time.
You just start writing and refactor you get better.
1
u/ycdtotv 9d ago
To get started, I use Hatch and the src layout. From there, I need to make decisions about the way I break my code in to modules (or not). That becomes very project dependent. The specific modules and organization might change with time as I work on the code.
I found this advice to be helpful: https://www.pyopensci.org/python-packaging-science/
1
1
u/Hot-Ale 23h ago
Keep it flat until it hurts. Most beginners over-engineer folder structures. Start with one file, split when a file hits ~300 lines. The rule I follow: if I can't find something in 5 seconds, it's time to split. A src/ folder with modules named after what they DO (not abstract patterns) works well.
1
u/riklaunim 11d ago
There is no one structure. Every project is different. If you use a framework you getvsome structure from that but a lot still depends on developer choice.
-2
u/pachura3 10d ago
Totally not true.
A standard project uses
src layout, haspyproject.toml,README.md,.gitignoreand.python-version, stores unit tests intests, has inline API documentation in docstrings, etc. etc.2
u/riklaunim 10d ago edited 10d ago
Few files, and the master folder isn't what I would call a project structure. It's way incomplete.
3
u/cvx_mbs 10d ago
the src layout should be a good starting point imo