Skip to content

habedi/template-python-library

Repository files navigation

Template for a Python Library

Tests PyPI version License Python version Pip downloads CodeFactor codecov

This repository is a template to make the development of Python libraries easier. It includes a basic structure, dummy package, unit tests, and GitHub Actions workflows for testing and deployment. I'm sharing this template in case others find it useful.

Features

  • Poetry: for dependency and virtual environment management.
  • Makefile: for managing common tasks like testing, linting, and formatting.
  • GitHub Actions: for running tests, linting, and deploying to PyPI.
  • Badges: for showing the status of tests, code quality, version, etc.

Structure

  • .github: GitHub Actions workflows.
  • assets: Asset files (e.g., images, logos, etc.).
  • docs: Documentation for the library.
  • src: Library's source code.
  • tests: Unit tests.
  • .editorconfig: Editor settings for consistent coding style.
  • .gitignore: Excludes files generated by Python and Poetry.
  • .gitattributes: Git LFS configuration.
  • LICENSE: License file.
  • Makefile: Manage tasks like testing, linting, and formatting.
  • pyproject.toml: Poetry's configuration file.

Getting Started

Prerequisites

  • Python >= 3.10
  • Poetry (should work with uv as well)
  • GNU Make

Tested on Ubuntu 24.04 LTS and Debian 12. But the template should work on other operating systems as well.

Setting Things Up

  1. Clone the repository:

    git clone https://github.com/habedi/template-python-library.git
    cd template-python-library
  2. Install dependencies:

    make setup
    make install

Development Workflow Management

# See the help for available commands
make help
# Run the unit tests
make test
# Lint the code
make lint
# Format the code
make format
# Perform type checking
make typecheck
# Build the library
make build
# Publish the library to PyPI
make publish

Note

To publish the library to PyPI, make sure you have a PyPI account and a valid API token. Set the PYPI_API_TOKEN secret in your GitHub repository settings, and PYPI_TOKEN environment variable in your local environment. For more information, refer to the Poetry documentation and GitHub documentation.