python-expert
它能做什么
这个技能指导编写 Python 代码,包括类型提示、异步编程、使用 pyproject.toml 打包、使用 pytest 测试以及性能剖析。适合构建 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。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请编写一个 Python 脚本,同时抓取五十个网页,带有类型提示,并附一个 pytest 测试。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能应用现代 Python 的惯例,例如对公开函数进行类型标注、用 asyncio 处理并发工作、用 dataclass 或 pydantic 处理数据,并在优化之前先做剖析。
技术内容(原始 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
typingmodule generics andTypeAliasfor clarity - Prefer composition over inheritance; use protocols (
typing.Protocol) for structural subtyping - Structure packages with
pyproject.tomlas 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
cProfileandline_profilerto identify actual bottlenecks rather than guessing
Techniques
- Use
dataclasses.dataclassfor simple value objects andpydantic.BaseModelfor validated data with serialization needs - Apply
asyncio.gather()for concurrent I/O tasks,asyncio.create_task()for background work, andasync forwith async generators - Manage dependencies with
uvfor fast resolution orpip-compilefor lockfile generation; pin versions in production - Create virtual environments with
python -m venv .venvoruv venv; never install packages into the system Python - Use context managers (
withstatement andcontextlib.contextmanager) for resource lifecycle management - Apply list/dict/set comprehensions for transformations and
itertoolsfor 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
structlogorlogging.config.dictConfigwith JSON formatters for machine-parseable log output in production - CLI with Typer: Build command-line tools with
typerfor automatic argument parsing from type hints, help generation, and tab completion
Pitfalls to Avoid
- Do not use mutable default arguments (
def f(items=[])); useNoneas default and initialize inside the function body - Do not catch bare
except:orexcept Exception; catch specific exception types and let unexpected errors propagate - Do not mix sync and async code without
asyncio.to_thread()orloop.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
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。