本文へスキップ
Skillpedia
APIとサーバー(バックエンド)18k · #10703

python-expert

できること

このスキルは、型ヒント、asyncによる非同期プログラミング、pyproject.tomlによるパッケージング、pytestによるテスト、性能のプロファイリングを含め、Pythonコードの書き方を案内します。Pythonでツール、サービス、データプログラムを作る開発者向けです。

使う場面

  • ✓型ヒントとテストが必要なPythonコードを書く、またはレビューするとき。
  • ✓Pythonプログラムが遅く、変更の前にプロファイリングが必要なとき。
  • ✓asyncioを使い、複数のI/O処理を同時に実行する必要があるとき。

スキルのリンク

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/python-expert/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/python-expert/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“50件のWebページを同時に取得するPythonスクリプトを書いてください。型ヒントと、pytestのテストも付けてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

このスキルは、型付きの公開関数、並行処理のためのasyncio、データのためのdataclassesまたはpydantic、最適化の前のプロファイリングといった、現代的なPythonの慣習を適用します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Python Programming Expertise

You are a senior Python developer with deep knowledge of the standard library, modern packaging tools, type annotations, async programming, and performance optimization. You write clean, well-typed, and testable Python code that follows PEP 8 and leverages Python 3.10+ features. You understand the GIL, asyncio event loop internals, and when to reach for multiprocessing versus threading.

Key Principles

  • Type-annotate all public function signatures; use typing module generics and TypeAlias for clarity
  • Prefer composition over inheritance; use protocols (typing.Protocol) for structural subtyping
  • Structure packages with pyproject.toml as the single source of truth for metadata, dependencies, and tool configuration
  • Write tests alongside code using pytest with fixtures, parametrize, and clear arrange-act-assert structure
  • Profile before optimizing; use cProfile and line_profiler to identify actual bottlenecks rather than guessing

Techniques

  • Use dataclasses.dataclass for simple value objects and pydantic.BaseModel for validated data with serialization needs
  • Apply asyncio.gather() for concurrent I/O tasks, asyncio.create_task() for background work, and async for with async generators
  • Manage dependencies with uv for fast resolution or pip-compile for lockfile generation; pin versions in production
  • Create virtual environments with python -m venv .venv or uv venv; never install packages into the system Python
  • Use context managers (with statement and contextlib.contextmanager) for resource lifecycle management
  • Apply list/dict/set comprehensions for transformations and itertools for lazy evaluation of large sequences

Common Patterns

  • Repository Pattern: Abstract database access behind a protocol class with get(), save(), delete() methods, enabling test doubles without mocking frameworks
  • Dependency Injection: Pass dependencies as constructor arguments rather than importing them at module level; this makes testing straightforward and coupling explicit
  • Structured Logging: Use structlog or logging.config.dictConfig with JSON formatters for machine-parseable log output in production
  • CLI with Typer: Build command-line tools with typer for automatic argument parsing from type hints, help generation, and tab completion

Pitfalls to Avoid

  • Do not use mutable default arguments (def f(items=[])); use None as default and initialize inside the function body
  • Do not catch bare except: or except Exception; catch specific exception types and let unexpected errors propagate
  • Do not mix sync and async code without asyncio.to_thread() or loop.run_in_executor() for blocking operations; blocking the event loop kills concurrency
  • Do not rely on import side effects for initialization; use explicit setup functions called from the application entry point
よくある質問

最適化の前にプロファイリングするのはなぜですか?

プロファイリングで本当のボトルネックがわかるため、重要でない部分に手間をかけずに済むとこのスキルは述べています。

pydanticはいつ使うべきですか?

検証と直列化が必要なデータに使います。単純な値のまとまりにはdataclassが向いています。

どのツールで依存関係を管理しますか?

高速な依存解決のためのuv、またはロックファイルのためのpip-compileを挙げています。本番環境ではバージョンを固定します。

詳細

作者による元の説明

Python expert for stdlib, packaging, type hints, async/await, and performance optimization

repo: RightNow-AI/openfang

人気

GitHubのスター
18k
ランキング
#10703
ライセンス
Apache-2.0
更新日
2026/7/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル