Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)18k · #10703

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.md

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/python-expert/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

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 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
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

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự