Skip to content

About

A Cookiecutter template for building Python libraries with modern tooling and best practices.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Python Library Template

A Cookiecutter template for Python libraries.

Motivation

This project scaffolds Python libraries with development tools and conventions already configured, building on the workflow provided by uv init or poetry new.

Features

  • uv for dependency management.
  • just with ready-to-use project commands.
  • mypy and Pyright for optional static type checking.
  • pytest for testing.
  • Ruff for linting and formatting.
  • Preconfigured prek hooks, a faster alternative to pre-commit.
  • MIT, BSD-3-Clause, or Apache-2.0 license generation with lice2.
  • AGENTS.md with project commands, verification steps, and documentation rules for coding agents.
  • Sphinx documentation with the Shibuya theme, Read the Docs configuration, and a GitHub Actions check.
  • llms.txt and per-page Markdown generated by sphinx-llm-friendly for agents reading the library documentation.
  • Optional Context7 guidance for looking up dependency documentation and submitting the generated library's published documentation for indexing.

Installation

Install the template dependencies:

pip install cookiecutter jinja2-git lice2

Then create a project:

cookiecutter git@github.com:Rub1kCube/python-template-libs.git

Alternatively, use a single command with uvx:

uvx --with jinja2-git --with lice2 cookiecutter git@github.com:Rub1kCube/python-template-libs.git

Enter the generated library directory and initialize Git:

cd <path-to-lib>
git init

Install just, uv, and Bash, then run just install. This installs dependencies and Git hooks while preserving the existing environment. Use just reinstall to recreate the environment and remove generated artifacts.

Run just to list available commands. just check-all checks dependencies, code, formatting, types, tests, and documentation without applying fixes. Use just format to format code and just check to run prek hooks with automatic fixes. After changing dependencies, run just install: check commands do not synchronize the environment automatically. Use just upgrade to update dependency versions and hooks.

Documentation for agents

Each generated project includes AGENTS.md for agents working on its code. The published documentation also provides llms.txt, an index linking to Markdown versions of its pages for agents using the library.

Run just docs in the generated project to build HTML, llms.txt, and the Markdown pages together in docs/_build/html/. Edit the documentation sources and docstrings; these outputs are generated automatically. just docs-check performs a strict build, runs doctests, and checks that llms.txt and index.md are nonempty. The existing documentation workflow runs this command, and Read the Docs publishes the generated files alongside the HTML pages once the repository is connected.

The generated AGENTS.md also guides agents to use Context7, when available, for dependency documentation matching the versions in uv.lock, with a fallback to official documentation or installed sources. The generated CONTRIBUTING.md explains client setup and submitting the published llms.txt to Context7. Maintainers register each library after publishing its documentation; generation and builds do not register it automatically. Context7 is optional and requires no additional Python dependency or CI service.

Each generated library also includes context7.json for repository-based indexing. It selects docs/ and keeps the root README while excluding build output and contributor instructions. The configuration applies when the repository is submitted as a Context7 source; it does not change the published llms.txt.

Library type

The type_lib prompt offers two options:

  • standard (default): a regular Python library.
  • django: a Django 5.2 library with Django>=5.2,<5.3, pytest-django for testing, and django-stubs[compatible-mypy] for type checking.

For example, from a local template checkout:

cookiecutter . --no-input project_name=my-django-lib type_lib=django copyright_holder='Your Name'

For Django libraries, pytest and the mypy plugin use tests.settings. The tests/settings.py file contains a test-only SECRET_KEY and an INSTALLED_APPS entry for the library package. Extend it as needed, for example by adding DATABASES for tests that need a database. The standard variant omits this file and the Django settings.

License selection

Choose MIT (default), BSD-3-Clause, or Apache-2.0 at the license prompt. Set copyright_holder to the person or organization that owns the copyright; its default is Your Name, so override it when generating a real project, including with --no-input.

cookiecutter . --no-input project_name=my-library license=Apache-2.0 copyright_holder='Example Organization'

The post-generation hook writes LICENSE with the current year and the supplied copyright holder. The generated pyproject.toml declares the SPDX license identifier and includes the license file in both wheel and source distributions. License generation uses templates bundled with lice2 and does not require a network connection.

Developing the template

The root .github/workflows/test.yml runs these checks on Python 3.13 and 3.14. It also generates both library types, installs their dependencies, runs their checks, and builds their packages. Renovate checks the root Python dependencies, uv.lock, and GitHub Actions for updates weekly. Its configuration is in .github/renovate.json; the Cookiecutter source directory is excluded because its pyproject.toml contains Jinja syntax. To enable automatic pull requests, install the Renovate GitHub App and grant it access to this repository.

Template license

This template is licensed under the MIT License. See LICENSE for details. Generated libraries use the license selected during generation.

About

A Cookiecutter template for building Python libraries with modern tooling and best practices.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages