python-best-practices

Enforce uv workflows, PEP 8 style, and type hints in Python code.

Updated May 11, 2022
One-click install
npx skills add https://github.com/Namacha411/dotfiles --skill python-best-practices-namacha411
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-best-practices
Source: https://github.com/Namacha411/dotfiles/tree/main/shared/claude/skills/python-best-practices
Command: npx skills add https://github.com/Namacha411/dotfiles --skill python-best-practices-namacha411

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Python scripts often become hard to understand and change later due to inconsistent style, missing type hints, unclear execution structure, and non-reproducible dependencies.

Core Features & Use Cases

  • Reproducible execution with uv: Use PEP 723 inline metadata for single-file throwaway scripts and uv init + uv add for real projects.
  • Static clarity with type hints: Require type hints on function signatures and prefer modern, precise types (including Final for constants).
  • Consistent readability with PEP 8: Enforce naming conventions, import grouping, formatting limits, and docstring expectations for public APIs.
  • Safety guardrails: Use if __name__ == "__main__": guards and reserve assert for invariants that type systems can’t express.

Quick Start

Ask an AI to rewrite your Python script to follow uv-based reproducible workflows, add complete type hints, and format it to PEP 8 while ensuring it can be run via uv (including the PEP 723 header when appropriate).

Frequently Asked Questions about python-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make Python scripts reproducible using uv?

To make Python scripts reproducible using uv, use PEP 723 inline metadata for single-file throwaway scripts and `uv init` with `uv add` for multi-file projects to manage dependencies. Execution should always be handled via `uv run` to ensure environment consistency.

What is the best way to add type hints to Python code for maintainability?

The best way to add type hints for maintainability is requiring them on all function signatures and using modern typing practices. This includes using precise types like `X | None`, `list[str]`, `dict[str, Any]`, and `Final` for constants to achieve static clarity.

Does uv work with PEP 8 code style and single-file Python scripts?

Yes, uv works with PEP 8 code style and single-file Python scripts by utilizing PEP 723 inline metadata. This allows you to enforce consistent readability through naming conventions, import grouping, and formatting limits while maintaining reproducible execution.

How do I structure Python code to prevent execution errors when imported?

To prevent execution errors when imported, structure Python code with `if __name__ == "__main__":` guards. This safety guardrail ensures the script runs properly via `uv run` while allowing safe imports without unintended side effects.

When should I use assert statements in Python type-checked code?

You should use assert statements in Python type-checked code only for invariants that the type system cannot express. Reserve assertions for safety checks during development rather than runtime control flow, ensuring maintainable and predictable execution.