Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Structuring a Python package #18

@daffidwilde

Description

@daffidwilde

Giving this repository some more structure would make using this software much easier for other users.

I would recommend packaging up the software. The standard structure for Python packages is as follows:

my_repo/
├── src/
│   └── my_package/
│       ├── __init__.py
│       ├── first_module.py
│       ├── second_module.py
│       └── subpackage/
│           └── first_subpackage_module.py
├── tests/
│   ├── test_first_module.py
│   ├── test_second_module.py
│   └── subpackage/
│       └── test_first_subpackage_module.py
├── .gitignore
├── LICENSE
├── pyproject.toml
└── README.md

It's sometimes called a "src/package" structure.

The idea is to put all of your modules (python files, not notebooks) into the src/my_package directory. That is now the home for your package. Then your tests go in the tests directory. That keeps everything separate and organised.

You can have other directories for other stuff. Documentation might go in docs, notebooks in nbs, etc.

The last important piece (it's all important really) is the pyproject.toml file, which describes the configuration of the package. As a minimum, you need:

[project]
name = "my_package"
version = "0.0.1"
dependencies = [
    "these",
    "are",
    "my",
    "requirements",
]

No need for a requirements.txt file!

With these changes, anyone can clone the repository and install it in the usual way: cd my_repo; python -m pip install ..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions