python-expert
Skill này làm gì
Skill này hướng dẫn viết mã Python, gồm gợi ý kiểu dữ liệu (type hints), lập trình bất đồng bộ, đóng gói bằng pyproject.toml, kiểm thử với pytest và phân tích hiệu năng. Skill dành cho lập trình viên xây dựng công cụ, dịch vụ hoặc chương trình xử lý dữ liệu bằng Python.
Khi nào nên dùng
- ✓Khi bạn đang viết hoặc xem lại mã Python cần có gợi ý kiểu dữ liệu và kiểm thử.
- ✓Khi một chương trình Python chạy chậm và cần phân tích hiệu năng trước khi thay đổi bất kỳ điều gì.
- ✓Khi bạn cần chạy đồng thời nhiều tác vụ I/O bằng asyncio.
Liên kết skill
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/python-expert/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy viết một script Python tải đồng thời năm mươi trang web, có gợi ý kiểu dữ liệu và một bài kiểm thử pytest.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill áp dụng các quy ước Python hiện đại, như hàm công khai có kiểu dữ liệu, asyncio cho công việc đồng thời, dataclass hoặc pydantic cho dữ liệu và phân tích hiệu năng trước khi tối ưu.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Vì sao phải phân tích hiệu năng trước khi tối ưu?
Skill cho rằng phân tích giúp tìm đúng nút thắt, nên không tốn công sức vào những phần không quan trọng.
Khi nào nên dùng pydantic?
Dùng khi dữ liệu cần được kiểm tra và tuần tự hóa, còn dataclass phù hợp với các đối tượng giá trị đơn giản.
Công cụ nào quản lý phụ thuộc?
Skill nhắc đến uv để phân giải nhanh hoặc pip-compile để tạo file khóa, với các phiên bản được ghim cố định khi chạy trên môi trường production.
Chi tiết
Mô tả gốc của tác giả
Python expert for stdlib, packaging, type hints, async/await, and performance optimization
repo: RightNow-AI/openfang
Độ phổ biến
- Sao GitHub
- 18k
- Vị trí xếp hạng
- #10703
- Giấy phép
- Apache-2.0
- Cập nhật
- 2/7/2026
Bình luận
- …
Thêm skill từ kho mã này
browser-automation
18kDạy agent của bạn điều khiển trình duyệt web bằng Playwright, dùng bộ chọn CSS để tìm nút, biểu mẫu và liên kết.
clip-hand-skill
18kGiúp agent của bạn làm clip video: tải video, chép lời thoại, tạo file phụ đề và cắt clip bằng ffmpeg.
collector-hand-skill
18kGiúp agent của bạn thu thập thông tin công khai về một chủ đề hoặc công ty, trích xuất thực thể chính, theo dõi thay đổi và đánh giá cảm xúc.
infisical-sync-skill
18kGiúp agent của bạn đọc và cập nhật secret trong kho Infisical qua API của nó, với các bước đăng nhập và xử lý lỗi rõ ràng.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.