├── .gitignore ├── README.md ├── example ├── __init__.py ├── package_1 │ ├── __init__.py │ └── awesome_module.py └── package_2 │ ├── __init__.py │ └── module.py ├── setup.py └── tests └── __init__.py /.gitignore: -------------------------------------------------------------------------------- 1 | /.gitignore 2 | /__pycache__ 3 | /*.egg-info 4 | /.vscode 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A template to structure your Python application 2 | A python project to use as a template when developing a Python application. 3 | 4 | ## In order to create a Python project with a similar structure you need to do the following: 5 | ### The structure of the project should be as follows: 6 | ``` 7 | project 8 | ├── README.md 9 | ├── example 10 | │   ├── __init__.py 11 | │   ├── package_1 12 | │   │   ├── __init__.py 13 | │   │   ├── awesome_module.py 14 | │   │   ├── ... 15 | │   │   └── awesome_module_n.py 16 | │   └── package_2 17 | │   ├── __init__.py 18 | │   └── module.py 19 | ├── setup.py 20 | └── tests 21 | └── __init__.py 22 | ``` 23 | ### (Optional) Create a Python environment: 24 | * For Python3 users: 25 | * `pip install virtualenv` 26 | * `virtualenv venv_name` 27 | * `source path/to/venv_name activate` 28 | * For Anaconda users: 29 | * `conda create --name conda_env` 30 | * `conda activate conda_env` 31 | * `conda install pip` 32 | 33 | ### Next you need to create a `setup.py` file in the root folder. It should be similar to the one presented below: 34 | ``` 35 | from distutils.core import setup 36 | from setuptools import setup, find_packages 37 | 38 | setup( 39 | name='example', 40 | version='0.1dev0', 41 | author='Author Name', 42 | author_email='author_email@mail.com', 43 | packages=find_packages(), 44 | long_description=open('README.md').read() 45 | ) 46 | ``` 47 | ### You need to create an **`__init__.py`** file in the `/example` directory where you should **import the packages** (i.e. `package_1`, and `package_2`): 48 | ``` 49 | # example/__init__.py 50 | from . import package_1, package_2 51 | ``` 52 | 53 | ### After that, you need to run the `setup.py` as follows: 54 | #### While being in the root of the folder run the following command: `pip install -e .` 55 | An `example.egg-info` directory should now be created in the root directory: 56 | ``` 57 | project 58 | ├── README.md 59 | ├── example 60 | │   ├── __init__.py 61 | │   ├── package_1 62 | │   │   ├── __init__.py 63 | │   │   ├── awesome_module.py 64 | │   │   ├── ... 65 | │   │   └── awesome_module_n.py 66 | │   └── package_2 67 | │   ├── __init__.py 68 | │   └── module.py 69 | ├── example.egg-info 70 | │ ├── dependency_links.txt 71 | │ ├── PKG_INFO 72 | │ ├── SOURCES.txt 73 | │ └── top_level.txt 74 | ├── setup.py 75 | └── tests 76 | └── __init__.py 77 | ``` 78 | If everything when according to plan, you should be able to use the modules you developed in the `package_1` from the `package_2` directory likewise: 79 | 80 | ``` 81 | # example/package_2/module.py 82 | from example.package_1.awesome_module import hello 83 | ``` 84 | -------------------------------------------------------------------------------- /example/__init__.py: -------------------------------------------------------------------------------- 1 | from . import package_1, package_2 -------------------------------------------------------------------------------- /example/package_1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csymvoul/python-structure-template/18fbaa5a4d4fadf4eb16902b1f059a74c2e312f0/example/package_1/__init__.py -------------------------------------------------------------------------------- /example/package_1/awesome_module.py: -------------------------------------------------------------------------------- 1 | hello = ['Hello! This is the awesome_module!'] -------------------------------------------------------------------------------- /example/package_2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csymvoul/python-structure-template/18fbaa5a4d4fadf4eb16902b1f059a74c2e312f0/example/package_2/__init__.py -------------------------------------------------------------------------------- /example/package_2/module.py: -------------------------------------------------------------------------------- 1 | from example.package_1.awesome_module import hello 2 | 3 | print(hello) -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from setuptools import setup, find_packages 3 | 4 | setup( 5 | name='example', 6 | version='0.1dev0', 7 | author='Author Name', 8 | author_email='author_email@mail.com', 9 | packages=find_packages(), 10 | long_description=open('README.md').read() 11 | ) -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csymvoul/python-structure-template/18fbaa5a4d4fadf4eb16902b1f059a74c2e312f0/tests/__init__.py --------------------------------------------------------------------------------