一键导入
developing-with-python
Python 3.11+ development with type hints, async patterns, FastAPI, and pytest
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Python 3.11+ development with type hints, async patterns, FastAPI, and pytest
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Third-party API integration patterns with webhook verification, idempotency, retry with Polly, circuit breakers, and HttpClientFactory. Use when integrating external services like Stripe, Twilio, SendGrid, or HubSpot.
Third-party API integration patterns with webhook verification, idempotency, retry with Polly, circuit breakers, and HttpClientFactory. Use when integrating external services like Stripe, Twilio, SendGrid, or HubSpot.
.NET 9 development with Clean Architecture, MediatR CQRS, Entity Framework Core, minimal APIs, and dependency injection. Use when writing C# code or working with .NET projects.
Azure DevOps YAML pipelines with multi-stage deployments, template references, variable groups, and environment approvals. Use when building CI/CD pipelines in Azure DevOps.
Azure DevOps YAML pipelines with multi-stage deployments, template references, variable groups, and environment approvals. Use when building CI/CD pipelines in Azure DevOps.
Production browser automation with Playwright for RPA, web scraping, and workflow automation. Resilient selectors, session persistence, retry patterns, and Playwright 1.56 agents. Distinct from E2E testing.
基于 SOC 职业分类
| name | developing-with-python |
| description | Python 3.11+ development with type hints, async patterns, FastAPI, and pytest |
| allowed-tools | Read, Write, Edit, Bash, Grep, Glob |
Production-grade Python development following strict quality standards. Prefer security and correctness over convenience and performance.
Python code using PEP 257 docstrings. Typical library or service modules. Testing is covered in the pytest skill.
except or catching Exception without re-raising or handlingprint for operational loggingBreak code into small, reusable units (functions/classes). Each module/class/function should have a single clear purpose (SRP). Design for loose coupling; inject collaborators instead of importing deep implementation details.
Fully annotate public APIs and internal functions.
Use Optional, Union, TypedDict, Protocol, and generics
as appropriate.
from __future__ import annotations
from typing import TypeVar, Generic, Protocol, Iterator
T = TypeVar('T')
class Sink(Protocol):
"""Protocol for item consumers."""
def write(self, item: tuple[int, str]) -> None:
"""Write a single item."""
...
def process(
lines: Iterator[str],
sink: Sink,
) -> int:
"""Process lines and write to sink.
Args:
lines: Input line iterator.
sink: Destination for processed items.
Returns:
Number of items processed.
"""
count = 0
for line in lines:
# Processing logic here
count += 1
return count
Every non-trivial module, class, and function has a docstring. First line: short imperative summary. Then a blank line. Include Args, Returns, Raises, and Examples when useful.
def normalize_token(token: str) -> str:
"""Normalize a single token to lowercase.
Strips whitespace and converts to lowercase. Empty tokens
after stripping raise ValueError.
Args:
token: Raw token string.
Returns:
Normalized lowercase token.
Raises:
TypeError: If token is not a string.
ValueError: If token is empty after stripping.
Examples:
>>> normalize_token(" Hello ")
'hello'
>>> normalize_token("")
Traceback (most recent call last):
...
ValueError: token cannot be empty
"""
if not isinstance(token, str):
raise TypeError("token must be str")
t = token.strip()
if not t:
raise ValueError("token cannot be empty")
return t.lower()
Catch specific exceptions; attach context and re-raise when needed.
Prefer raise ... from e to maintain traceback.
Use logging.getLogger(__name__); choose appropriate levels.
import logging
from typing import Iterable, Iterator
logger = logging.getLogger(__name__)
class ParseError(ValueError):
"""Raised when input lines are malformed."""
pass
def parse_lines(
lines: Iterable[str],
) -> Iterator[tuple[int, str]]:
"""Parse input lines of the form 'id,value'.
Emits pairs (id, normalized_value). Lines with leading/trailing
spaces are tolerated. Empty lines are skipped.
Args:
lines: Iterable of CSV-like strings.
Yields:
Tuples of (int id, normalized str value).
Raises:
ParseError: When a non-empty line is malformed.
"""
for raw in lines:
if raw is None:
raise TypeError("lines must contain str items")
s = raw.strip()
if not s:
continue
try:
left, right = s.split(",", 1)
ident = int(left.strip())
value = right.strip().lower()
yield ident, value
except (ValueError, TypeError) as e:
logger.debug("Failed to parse line %r: %s", raw, e)
raise ParseError(f"Malformed line: {raw!r}") from e
Read secrets/config via environment variables (optionally via dotenv). Validate and sanitize all external inputs; fail fast with clear errors.
import os
from dataclasses import dataclass
@dataclass(frozen=True)
class Settings:
"""Application configuration from environment."""
batch_size: int
log_level: str
@staticmethod
def from_env() -> Settings:
"""Load settings from environment variables.
Returns:
Populated Settings instance.
Raises:
ValueError: If BATCH_SIZE is not a valid integer.
"""
raw_bs = os.getenv("BATCH_SIZE", "100")
try:
bs = int(raw_bs)
except ValueError as e:
raise ValueError(
"BATCH_SIZE must be an integer"
) from e
level = os.getenv("LOG_LEVEL", "INFO").upper()
return Settings(batch_size=bs, log_level=level)
.env.example:
BATCH_SIZE=100
LOG_LEVEL=INFO
Use generators/iterators for streaming data.
Avoid unnecessary copies; short-circuit early.
Use functools.lru_cache for pure, expensive computations.
from functools import lru_cache
@lru_cache(maxsize=512)
def expensive_computation(value: str) -> str:
"""Compute result with memoization.
Results are cached for repeated calls with the same value.
Args:
value: Input to process.
Returns:
Computed result.
"""
# Expensive processing here
return value.upper()
Avoid circular imports by injecting dependencies.
from typing import Protocol, Iterable
class Sink(Protocol):
"""Protocol for output destinations."""
def write(self, item: tuple[int, str]) -> None:
"""Write item to destination."""
...
def process(lines: Iterable[str], sink: Sink) -> int:
"""Process lines and write parsed items to sink.
Args:
lines: Input lines to process.
sink: Destination for output.
Returns:
Number of successfully processed items.
"""
from .parser import parse_lines # local import avoids cycles
count = 0
for item in parse_lines(lines):
sink.write(item)
count += 1
return count
Pin versions in requirements.txt (e.g., package==X.Y.Z).
Keep dependencies minimal; justify each addition.
Provide .env.example listing required env vars.
# requirements.txt
pydantic==2.5.0
python-dotenv==1.0.0
# Bad
def f(x): return x + 1
# Good
def f(x: int) -> int:
return x + 1
# Bad
try:
risky_operation()
except:
pass
# Good
try:
risky_operation()
except ValueError as e:
raise CustomError("Operation failed") from e
# Bad
print("failed")
# Good
logger.error("Operation failed: %s", err)
# Bad
API_KEY = "sk-live-..."
# Good
API_KEY = os.getenv("API_KEY")
# Document in .env.example
# Bad
CACHE = {}
# Good
@lru_cache(maxsize=256)
def cached_lookup(key: str) -> str:
...
# Bad
int(os.getenv("BATCH_SIZE"))
# Good
raw = os.getenv("BATCH_SIZE", "100")
try:
batch_size = int(raw)
except ValueError as e:
raise ValueError("BATCH_SIZE must be integer") from e
If any answer is no, revise the code until all criteria are satisfied.