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 likefeat/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
- Clone the repository in the pwd of your project.
git clone git@github.com:25-d/python-app-boilerplate .
- Install the project
uv sync --dev
- Install pre-commit hooks
pre-commit install --hook-type pre-commit --hook-type commit-msg
- Run the project
uv run app
- Change instances of
python_app_boilerplate_25_dto 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.
- 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
- Clone the repository in the pwd of your project.
git clone git@github.com:25-d/python-app-boilerplate .
- Install the project
uv sync --dev
- Check the
profiling/profiler.pyscript and replace the function under the comment to profile.
# Place function to profile here
- Run the profiling script from the root of the project.
uv run profiling/profiler.py
- Check the reports on profiling/reports.
Documentation
If deploying on Github Pages, go to the repository Settings and the Pages section to select the gh-pages branch as the source of the page.
- Clone the repository in the pwd of your project.
git clone git@github.com:25-d/python-app-boilerplate .
- Install the project docs dependencies
uv sync --group docs
- Build the documentation
uv run mkdocs build
- 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
- (Optional) Run the commit check for conventional commits to test validate commit
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
- Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
-
Set up the PyPI and TestPyPi tokens in Github secrets used by
.github/workflows/release.ymlas environmental variables -
Push to the
mainfor releases, and to a*/*format like branch for pre-releases -
Once commited, the
.github/workflows/release.ymlworkflow runs.semantic-releasegenerates 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 fromsemantic-releaseusinguv buildanduv 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
- Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
- Build the project
uv build
- Publish to an index using the
--tokenflag with a token generated from PyPi or TestPyPi. Use--index testpypiflag to publish to TestPyPi as specified in thepyproject.toml, by default it publishes to PyPi.
uv publish
Docker
- Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
- Build the Docker image from the root of the project
docker build . --file docker/app.Dockerfile --tag python-app
- Run the Docker container
docker run python-app
Docker Compose
- Clone the repository
git clone git@github.com:25-d/python-app-boilerplate .
- Build the Docker image from the root of the project. Pass the
--buildflag 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_app_boilerplate_25_d-1.0.2.tar.gz.
File metadata
- Download URL: python_app_boilerplate_25_d-1.0.2.tar.gz
- Upload date:
- Size: 4.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ebdac66e677dbd141a4127279e158c89120c17423b04d5c37b1c46b414da2e9
|
|
| MD5 |
72bbc1365b5d463f5c2d760ac0b0ab0d
|
|
| BLAKE2b-256 |
72f8d9378d194f20d53de722844801fac8ccc7d6de6909a32675cd6dab179b3e
|
File details
Details for the file python_app_boilerplate_25_d-1.0.2-py3-none-any.whl.
File metadata
- Download URL: python_app_boilerplate_25_d-1.0.2-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d32414d5cd64100c82cc944fa53048e333e1c84d390b68495b06e7ca521d6f9
|
|
| MD5 |
bbac83b9f4b3827dfd53ac95208b5a00
|
|
| BLAKE2b-256 |
ddeab999e088437cace9f6d4bb080f7f346f8664211c2197612a7b88d721ab48
|