Skip to main content

Project Structure

Project Structure foundation or template

PyPI latest release version
PyPI Python versions
Python code style
Reuse license status
GitLab latest release
GitLab CI/CD pipeline status
GitLab coverage report
GitLab repository stars
GitHub release (latest SemVer)
GitHub Actions status
Codecov test coverage
GitHub repository stars
Docker Hub image version
Docker Hub image pulls count
Docker Hub stars
Docker Hub image size
KeyBase Pretty Good Privacy (PGP) key ID
GitHub followers count
LiberaPay donated per week
LiberaPay patrons count

This repository provides a minimal, yet opinionated baseline for Python [1] software projects. It includes:

Add a VCS remote for this repository to a real project. When the template adds structure specific to certain types of projects, for example command-line tools, web services, UI apps, the it adds branches for each variant. When the template makes changes to structure common to different variants it can merge those changes into those variants. Real projects can also merge those changes.

Template usage

This is a rough guide for how to use this template in your project. This isn’t widely tested. Such tests are meta and wasteful to create and support. Report any issues you have or better yet submit a PR with corrections.

  1. Pick the branch to use:

    Pick the branch for your project type:

    • py:

      Basic Python distribution metadata and packaging.

    • py-cli:

      The preceding plus boilerplate for a command-line console script with subcommand.

    • docker:

      Docker images for development and end-users or deployments.

    • py-docker:

      The preceding Docker images with the Python package installed.

    • ci:

      The preceding plus GitLab CI/CD pipelines that run tests and linters as CI and publish releases from develop and main as CD.

    • py-ci:

      The py-docker and ci branches merged together.

    • py-ci-cli:

      All the preceding combined together.

    It’s important to use one of the preceding branches to merge into your project and not the develop or main branches from the template. Template developers use those branches to test the release process. They contain bumped versions, release notes, and other release artifacts that real projects shouldn’t merge into their code or history.

  2. Merge into your project:

    If starting a fresh project:

    $ git clone --origin "template" --branch "${TEMPLATE_BRANCH:?}" \
    "https://gitlab.com/rpatterson/project-structure.git" "./foo-project"
    $ cd "./foo-project"
    $ git config remote.template.tagOpt --no-tags
    $ git remote add "origin" "git@gitlab.com:foo-username/foo-project.git"
    $ git switch -C "main" --track "origin/main"

    If merging into an existing project:

    $ git remote add "template" \
    "https://gitlab.com/rpatterson/project-structure.git"
    $ git config remote.template.tagOpt --no-tags
    $ git merge --allow-unrelated-histories "template/${TEMPLATE_BRANCH:?}"
  3. Rename files and directories derived from the project name:

    $ git ls-files | grep -iE 'project.?structure'
  4. Rename project name and template creator identity strings:

    $ git grep -iE 'project.?structure|ross|Patterson'
  5. Make changes described in # TEMPLATE: comments:

    These bits need the developer’s attention and reasoning. Read the comments and follow them with care:

    $ git grep "TEMPLATE"

Lastly, remove this Template usage section and update the rest of this ./README.rst for your project. When the template adds fixes and features, merge them into your project and repeat steps 3–5.

This template publishes pre-releases on push to the develop branch and final releases on push to the main branch. Project owners can decide the types of changes that require a pre-release before final release and the types of changes that go straight to final release. For example they can decide that:

  • Merge public contributions into develop. See the contributing documentation [16] for an example public contributions policy and workflow.

  • Optionally commit fixes for bugs in final releases to a branch off main. After passing all tests and checks, merge back into main to publish final releases directly.

  • Optionally also merge version upgrades for security updates directly to main.

Installation

Install locally or use the Docker container image:

Local Installation

Install by using any tool for installing standard Python 3 distributions such as pip [17]:

$ pip3 install --user project-structure

Optional shell prompt tab completion is available by using argcomplete [18].

Docker Container Image

The recommended way to use the container image is by using Docker Compose [19]. See the example ./docker-compose.yml file [20]. Write your configuration and run the container:

$ docker compose up

You can also use the image directly. Pull the Docker image [21]. Use it to create and run a container:

$ docker pull "registry.gitlab.com/rpatterson/project-structure"
$ docker run --rm -it "registry.gitlab.com/rpatterson/project-structure" ...

Use image variant tags to control when the image updates. Releases publish tags for the branch and for major and minor versions. For example, to keep up to date with a specific branch, use a tag such as registry.gitlab.com/rpatterson/project-structure:main. Releases from develop publish pre-releases. Releases from main publish final releases. Releases from main also publish tags without a branch, for example registry.gitlab.com/rpatterson/project-structure. Releases from main also publish tags for the major and minor version, for example registry.gitlab.com/rpatterson/project-structure:v0.8.

Releases publish multi-platform images for the following platforms:

  • linux/amd64

  • linux/arm64

  • linux/arm/v7

Usage

See the command-line help for details on options and arguments:

$ project-structure --help
usage: project-structure [-h]

project structure foundation or template, top-level package.

Pptional arguments:
  -h, --help  show this help message and exit

The Docker container image can run the command-line script as well:

$ docker compose run "project-structure" project-structure --help
usage: project-structure [-h]

Project structure foundation or template, top-level package.

optional arguments:
  -h, --help  show this help message and exit

Contributing

GitLab hosts this project [22] and mirrors it to GitHub [23] but use GitLab for reporting issues, submitting pull or merge requests and any other development or maintenance activity. See the contributing documentation [16] for more details on how to get started with development.

Motivation

Plenty other project templates exists. Why make another? I’ve been a full-stack web developer from 1998 on. I’ve had plenty of time to develop plenty of opinions of my own. From a template I want a full tool set (for example test coverage, linting, formatting, CI). Conversely, I want minimal dependencies, structure, and opinion beyond a full tool set (for example some build or task system, structure for unused frameworks or libraries). I couldn’t find a template that manages that balance and I created this one.

I also find it hard to discern from other templates why they made what choices the did. As such, I also use this template to try out different options and learn for myself. You can learn about my findings and the reasons the choices I’ve made in the commit history.

Most importantly I’ve never found a satisfactory approach to keeping project structure up to date over time. As such, the primary motivation is providing a template upstream remote, merging structure updates into real projects over their lifetime.

References

Metadata

Release files for project-structure 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for project-structure 1.0.1
File Size Uploaded Provenance Actions
project-structure-1.0.1.tar.gz 165.7 kB Without provenance Details for project-structure-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for project-structure 1.0.1
File Interpreter ABI Platform Actions
project_structure-1.0.1-py3-none-any.whl Python 3 none any Details for project_structure-1.0.1-py3-none-any.whl

Total release size: 176.0 kB

Release files / project-structure-1.0.1.tar.gz

Download URL project-structure-1.0.1.tar.gz
Size 165.7 kB
Tags Source
SHA-256 checksum
How to use checksums
639c4a4ff5d4b6a2b2e086560af422848a9d5db946951d1d340ccf560e332b3c
BLAKE2b-256 checksum
How to use checksums
01854d7db3e29b6edb9aeb9b7331e1d608b1f0e97958a3423c5e6093c15dc977
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / project_structure-1.0.1-py3-none-any.whl

Download URL project_structure-1.0.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7a2937d2e8f81f02ccb27c64f8cc4d105460ec034615c4c6d9691330cd66516
BLAKE2b-256 checksum
How to use checksums
476ec1ff4b36f53c613c7d85306faf0c86c6bcde66a9c17289b4540be0b614f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Security for project-structure 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page