Skip to main content

Simple Python Boilerplate

Project description

python-app-boilerplate

Python application boilerplate. This boilerplate may be used for scripts, CLIs, or GUI or non GUI services.

Requirements

  • Git 2.47.0+
  • Python 3.12.6+
  • uv 0.6.3+
  • Docker 27.4.0+ [optional]

Problems

  • No synchronization between uv-dynamic-versioning project version and docker image built. Current approach uses fallback version
[tool.uv-dynamic-versioning]
fallback-version = "0.0.0" 
  • No tool for enforcing creation of pre-release branches to have a */* format like feat/some-feature. Current approach is giving coding guidelines

Project structure

project/
├── .benchmarks/                # Benchmarks reports [pytest.ini --benchmark-autosave argument]
├── .github/workflows           # Github Actions workflows 
├── docker/                     # Dockerfiles
├── docs/                       # Documentation template
├── htmlcov/                    # Coverage reports   [pytest.ini --cov-report=html]
├── profiling/                  # Profiling script
├── site/                       # Generated documentation
├── src/                        # Code source 
│   └── python_app_boilerplate/ # Name of project
│       └──...                  # Python files of project   
├── test/                       # Test files 
│   ├── benchmark/              # Benchmark tests
│   ├── unit/                   # Unit tests
│   └── [conftest.py]           # Setup tests
├── .coveragerc                 # Coverage setup     [pytest.ini --cov-config=.coveragerc]
├── .gitignore                  # Git ignored files
├── .pre-commit-config.yaml     # Pre-commit setup
├── .python-version             # Project python version
├── .ruff.toml                  # Ruff setup
├── LICENSE                     # Project License
├── mkdocs.yaml                 # Mkdocs setup
├── mypy.ini                    # Mypy setup
├── pyproject.toml              # Project setup
├── pytest.ini                  # Pytest setup
├── README.md                   # README.md
└── uv.lock                     # Dependencies declaration

How to use

Development

  1. Clone the repository in the pwd of your project.
git clone git@github.com:25-d/python-app-boilerplate .
  1. Install the project
uv sync --dev
  1. Install pre-commit hooks
pre-commit install --hook-type pre-commit --hook-type commit-msg
  1. Run the project
uv run app
  1. Change instances of python_app_boilerplate_25_d to your project name in the following files and folders:
  • pyproject.toml: project name and app script.
  • README.md: Project structure, deployment.
  • src/python_app_boilerplate_25_d: Folder name.
  • *.py: Top path comment.
  • docs/reference/api.md: Reference to python_app_boilerplate.
  1. Commits should follow the conventional commits guideline for semantic-release to auto generate tags and versions that follow semantic-versioning in the CI/CD pipeline. Commitizen can be used to generate conventional commits
uv run cz commit

Profiling

  1. Clone the repository in the pwd of your project.
git clone git@github.com:25-d/python-app-boilerplate .
  1. Install the project
uv sync --dev
  1. Check the profiling/profiler.py script and replace the function under the comment to profile.
# Place function to profile here
  1. Run the profiling script from the root of the project.
uv run profiling/profiler.py
  1. Check the reports on profiling/reports.

Documentation

  1. Clone the repository in the pwd of your project.
git clone git@github.com:25-d/python-app-boilerplate .
  1. Install the project docs dependencies
uv sync --group docs
  1. Build the documentation
uv run mkdocs build
  1. Serve the documentation locally or use built documentation in the site/ folder to deploy it on a web server.
uv run mkdocs serve

Committing, Formatting, Linting, Type Checking, and Testing

Before committing changes, make sure to run the commit check, formatter, linter, type checker, and tests.

  • Pre-commit hooks will run the commit check, formatter, linter, and type checker before committing changes. To run the pre-commit hooks manually, use the following command:
pre-commit run --all-files
uv run cz check --message commit
  • (Optional) Run the linter and formatter
uv run ruff format
uv run ruff check --fix
  • (Optional) Run the type checker
uv run mypy .
  • (Optional) Run the tests and coverage
uv run pytest --cov

Deployment

  • Scripts may not need a deployment or packaging
  • CLIs, GUIs/non-GUI services could be deployed from a docker image or built, packaged and published to PyPI or Github Release
  • GUIs application may need an specific command in Windows. reference
[project.gui-scripts]
app-gui = "python_app_boilerplate_25_d.main:main_gui"

Automatic release

  1. Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
  1. Set up the PyPI and TestPyPi tokens in Github secrets used by .github/workflows/release.yml as environmental variables

  2. Push to the main for releases, and to a */* format like branch for pre-releases

  3. Once commited, the .github/workflows/release.yml workflow runs. semantic-release generates a git tag based on the .releaserc.json, and it pushes to github release. Finally, the running workflow publishes to PyPI or TestPyPi with the updated dynamic version from semantic-release using uv build and uv publish

release type prerelease release
Release type */* main
Versioning v1.0.0-rc.1 v1.0.0
Git Tag v1.0.0-rc.1 v1.0.0
Git Releases pre-release release
Index Publishing testPyPi pyPi

Manual TestPyPi/PyPi

  1. Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
  1. Build the project
uv build
  1. Publish to an index using the --token flag with a token generated from PyPi or TestPyPi. Use --index testpypi flag to publish to TestPyPi as specified in the pyproject.toml, by default it publishes to PyPi.
uv publish

Docker

  1. Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
  1. Build the Docker image from the root of the project
docker build . --file docker/app.Dockerfile --tag python-app
  1. Run the Docker container
docker run python-app

Docker Compose

  1. Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
  1. Build the Docker image from the root of the project. Pass the --build flag to rebuild the image if there are changes in the Dockerfile or the application code.
docker-compose --file docker/docker-compose.yml up --detach 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_app_boilerplate_25_d-1.0.1.tar.gz (4.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_app_boilerplate_25_d-1.0.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file python_app_boilerplate_25_d-1.0.1.tar.gz.

File metadata

File hashes

Hashes for python_app_boilerplate_25_d-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a6469d11cc9d9c7127a7443a719d62afae01141ef95db5c6fa2436b090e5ea50
MD5 ce2427a1a7c1119780978b467244b778
BLAKE2b-256 435c708a0ff5ba6850c2f546851565d882b56459fbc23dbb8728623a76612801

See more details on using hashes here.

File details

Details for the file python_app_boilerplate_25_d-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_app_boilerplate_25_d-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af8ca3cd283b3e236dcb3b8c0f1d0703211ecd636aad308806a19ddc33e41309
MD5 5ea79a637580b410e53c8d2d0ece9f1c
BLAKE2b-256 d51475be0738a0ecae87dd30e00acceaf8b5208ba86b84d9a07795eaf75fd625

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page