Python
Skill ComeOnOliver/skillshub/skills/pproenca/dot-skills/python
π§ The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.From the repository description
npx -y skills add ComeOnOliver/skillshub --skill pythonAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
7.9 KB, ~2.2k tokens by cl100k_base, as published. Nobody here has run it
Python 3.11 Best Practices
Comprehensive performance optimization guide for Python 3.11+ applications. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new Python async I/O code
- Choosing data structures for collections
- Optimizing memory usage in data-intensive applications
- Implementing concurrent or parallel processing
- Reviewing Python code for performance issues
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | I/O & Async Patterns | CRITICAL | io- |
| 2 | Data Structure Selection | CRITICAL | ds- |
| 3 | Memory Optimization | HIGH | mem- |
| 4 | Concurrency & Parallelism | HIGH | conc- |
| 5 | Loop & Iteration | MEDIUM | loop- |
| 6 | String Operations | MEDIUM | str- |
| 7 | Function & Call Overhead | LOW-MEDIUM | func- |
| 8 | Python Idioms & Micro | LOW | py- |
Table of Contents
-
I/O & Async Patterns β CRITICAL
- 1.1 Defer await Until Value Needed β CRITICAL (2-5Γ faster for dependent operations)
- 1.2 Use aiofiles for Async File Operations β CRITICAL (prevents event loop blocking)
- 1.3 Use asyncio.gather() for Concurrent I/O β CRITICAL (2-10Γ throughput improvement)
- 1.4 Use Connection Pooling for Database Access β CRITICAL (100-200ms saved per connection)
- 1.5 Use Semaphores to Limit Concurrent Operations β CRITICAL (prevents resource exhaustion)
- 1.6 Use uvloop for Faster Event Loop β CRITICAL (2-4Γ faster async I/O)
-
Data Structure Selection β CRITICAL
- 2.1 Use bisect for O(log n) Sorted List Operations β CRITICAL (O(n) to O(log n) search)
- 2.2 Use defaultdict to Avoid Key Existence Checks β CRITICAL (eliminates redundant lookups)
- 2.3 Use deque for O(1) Queue Operations β CRITICAL (O(n) to O(1) for popleft)
- 2.4 Use Dict for O(1) Key-Value Lookup β CRITICAL (O(n) to O(1) lookup)
- 2.5 Use frozenset for Hashable Set Keys β CRITICAL (enables set-of-sets patterns)
- 2.6 Use Set for O(1) Membership Testing β CRITICAL (O(n) to O(1) lookup)
-
Memory Optimization β HIGH
- 3.1 Intern Repeated Strings to Save Memory β HIGH (reduces duplicate string storage)
- 3.2 Use slots for Memory-Efficient Classes β HIGH (20-50% memory reduction per instance)
- 3.3 Use array.array for Homogeneous Numeric Data β HIGH (4-8Γ memory reduction for numbers)
- 3.4 Use Generators for Large Sequences β HIGH (100-1000Γ memory reduction)
- 3.5 Use weakref for Caches to Prevent Memory Leaks β HIGH (prevents unbounded cache growth)
-
Concurrency & Parallelism β HIGH
- 4.1 Use asyncio for I/O-Bound Concurrency β HIGH (300% throughput improvement for I/O)
- 4.2 Use multiprocessing for CPU-Bound Parallelism β HIGH (4-8Γ speedup on multi-core systems)
- 4.3 Use Queue for Thread-Safe Communication β HIGH (prevents race conditions)
- 4.4 Use TaskGroup for Structured Concurrency β HIGH (prevents resource leaks on failure)
- 4.5 Use ThreadPoolExecutor for Blocking Calls in Async β HIGH (prevents event loop blocking)
-
Loop & Iteration β MEDIUM
- 5.1 Hoist Loop-Invariant Computations β MEDIUM (avoids NΓ redundant work)
- 5.2 Use any() and all() for Boolean Aggregation β MEDIUM (O(n) to O(1) best case)
- 5.3 Use dict.items() for Key-Value Iteration β MEDIUM (single lookup vs double lookup)
- 5.4 Use enumerate() for Index-Value Iteration β MEDIUM (cleaner code, avoids index errors)
- 5.5 Use itertools for Efficient Iteration Patterns β MEDIUM (2-3Γ faster iteration patterns)
- 5.6 Use List Comprehensions Over Explicit Loops β MEDIUM (2-3Γ faster iteration)
-
String Operations β MEDIUM
- 6.1 Use f-strings for Simple String Formatting β MEDIUM (20-30% faster than .format())
- 6.2 Use join() for Multiple String Concatenation β MEDIUM (4Γ faster for 5+ strings)
- 6.3 Use str.startswith() with Tuple for Multiple Prefixes β MEDIUM (single call vs multiple comparisons)
- 6.4 Use str.translate() for Character-Level Replacements β MEDIUM (10Γ faster than chained replace())
-
Function & Call Overhead β LOW-MEDIUM
- 7.1 Reduce Function Calls in Tight Loops β LOW-MEDIUM (100ms savings per 1M iterations)
- 7.2 Use functools.partial for Pre-Filled Arguments β LOW-MEDIUM (50% faster debugging via introspection)
- 7.3 Use Keyword-Only Arguments for API Clarity β LOW-MEDIUM (prevents positional argument errors)
- 7.4 Use lru_cache for Expensive Function Memoization β LOW-MEDIUM (avoids repeated computation)
-
Python Idioms & Micro β LOW
- 8.1 Leverage Zero-Cost Exception Handling β LOW (zero overhead in happy path (Python 3.11+))
- 8.2 Prefer Local Variables Over Global Lookups β LOW (faster name resolution)
- 8.3 Use dataclass for Data-Holding Classes β LOW (reduces boilerplate by 80%)
- 8.4 Use Lazy Imports for Faster Startup β LOW (10-15% faster startup)
- 8.5 Use match Statement for Structural Pattern Matching β LOW (reduces branch complexity)
- 8.6 Use Walrus Operator for Assignment in Expressions β LOW (eliminates redundant computations)
References
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.