Search code examples
pythonpydevproject-structureproject-organization

How to organize a Python Project?


I'm new to Python and I'm starting a mini Project, but I have some doubts on how to organize the folders in the "Python Way".

I'm using PyDev in my Development Environment, and when I create a new project a folder is created called src

+ src

Now, in the PyDev, I can create Pydev Module and PyDev Package

I need to organize my Project in the following way:

+ Indicators
    - Moving_averages.py
    - Stochastics.py
+ Strategies
    - Moving_averages_cross.py
- example.py

How can I organize this in terms of Modules and Packages? What is the meaning of Modules and Packages?


Solution

  • A Package is basically a folder with __init__.py file under it and usually some Modules, where Module is a *.py file. It has to do with import mainly. If you add __init__.py to Indicators you can use:

    from Indicators.Stochastics import *
    

    or

    from Indicators import Stochastics
    

    By the way, I would recommend to keep module/package names lowercase. It does not affect functionality but it's more "pythonic".