|
1 | | -# python-boilerplate |
2 | | -Minimal Python boilerplate using uv for fast dependency management, isolated virtual environments, and modern project structure. |
| 1 | +# Python boilerplate |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <a href="https://github.com/astral-sh/uv" target="blank"><img src="https://github.com/astral-sh/uv/blob/8674968a17e5f2ee0dda01d17aaf609f162939ca/docs/assets/logo-letter.svg" height="60" alt="uv logo" /></a> |
| 5 | +</p> |
| 6 | + |
| 7 | +[](https://github.com/MrHDOLEK/python-boilerplate/actions/workflows/code-quality.yml) |
| 8 | +[](https://github.com/MrHDOLEK/python-boilerplate/actions/workflows/python.yml) |
| 9 | +[](https://github.com/MrHDOLEK/python-boilerplate) |
| 10 | +[](https://www.python.org/) |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +#### A Python boilerplate using modern dev tools |
| 15 | + |
| 16 | +## Project setup |
| 17 | + |
| 18 | +### Development environment |
| 19 | + |
| 20 | +```bash |
| 21 | +# Clone the repository |
| 22 | +git clone https://github.com/MrHDOLEK/python-boilerplate.git |
| 23 | + |
| 24 | +# Navigate to project directory |
| 25 | +cd python-boilerplate/ |
| 26 | + |
| 27 | +# Checkout working branch |
| 28 | +git checkout <branch> |
| 29 | + |
| 30 | +# Setup Python environment |
| 31 | +uv python install |
| 32 | +uv venv |
| 33 | +source .venv/bin/activate |
| 34 | + |
| 35 | +# Install dependencies |
| 36 | +uv sync |
| 37 | + |
| 38 | +# Install pre-commit hooks |
| 39 | +pre-commit install |
| 40 | +``` |
| 41 | + |
| 42 | +## Tools & Features |
| 43 | + |
| 44 | +### uv |
| 45 | + |
| 46 | +Fast Python package manager, written in Rust. Configuration in `pyproject.toml` and dependencies locked in `uv.lock`. |
| 47 | + |
| 48 | +```bash |
| 49 | +# Install a package |
| 50 | +uv pip install <package> |
| 51 | + |
| 52 | +# Run a command in the environment |
| 53 | +uv run pytest tests |
| 54 | +``` |
| 55 | + |
| 56 | +### pre-commit |
| 57 | + |
| 58 | +Framework for managing git hooks. Configuration in `.pre-commit-config.yaml`. |
| 59 | + |
| 60 | +```bash |
| 61 | +# Run against all files |
| 62 | +pre-commit run --all-files |
| 63 | +``` |
| 64 | + |
| 65 | +### ruff |
| 66 | + |
| 67 | +Fast Python linter and formatter. Rules defined in `pyproject.toml`. |
| 68 | + |
| 69 | +```bash |
| 70 | +# Format code |
| 71 | +uv run ruff format . |
| 72 | + |
| 73 | +# Check code |
| 74 | +uv run ruff check . |
| 75 | +``` |
| 76 | + |
| 77 | +### Testing |
| 78 | + |
| 79 | +Using pytest for tests: |
| 80 | + |
| 81 | +```bash |
| 82 | +# Run tests |
| 83 | +uv run pytest tests |
| 84 | + |
| 85 | +# Run tests with coverage |
| 86 | +uv run pytest tests --cov=src |
| 87 | +``` |
| 88 | + |
| 89 | +### Docker |
| 90 | + |
| 91 | +```bash |
| 92 | +# Login to GitHub Container Registry |
| 93 | +echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin |
| 94 | +# Build production image |
| 95 | +docker buildx build -f .docker/python/Dockerfile -t my-python-application:latest . |
| 96 | +# Run the application |
| 97 | +docker run -it --rm my-python-application:latest |
| 98 | +``` |
| 99 | + |
| 100 | +## Documentation |
| 101 | + |
| 102 | +Learn more at these links: |
| 103 | + |
| 104 | +- [uv](https://github.com/astral-sh/uv) |
| 105 | +- [pre-commit](https://pre-commit.com/) |
| 106 | +- [ruff](https://github.com/astral-sh/ruff) |
| 107 | +- [mypy](http://mypy-lang.org/) |
| 108 | +- [bandit](https://bandit.readthedocs.io/) |
| 109 | +- [pytest](https://docs.pytest.org/) |
0 commit comments