SwiftRelay

← All sprint notes

Pair Programming a Python Pipeline with Claude Code

Agent quick startsEN

Pair programming with Claude Code works best when you keep ownership of the data rules and give your coding partner bounded implementation tasks. This walkthrough builds a local pipeline that reads order CSV files, validates records, and writes daily revenue totals. Use synthetic fixtures throughout; keep production data and credentials outside the session.

1. Prepare a Safe Python Pipeline Workspace

Create a Git branch with git switch -c pipeline/daily-revenue. Use your repository's existing Python environment and dependency tooling. For a new project, ask for a minimal package containing pipeline.py, tests/test_pipeline.py, and tests/fixtures/orders.csv. Keep generated output in a separate directory.

Claude Code can inspect repository files, edit code, and execute commands. Begin by asking it to explain the current project layout without making changes. Review command permissions before allowing execution, particularly anything involving deletion or external services. ([support.claude.com](https://support.claude.com/en/articles/14553517-claude-code-common-developer-use-cases))

2. Connect Claude Code Through SwiftRelay

If you want pay-as-you-go access for this workflow, SwiftRelay works with Claude Code and bills per token. Configure the client using SwiftRelay's connection instructions, keeping credentials outside tracked files. Use the bare API host for Claude Code, rather than adding the /v1 suffix used by OpenAI-compatible SDKs.

Claude Code supports compatible third-party gateways, but gateway compatibility is not an endorsement from Anthropic. Check your organization's data-handling requirements before routing repository context through another service. ([docs.anthropic.com](https://docs.anthropic.com/en/docs/claude-code/llm-gateway))

Sign up for SwiftRelay to try the walkthrough with the small gift credit available to new accounts.

3. Define the Order Data Contract Before Coding

Give Claude a concrete specification: “Read CSV columns order_id, ordered_at, currency, and amount. Accept only USD. Require unique, nonempty order identifiers, timezone-aware timestamps, and nonnegative amounts with at most two decimal places. Aggregate by UTC date. Reject the entire file if any record is invalid.”

Specify the output columns as date, currency, and revenue, sorted by date. Require decimal arithmetic, explicit error messages, and no silent row dropping. Treat refunds as unsupported for this first version rather than letting Claude invent their accounting treatment.

Put lasting rules and test commands in CLAUDE.md, which Claude reads at the start of a conversation. Keep task-specific examples in the current prompt. ([code.claude.com](https://code.claude.com/docs/en/best-practices))

4. Ask Claude to Plan a Small Implementation

Use this prompt: “Propose functions for reading, validation, aggregation, and writing. Keep transformation logic separate from file access. Use the Python standard library for runtime code. Do not edit files until I approve the plan.”

Separating exploration and planning from implementation follows Anthropic's recommended workflow for changes spanning multiple files. Approve a narrow plan, not an unrelated architecture rewrite. ([code.claude.com](https://code.claude.com/docs/en/best-practices))

Agree on a command interface such as python -m pipeline --input tests/fixtures/orders.csv --output output/daily.csv. Ask for actionable errors containing the source row number, without printing entire records.

5. Write Fixture Tests Before Implementing Transformations

Ask Claude to write tests first, run them, and show the expected failures before implementing the pipeline. Anthropic recommends giving Claude executable checks so it can verify changes rather than merely assert completion. ([code.claude.com](https://code.claude.com/docs/en/best-practices))

  • Combine two USD orders on the same UTC date and verify the exact total.
  • Reject duplicate identifiers, missing columns, invalid amounts, and unsupported currencies.
  • Check that a timestamp with an offset lands on the correct UTC date.
  • Verify that invalid input leaves an existing output file unchanged.

Use hand-calculated expectations. Do not generate expected totals with the same aggregation function under test.

6. Implement, Inspect, and Exercise the Pipeline

Approve implementation, then ask Claude to run python -m pytest tests/test_pipeline.py -q. Review the patch yourself: check decimal parsing, timestamp conversion, duplicate handling, and output ordering. Require validation to finish before publishing output, with temporary-file cleanup on failure.

Run the agreed command against the fixture and inspect the resulting CSV. Repeat the run and confirm it replaces the destination deterministically rather than appending duplicate totals. Introduce one malformed record and verify the failure message and unchanged destination.

7. Commit the Pipeline With Reproducible Evidence

Ask Claude for a handoff listing changed files, commands actually executed, test results, and remaining assumptions. Inspect git diff and git status before committing. Include fixture data and usage instructions, but exclude credentials and generated output. Your deliverable is a reviewable pipeline with explicit rules and repeatable checks—not simply code that looks plausible.

Keep reading

Back for another lap?Log in