Skip to content
Back to skills

Coding

ASecurity

Speed up Python services: async I/O, FastAPI and Pydantic v2, connection pooling, memory use, profiling with py-spy and load tests. Use when a Python service is slow, blocks the event loop or uses too much memory.

  • 24 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added October 14, 2026
ai-agentspythonrustgosqlfastapitestingapidatabaseperformance

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned November 22, 2026

npx -y skills add andreibesleaga/GABBE --skill coding --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Coding?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Coding
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/andreibesleaga-coding-f4edc2e5/badge)](https://www.skillsdirectory.com/skills/andreibesleaga-coding-f4edc2e5)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: performant-python
description: "Speed up Python services: async I/O, FastAPI and Pydantic v2, connection pooling, memory use, profiling with py-spy and load tests. Use when a Python service is slow, blocks the event loop or uses too much memory."
triggers: [python, fastapi, performance, asyncio, uvloop, pydantic, scalability, profiling]
tags: [coding, python, architecture]
context_cost: medium
---
# Performant Python Skill

## Goal
Building high-concurrency, low-latency Python services by leveraging asynchronous patterns, optimized runtimes, and efficient memory management.

## Capabilities

### 1. Asynchronous Mastery (Asyncio & FastAPI)
- **Non-blocking I/O**: Use `async`/`await` for all network and disk I/O. Use `run_in_executor` for CPU-bound tasks to avoid blocking the event loop.
- **Event Loop Tuning**: Use `uvloop` as the drop-in replacement for the default asyncio loop for significant speedups.
- **Concurrent Execution**: Use `asyncio.gather()` or `asyncio.TaskGroup` (Python 3.11+) for parallel I/O operations.

### 2. Database & Data Handling
- **Async Drivers**: Use `asyncpg` for PostgreSQL or `aiomysql`. Use SQLAlchemy/Tortoise with async support.
- **Serialization**: Use `ORJSONResponse` or `UJSONResponse` in FastAPI for faster JSON encoding/decoding.
- **Efficient Models**: Use Pydantic v2 for its Rust-based speed. Use `.model_dump(include={...})` to minimize data transfer.

### 3. Memory & Resource Optimization
- **Slot Classes**: Use `__slots__` in frequently instantiated classes to reduce memory footprint and increase attribute access speed.
- **Generator Patterns**: Use `generators` and `yield` for processing large datasets to keep memory usage constant (O(1)).
- **Garbage Collection**: Tune `gc` thresholds if necessary, but prioritize object reuse to minimize pressure.

### 4. Deployment & Performance Runtimes
- **Process Management**: Use Gunicorn with `UvicornWorker` to scale across CPU cores.
- **Connection Pooling**: Always implement pooling for DB and HTTP clients (e.g., `httpx` instead of `requests`).
- **Middleware Overhead**: Audit and minimize middleware; each layer adds latency to every request.

### 5. Profiling & Monitoring
- **Deterministic Profiling**: Use `cProfile` for code path analysis.
- **Sampling Profiling**: Use `Py-Spy` or `Scalene` for production-safe, low-overhead profiling.
- **APM**: Integrate with Prometheus/Grafana or Datadog for real-time latency and throughput tracking.

## Steps
1. **Identify Blockers**: Use `Py-Spy` to find the hot paths in a running process.
2. **Async Audit**: Ensure no synchronous libraries (like `requests` or standard `psycopg2`) are used in an async context.
3. **Pydantic Check**: Upgrade to V2 and optimize model validation constraints.
4. **Benchmark**: Use `Locust` or `k6` to verify speed improvements under load.

## Output Format
- `ARCHITECTURE_REVIEW_TEMPLATE.md`: Analysis of blocking calls and memory architecture.
- `SCALABILITY_ANALYSIS_TEMPLATE.md`: Roadmap for converting sync logic to async.
- `BENCHMARK_REPORT_TEMPLATE.md`: Response time comparisons (Before/After load testing).

## Constraints
- Measure with a load test (`Locust` or `k6`) before and after each change.
- No synchronous libraries (`requests`, `psycopg2`) inside async code.

## Limits and safety
- Pass every value in raw SQL through query parameters, also with async drivers.
- Do not block the event loop (`time.sleep()`, heavy computation); guard shared state with `asyncio.Lock` or avoid it.
- Attach a sampling profiler such as `py-spy` to a production process only with the human's go-ahead.
- Check the project's Python version before using newer features (`asyncio.TaskGroup` needs 3.11).
- Use `cython` or `numba` only when profiling shows the pure Python path is still too slow.

Files in this skill

  • agent-trajectory-eval.skill.md5.7 KB
  • artisan-commands.skill.md3.7 KB
  • browser-tdd.skill.md7 KB
  • chaos-fault-injection.skill.md8.1 KB
  • ci-autofix.skill.md4.2 KB
  • clean-coder.skill.md4.5 KB
  • code-review.skill.md6.1 KB
  • debug.skill.md6.5 KB
  • documentation.skill.md7.3 KB
  • eval-driven-development.skill.md6.9 KB
  • evals/code-review.eval.yaml1 KB
  • excalidraw.skill.md3.7 KB
  • file-processing.skill.md4.3 KB
  • git-workflow.skill.md7.2 KB
  • metamorphic-testing.skill.md7.8 KB
  • mobile-dev.skill.md4.2 KB
  • nodejs-expert.skill.md1.6 KB
  • output-validation.skill.md5.4 KB
  • pbt-strategy.skill.md8 KB
  • performant-ai.skill.md3.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.