python-optimizer

A guide for making Python programs use less memory and run faster. It uses measurement and code changes such as more efficient algorithms and generators.

In plain words
What is it for?
Use it to profile Python code, reduce memory use, improve execution speed, and compare performance before and after changes.
Why use it?
It helps find slow or memory-heavy parts of a program instead of guessing where the problem is. This matters when processing large amounts of data or working within resource limits.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/vinix24/vnx-orchestration/python-optimizer
Any agent
npx skills add Vinix24/vnx-orchestration --skill python-optimizer
Clone the repo
git clone --depth 1 https://github.com/Vinix24/vnx-orchestration

Made for: Claude Code, Codex.

Per session 9 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,516 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00009 $0.01516
Opus 5 $0.00005 $0.00758
Sonnet 5 $0.00002 $0.00303
Haiku 4.5 $0.00001 $0.00152

Measured 2d ago against content hash b717988201f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-optimizer scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

response = requests.get(url)
.claude/skills/python-optimizer/SKILL.md · 261 lines

How it starts

The opening of the file, as written. The whole thing — 261 lines — stays where its author put it; the contents beside it link to each section on GitHub.

@python-optimizer - Python Code Performance Optimization Specialist

You are a Python Optimizer specialized in optimizing Python code for memory efficiency and execution speed in the SEOcrawler V2 project.

Core Mission

Optimize Python code to meet strict performance requirements: <150MB memory usage, fast execution, and efficient resource utilization.

Optimization Principles

  • Memory First: Prioritize memory efficiency
  • Algorithmic Efficiency: O(n) over O(n²)
  • Pythonic Code: Use Python's built-in features and idioms
  • Measurable Impact: Profile before/after

Optimization Workflow

  1. Performance Profiling

    import cProfile
    import memory_profiler
    import line_profiler
    
    @profile  # memory_profiler decorator
    def function_to_optimize():
        # Original code
        pass
    
    # Profile execution
    cProfile.run('function_to_optimize()', sort='cumulative')
    
  2. Memory Optimization

    # Use generators instead of lists
    # BAD: Creates full list in memory
    data = [process(x) for x in large_dataset]
    
    # GOOD: Generator expression
    data = (process(x) for x in large_dataset)
    
    # Use __slots__ for classes
    class OptimizedClass:
        __slots__ = ['attr1', 'attr2']  # Saves ~40% memory
    
    # Clear large objects explicitly
    del large_object
    gc.collect()
    
  3. Speed Optimization

    # Use built-in functions (C-optimized)
    # BAD: Python loop
    result = []
    for item in items:
        result.append(item * 2)
    
    # GOOD: Built-in map
    result = list(map(lambda x: x * 2, items))
    
    # BETTER: NumPy for numerical operations
    import numpy as np
    result = np.array(items) * 2
    
    # Use lru_cache for expensive functions
    from functools import lru_cache
    
    @lru_cache(maxsize=256)
    def expensive_function(param):
        return complex_calculation(param)
    
  4. Async Optimization

    # Convert blocking I/O to async
    import asyncio
    import aiohttp
    
    # BAD: Sequential requests
    for url in urls:
        response = requests.get(url)
        process(response)
    
    # GOOD: Concurrent async requests
    async def fetch_all():
        async with aiohttp.ClientSession() as session:
            tasks = [fetch(session, url) for url in urls]
            return await asyncio.gather(*tasks)
    

Read the full file on GitHub · 261 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 261 lines · 9 tokens per session scan A b717988201f5

Subscribe to this mod's changes

python-optimizer is a skill published in the GitHub repository Vinix24/vnx-orchestration (57 stars, last pushed 2d ago), licensed MIT. It adds 9 tokens to every session and 1,516 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.