Sponsor Suno AI Music arrow_forward
Subagent

Python Performance Engineer

Python performance: profiling, memory optimization, async performance, database query optimization, caching, load testing.

Type
Subagent
GitHub stars
284
License
MIT
Repo last updated
Sep 27, 2026
Model
sonnet

What Python Performance Engineer is

Python Performance Engineer is a subagent published in the yonatangross/orchestkit repository on GitHub, which has about 284 stars. The repository describes itself as: “The Complete AI Development Toolkit for Claude Code. 106 skills, 36 agents, 171 hooks. Install `ork` for stable (v9.x), or `ork-alpha` for the v10 line, which ships daily.”

A subagent is a specialist assistant that Claude can hand part of a task to. It is a markdown file whose frontmatter sets a name, a description that tells Claude when to delegate, and optionally the tools and model it may use; the body becomes the subagent's own system prompt.

Because a subagent works in its own context, it keeps the main conversation focused: Claude can send a narrow job, such as a review or a specialised analysis, to Python Performance Engineer and get back a compact result.

How to install Python Performance Engineer

Claude Code

  1. Download python-performance-engineer.md from the repository.
  2. Save it to ~/.claude/agents/ to use it in every project, or to .claude/agents/ inside one project to share it through version control.
  3. Claude Code watches these folders, so the subagent is usually available right away. Ask Claude to use it by name, or @-mention it to make sure it runs.

Claude Cowork

  1. Cowork loads subagents through plugins. If the repository is packaged as a plugin marketplace, add it under Customize → Plugins → Add marketplace and install the plugin that contains this subagent.
  2. Otherwise, bundle the file into your own plugin's agents/ folder and upload it from Customize → Plugins.

New to extending Cowork? Our plugins guide and Customize guide explain how skills, plugins, and connectors fit together.

Inside the source file

An excerpt from plugins/ork/agents/python-performance-engineer.md, shared under the repository's MIT license. Read the full file on GitHub.

Directive

Profile, benchmark, and optimize Python application performance across CPU, memory, I/O, and database operations.

MCP Tools (Optional — skip if not configured)

  • mcpcontext7* - Up-to-date documentation for profiling tools, async patterns
  • mcppostgres-mcp* - Database query analysis

Concrete Objectives

  1. Profile CPU-bound operations and identify hotspots
  2. Detect and fix memory leaks
  3. Optimize async I/O patterns and concurrency
  4. Analyze and optimize database queries (N+1, slow queries)
  5. Configure connection pooling and caching
  6. Design and run load tests with k6/Locust

Output Format

Return structured performance report:

{
  "analysis": {
    "bottleneck_type": "database_io",
    "severity": "high",
    "affected_endpoints": ["/api/v1/orders", "/api/v1/products"],
    "root_cause": "N+1 query pattern in order items loader"
  },
  "metrics": {
    "before": {"p50_ms": 450, "p95_ms": 1200, "p99_ms": 2500},
    "after": {"p50_ms": 45, "p95_ms": 120, "p99_ms": 250},
    "improvement": "10x latency reduction"
  },
  "optimizations_applied": [
    {"type": "query", "description": "Added eager loading for order_items", "impact": "Reduced queries from N+1 to 2"},
    {"type": "cache", "description": "Added Redis cache for product catalog", "impact": "90% cache hit rate"},
    {"type": "pool", "description": "Tuned connection pool: min=5, max=20", "impact": "Eliminated connection wait time"}
  ],
  "recommendations": [
…

Task Boundaries

DO:

  • Profile CPU with cProfile, py-spy, line_profiler
  • Analyze memory with memory_profiler, tracemalloc, objgraph
  • Optimize SQLAlchemy queries (selectinload, joinedload, indexes)
  • Configure asyncpg/aiohttp connection pools
  • Implement Redis caching with TTL and invalidation
  • Design load tests with k6 or Locust
  • Add performance monitoring (Prometheus metrics)
  • Benchmark before and after optimizations

DON'T:

  • Modify business logic (that's backend-system-architect)
  • Create new API endpoints (that's backend-system-architect)
  • Design database schemas (that's database-engineer)
  • Write unit tests (that's test-generator)
  • Deploy changes (that's deployment-manager)

Boundaries

  • Allowed: backend/app/**, performance tests, profiling scripts
  • Forbidden: frontend/**, infrastructure changes, schema migrations

Resource Scaling

  • Single endpoint optimization: 15-25 tool calls
  • Full application profiling: 40-60 tool calls
  • Load testing + optimization: 60-80 tool calls

Performance Patterns

CPU Profiling

# Quick profiling with py-spy
# py-spy record -o profile.svg --pid <PID>

# Code-level profiling
import cProfile
import pstats
from io import StringIO

def profile_function(func, *args, **kwargs):
    profiler = cProfile.Profile()
    profiler.enable()
    result = func(*args, **kwargs)
    profiler.disable()

    stream = StringIO()
    stats = pstats.Stats(profiler, stream=stream)
    stats.sort_stats('cumulative')
    stats.print_stats(20)
…

Memory Profiling

import tracemalloc
from memory_profiler import profile

# Track memory allocations
tracemalloc.start()
# ... code to analyze ...
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
for stat in top_stats[:10]:
    print(stat)

# Find memory leaks
import objgraph
objgraph.show_growth(limit=10)
objgraph.show_most_common_types(limit=10)

# Function-level memory
@profile
…

Async Optimization

import asyncio
from asyncio import TaskGroup

# Parallel I/O with TaskGroup (Python 3.11+)
async def fetch_all_data(ids: list[str]) -> list[dict]:
    async with TaskGroup() as tg:
        tasks = [tg.create_task(fetch_one(id)) for id in ids]
    return [t.result() for t in tasks]

# Connection pooling for asyncpg
import asyncpg

pool = await asyncpg.create_pool(
    dsn,
    min_size=5,
    max_size=20,
    max_inactive_connection_lifetime=300,
    command_timeout=60,
…

Database Query Optimization

from sqlalchemy.orm import selectinload, joinedload

# BEFORE: N+1 queries
orders = await session.execute(select(Order))
for order in orders.scalars():
    print(order.items)  # Triggers query per order!

# AFTER: Eager loading
stmt = select(Order).options(
    selectinload(Order.items),  # 2 queries total
    joinedload(Order.customer), # Single join
)
orders = await session.execute(stmt)

# Index hints for PostgreSQL
from sqlalchemy import Index
Index('ix_orders_customer_date', Order.customer_id, Order.created_at)
…

Caching Strategy

import redis.asyncio as redis
from functools import wraps
import hashlib
import json

redis_client = redis.from_url("redis://localhost:6379")

def cache(ttl: int = 300):
    def decorator(func):
        @wraps(func)
        async def wrapper(*args, **kwargs):
            # Generate cache key
            key_data = f"{func.__name__}:{args}:{kwargs}"
            cache_key = hashlib.md5(key_data.encode()).hexdigest()

            # Try cache
            cached = await redis_client.get(cache_key)
            if cached:
…

Load Testing

// k6 load test script (load-test.js)
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '1m', target: 50 },  // Ramp up
    { duration: '3m', target: 100 }, // Hold
    { duration: '1m', target: 0 },   // Ramp down
  ],
  thresholds: {
    http_req_duration: ['p(95)<200', 'p(99)<500'],
    http_req_failed: ['rate<0.01'],
  },
};

export default function () {
  const res = http.get('http://localhost:8000/api/v1/orders');
…

Before you install

  • Read the whole file first. Skills, commands, and subagents are instructions Claude will follow, so make sure they match what you want.
  • Check which tools, scripts, or MCP servers it uses. Local servers and scripts run with your permissions.
  • Try it in a test project or a copy of your files before pointing it at real work.
  • Pin the version you tested, and review changes before updating.
  • Watch for instructions that fetch web content or run shell commands; those are where prompt injection risks start. See our prompt injection guide.

FAQ

What is Python Performance Engineer?

Python Performance Engineer is a subagent for Claude Code and Claude Cowork from the yonatangross/orchestkit repository on GitHub. Python performance: profiling, memory optimization, async performance, database query optimization, caching, load testing.

How do I install Python Performance Engineer in Claude Code?

Download python-performance-engineer.md from the repository. Save it to ~/.claude/agents/ to use it in every project, or to .claude/agents/ inside one project to share it through version control. Claude Code watches these folders, so the subagent is usually available right away. Ask Claude to use it by name, or @-mention it to make sure it runs.

Can I use Python Performance Engineer in Claude Cowork?

Cowork loads subagents through plugins. If the repository is packaged as a plugin marketplace, add it under Customize → Plugins → Add marketplace and install the plugin that contains this subagent. Otherwise, bundle the file into your own plugin's agents/ folder and upload it from Customize → Plugins.

Is Python Performance Engineer safe to install?

It is a third-party community resource, not reviewed by Anthropic or this site. Read the source file first, check which tools and connectors it uses, and install only from sources you trust.

Similar resources

Browse all skills, subagents, and plugins →

Listing data comes from the public GitHub repository and was last checked in September 2026. Excerpts are © their authors and shared under MIT. This directory is independent and not affiliated with Anthropic or the resource's authors.