Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

parseltongue

Modern Python development suite for testing, performance, async patterns, and packaging.

Overview

Parseltongue brings Python 3.12+ best practices to your workflow. It covers the full development lifecycle: testing with pytest, performance optimization, async patterns, and modern packaging with uv.

Installation

/plugin install parseltongue@claude-night-market

Skills

SkillDescriptionWhen to Use
python-testingPytest and TDD workflowsWriting and running tests
python-performanceProfiling and optimizationDebugging slow code
python-asyncAsync programming patternsImplementing asyncio
python-packagingModern packaging with uvManaging pyproject.toml

Commands

CommandDescription
/analyze-testsReport on test suite health
/run-profilerProfile code execution
/check-asyncValidate async patterns

Agents

AgentDescription
python-proMaster Python 3.12+ with modern features
python-testerExpert testing for pytest, TDD, mocking
python-optimizerExpert performance optimization

Usage Examples

Test Analysis

/analyze-tests

# Reports:
# - Coverage metrics
# - Test distribution
# - Slow tests
# - Missing coverage areas
# - Anti-patterns detected

Profiling

/run-profiler src/heavy_function.py

# Outputs:
# - CPU time breakdown
# - Memory usage
# - Hot paths
# - Optimization suggestions

Async Validation

/check-async src/async_module.py

# Checks:
# - Proper await usage
# - Event loop handling
# - Async context managers
# - Concurrency patterns

Skill Invocation

Skill(parseltongue:python-testing)

# Provides:
# - Pytest configuration patterns
# - TDD workflow guidance
# - Mocking strategies
# - Fixture patterns

Python 3.12+ Features

Parseltongue emphasizes modern Python:

Type Hints

# Modern syntax (3.10+)
def process(data: list[str] | None) -> dict[str, int]:
    ...

Pattern Matching

# Structural pattern matching (3.10+)
match response:
    case {"status": "ok", "data": data}:
        return data
    case {"status": "error", "message": msg}:
        raise ValueError(msg)

Exception Groups

# Exception groups (3.11+)
try:
    async with asyncio.TaskGroup() as tg:
        tg.create_task(task1())
        tg.create_task(task2())
except* ValueError as eg:
    for exc in eg.exceptions:
        handle(exc)

Testing Patterns

TDD Workflow

Skill(parseltongue:python-testing)

# RED-GREEN-REFACTOR:
# 1. Write failing test
# 2. Implement minimal code
# 3. Refactor with tests green

Fixture Patterns

# Recommended patterns
@pytest.fixture
def db_session(tmp_path):
    """Session-scoped database fixture."""
    db = Database(tmp_path / "test.db")
    yield db
    db.close()

@pytest.fixture
def user(db_session):
    """User fixture depending on db."""
    return db_session.create_user("test")

Mocking Strategies

# Strategic mocking
def test_api_call(mocker):
    mock_response = mocker.patch("requests.get")
    mock_response.return_value.json.return_value = {"status": "ok"}

    result = fetch_data()

    assert result["status"] == "ok"

Performance Optimization

Profiling Tools

# cProfile integration
python -m cProfile -s cumtime script.py

# Memory profiling
from memory_profiler import profile

@profile
def memory_heavy():
    ...

Optimization Patterns

  • Generators over lists: Save memory
  • Local variables: Faster lookup
  • Built-in functions: C-optimized
  • Lazy evaluation: Defer computation

Async Patterns

async def main():
    async with aiohttp.ClientSession() as session:
        tasks = [fetch(session, url) for url in urls]
        results = await asyncio.gather(*tasks)
    return results

if __name__ == "__main__":
    asyncio.run(main())

Anti-Patterns to Avoid

  • Blocking calls in async functions
  • Creating event loops inside coroutines
  • Ignoring exceptions in fire-and-forget tasks

Packaging with uv

pyproject.toml

[project]
name = "my-package"
version = "1.0.0"
dependencies = ["requests>=2.28"]

[project.optional-dependencies]
dev = ["pytest", "ruff", "mypy"]

[tool.uv]
index-url = "https://pypi.org/simple"

Commands

# Install with uv
uv pip install -e ".[dev]"

# Lock dependencies
uv pip compile pyproject.toml -o requirements.lock

# Sync environment
uv pip sync requirements.lock

Superpowers Integration

SkillEnhancement
python-testingUses test-driven-development for TDD cycles
python-testingUses testing-anti-patterns for detection
  • leyline: Provides pytest-config patterns
  • sanctum: Test updates integrate with test-updates skill