Python Patterns

构建健壮、高效且易于维护的 Python 应用程序的 Python 惯用法(Pythonic idioms)、PEP 8 标准、类型提示(Type hints)以及最佳实践。

2,037 stars 332 forksSoftware Development Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add xu-xiang/everything-claude-code-zh

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add xu-xiang/everything-claude-code-zh --skill python-patterns
Manual install
git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p ~/.claude/skills
cp -r /tmp/everything-claude-code-zh/skills/python-patterns ~/.claude/skills/python-patterns

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Python 开发模式 (Python Development Patterns)

用于构建健壮、高效且易于维护的应用程序的 Python 惯用模式与最佳实践。

## 何时激活

- 编写新的 Python 代码时
- 评审 Python 代码时
- 重构现有的 Python 代码时
- 设计 Python 包(Packages)或模块(Modules)时

## 核心原则

### 1. 可读性至上 (Readability Counts)

Python 优先考虑可读性。代码应当直观且易于理解。

```python
# 推荐:清晰且可读
def get_active_users(users: list[User]) -> list[User]:
    """仅从提供的列表中返回活跃用户。"""
    return [user for user in users if user.is_active]

# 不推荐:虽然精简但令人困惑
def get_active_users(u):
    return [x for x in u if x.a]
```

### 2. 显式优于隐式 (Explicit is Better Than Implicit)

避免使用“魔法”;确保代码的行为清晰透明。

```python
# 推荐:显式配置
import logging

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

# 不推荐:隐藏的副作用
import some_module
some_module.setup()  # 这行代码具体做了什么?
```

### 3. EAFP - 宽恕好过许可 (Easier to Ask Forgiveness Than Permission)

Python 倾向于使用异常处理而非预先检查条件。

```python
# 推荐:EAFP 风格
def get_value(dictionary: dict, key: str) -> Any:
    try:
        return dictionary[key]
    except KeyError:
        return default_value

# 不推荐:LBYL (Look Before You Leap) 风格
def get_value(dictionary: dict, key: str) -> Any:
    if key in dictionary:
        return dictionary[key]
    else:
        return default_value
```

## 类型提示 (Type Hints)

### 基础类型标注
Read the full skill on GitHub

Details

Skill name
python-patterns
Path
skills/python-patterns/SKILL.md
License
MIT
Repo updated
5 March 2026

FAQ

What does the Python Patterns skill do?

构建健壮、高效且易于维护的 Python 应用程序的 Python 惯用法(Pythonic idioms)、PEP 8 标准、类型提示(Type hints)以及最佳实践。

How do I install the Python Patterns skill?

Claude Code plugin: /plugin marketplace add xu-xiang/everything-claude-code-zh. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Python Patterns popular?

It lives in xu-xiang/everything-claude-code-zh, which has 2,037 GitHub stars and 332 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.