python-best-practices

Apply Python best practices for type annotations, error handling, and PEP 8.

Updated Apr 20, 2025
One-click install
npx skills add https://github.com/cathayrisk/Anya --skill python-best-practices-cathayrisk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-best-practices
Source: https://github.com/cathayrisk/Anya/tree/main/skills/python-best-practices
Command: npx skills add https://github.com/cathayrisk/Anya --skill python-best-practices-cathayrisk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python projects often suffer from inconsistent style, weak typing, and unreliable error handling. This skill provides a structured set of guidelines to improve readability, maintainability, and correctness across modules.

Core Features & Use Cases

  • Type annotations for public APIs and function signatures to catch errors early.
  • Clear error handling patterns with specific exception types and safe fallbacks.
  • Dataclass vs TypedDict guidelines for modeling data with or without behavior.
  • Async/await patterns and logging practices aligned with PEP 8.
  • General coding standards and naming conventions to improve consistency.

Quick Start

Review and apply these Python best-practice guidelines to your next function or module to ensure quality.

Frequently Asked Questions about python-best-practices

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

FAQPage Schema
How do I add type annotations to public APIs in Python?

Type annotations for Python public APIs involve explicitly defining parameter and return types to catch errors early and improve consistency across modules.

What is the best way to handle errors and exceptions in Python?

Error handling in Python should use clear patterns with specific exception types and safe fallbacks to ensure code correctness and maintainability.

When should I use dataclasses versus TypedDict for data modeling?

Use Python dataclasses for modeling data with behavior and TypedDict for structuring data without behavior, ensuring appropriate modeling for your specific use case.

How do I structure logging and async/await patterns to follow PEP 8?

Structuring logging and async/await patterns to follow PEP 8 requires applying general coding standards and naming conventions to align with Python's style guidelines.

Does this Python coding standard apply to refactoring existing codebases?

Yes, these Python coding standards apply to writing new modules, reviewing existing code, and refactoring codebases to improve readability, correctness, and maintainability.