← スキル一覧に戻る

python-best-practices
by pproenca
Personal Claude Code plugins marketplace
⭐ 0🍴 0📅 2026年1月21日
SKILL.md
name: python-best-practices description: Python >=3.11 performance optimization guidelines. This skill should be used when writing, reviewing, or refactoring Python code to ensure optimal performance patterns. Triggers on tasks involving asyncio, data structures, memory management, serialization, concurrency, or Python performance optimization.
Python Community Python >=3.11 Best Practices
Comprehensive performance optimization guide for Python >=3.11 applications. Contains 45 rules across 9 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new Python async/await code
- Processing large datasets or files
- Implementing caching and memoization
- Choosing data structures for performance
- Reviewing code for performance issues
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | I/O Patterns | CRITICAL | io- |
| 2 | Async Concurrency | CRITICAL | async- |
| 3 | Memory Management | HIGH | mem- |
| 4 | Data Structures | HIGH | ds- |
| 5 | Algorithm Efficiency | MEDIUM-HIGH | algo- |
| 6 | Concurrency Model | MEDIUM | conc- |
| 7 | Serialization | MEDIUM | serial- |
| 8 | Caching and Memoization | LOW-MEDIUM | cache- |
| 9 | Runtime Tuning | LOW | runtime- |
Quick Reference
1. I/O Patterns (CRITICAL)
io-async-file-operations- Use async file I/O for non-blocking operationsio-batch-database-operations- Batch database operations to reduce round tripsio-connection-pooling- Use connection pooling for database and HTTP clientsio-streaming-large-files- Stream large files instead of loading into memoryio-use-buffered-io- Use buffered I/O for frequent small writes
2. Async Concurrency (CRITICAL)
async-avoid-async-overhead- Avoid async overhead for CPU-bound workasync-avoid-blocking-calls- Avoid blocking calls in async codeasync-create-task-fire-forget- Store references to fire-and-forget tasksasync-gather-independent-operations- Use asyncio.gather() for independent operationsasync-semaphore-rate-limiting- Use semaphores for concurrency limitingasync-taskgroup-structured-concurrency- Use TaskGroup for structured concurrency
3. Memory Management (HIGH)
mem-avoid-intermediate-lists- Avoid intermediate lists in pipelinesmem-generators-lazy-evaluation- Use generators for lazy evaluationmem-preallocate-lists- Preallocate lists when size is knownmem-slots-dataclass- Use slots for memory-efficient classesmem-string-interning- Leverage string interning for repeated stringsmem-weak-references- Use weak references for caches and observers
4. Data Structures (HIGH)
ds-counter-for-counting- Use Counter for frequency countingds-deque-for-queues- Use deque for O(1) queue operationsds-dict-get-default- Use dict.get() with default instead of KeyError handlingds-namedtuple-immutable-records- Use NamedTuple for immutable lightweight recordsds-set-for-membership- Use Set for O(1) membership testing
5. Algorithm Efficiency (MEDIUM-HIGH)
algo-avoid-repeated-computation- Cache expensive computations in loopsalgo-builtin-functions- Use built-in functions over manual implementationalgo-itertools-recipes- Use itertools for efficient iteration patternsalgo-list-comprehension- Use list comprehensions over manual loopsalgo-local-variable-lookup- Use local variables in hot loopsalgo-string-join- Use str.join() for string concatenation
6. Concurrency Model (MEDIUM)
conc-asyncio-queues- Use asyncio.Queue for producer-consumer patternsconc-avoid-lock-contention- Minimize lock contention in threaded codeconc-choose-right-model- Choose the right concurrency modelconc-process-pool-chunking- Use chunking for ProcessPoolExecutorconc-thread-safe-globals- Use thread-safe data structures for shared state
7. Serialization (MEDIUM)
serial-avoid-pickle-security- Avoid pickle for untrusted dataserial-msgpack-binary- Use MessagePack for compact binary serializationserial-orjson-over-json- Use orjson for high-performance JSONserial-pydantic-validation- Use Pydantic for validated deserialization
8. Caching and Memoization (LOW-MEDIUM)
cache-avoid-over-caching- Avoid over-caching low-value operationscache-cached-property- Use cached_property for expensive computed attributescache-lru-cache-decorator- Use lru_cache for expensive pure functionscache-ttl-expiration- Implement TTL for time-sensitive caches
9. Runtime Tuning (LOW)
runtime-avoid-global-lookups- Avoid repeated global and module lookupsruntime-exception-handling-cost- Minimize exception handling in hot pathsruntime-profile-before-optimizing- Profile before optimizingruntime-use-python311-plus- Upgrade to Python 3.11+ for free performance
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Reference Files
| File | Description |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です