Python is the language most people call Claude from, and the one where "just use the SDK" is said most often, so it gets two rows on the leaderboard. One is a client in a single file on http.client and json, nothing installed. The other is the official anthropic package, written exactly the way its documentation says. Same spec, same harness, same interpreter. The gap between them is the cost of the SDK, isolated from the cost of Python.
The code for both is at github.com/AndyCross/claude-hot-path, under python and python-sdk.
The standard library client
http.client is the module urllib is built on, and it is the right level for this: open a connection, send a request, get a response object that is also a buffered reader. Iterating the response yields a line at a time as the bytes arrive, which is the entire SSE transport:
conn.request("POST", "/v1/messages", json.dumps(body), {
"x-api-key": key, "anthropic-version": VERSION, "content-type": "application/json",
})
resp = conn.getresponse()
...
for raw in resp:
if not raw.startswith(b"data: "):
continue # event:, ping, blank separators
ev = json.loads(raw[6:])
index = ev.get("index", 0)
kind = ev["type"]
if kind == "content_block_start":
content.append(ev["content_block"])
partial.append([])
elif kind == "content_block_delta":
delta = ev["delta"]
if delta["type"] == "text_delta":
out.write(delta["text"])
out.flush()
content[index]["text"] = content[index].get("text", "") + delta["text"]
elif delta["type"] == "input_json_delta":
partial[index].append(delta["partial_json"])
elif kind == "content_block_stop":
if content[index]["type"] == "tool_use" and partial[index]:
content[index]["input"] = json.loads("".join(partial[index]))
elif kind == "message_delta":
stop = ev["delta"].get("stop_reason")
Ninety lines, and it reads almost exactly like the Go and Rust versions, because the protocol is the same six events whatever you write it in. The one connection is reused for the second turn, the events decode straight into dicts that are echoed back as the assistant message, and zoneinfo from the standard library does the timezone lookup, which is the same database Go reads and Rust and Zig parse by hand. Python has had it in the box since 3.9.
The out.flush() after each delta is there for the same reason as in every other client. Python buffers stdout when it is not a terminal, and without the flush the words would arrive at the end in one piece. The harness checks for that and fails it.
The SDK client
with client.messages.stream(model=MODEL, max_tokens=1024, tools=TOOLS, messages=messages) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
response = stream.get_final_message()
That is the whole stream in the SDK version, and it is lovely. Fifty-five lines for the complete client, the shortest on the board, and the tool loop is the one from the SDK's own documentation: check stop_reason, collect the tool_use blocks, append the assistant turn and a user turn of tool_result blocks, go round again. The SDK reads ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL from the environment on its own, retries on its own (switched off here so the error test is a fair one), and types every block.
What they measure as
| Python, standard library | Python SDK | Rust, for scale | |
|---|---|---|---|
| On the path, median of 100 | 140.4 ms | 592.5 ms | 3.2 ms |
| Cold start | 123.8 ms | 464.6 ms | 1.1 ms |
| Turnaround | 1.9 ms | 8.7 ms | 0.7 ms |
| Tail after the last reply | 15.2 ms | 119.8 ms | 1.3 ms |
| Peak RSS | 21 MB | 84 MB | 3 MB |
| Runtime shipped | 35.5 MB | 71.9 MB | 2.0 MB |
| Lines of code | 90 | 55 | 184 |
Python 3.14.8 and anthropic 1.15.0, linux/arm64, Apple M4 Max under Docker.
Read the cold start column first. The standard library client spends 124 ms before its first byte goes out, and that is the interpreter starting plus the imports of http.client, json, datetime and zoneinfo. The SDK client spends 465 ms, and the extra 340 ms is import anthropic: pydantic, httpx, anyio, the generated type modules for every request and response shape in the API. The SDK ships with sixteen packages in site-packages and loads most of them before it has sent anything.
Then the tail. After the last byte of the answer has been printed, the standard library client takes 15 ms to exit and the SDK client takes 120 ms. That is the HTTP client's connection pool closing down and the interpreter tearing down everything the import built. Nobody waits for it in a terminal, and a Lambda is billed for it.
Between those two numbers, while the stream is actually flowing, the SDK is good. Its turnaround of 8.7 ms is slower than the standard library's 1.9 ms, because each event passes through pydantic on the way to you, but both are a rounding error against the 1.5 seconds the model takes to answer.
So the honest split is this. Python costs you 140 ms per process, and the SDK costs you another 450 ms on top. If your process lives for an hour and makes a thousand calls, neither number matters and you should use the SDK, because it is fifty-five lines and it is typed. If your process lives for one call, a CLI, a Lambda, a hook, the SDK is costing you half a second you can see, and ninety lines of standard library gets most of it back.
How to run it
git clone https://github.com/AndyCross/claude-hot-path
cd claude-hot-path
./bench/bench.sh python
./bench/bench.sh python-sdk
Docker and Python 3, no key. The SDK row is marked as a baseline on the leaderboard and sorts below the hand-written clients, because it is the thing they are measured against rather than one of them. The TypeScript SDK gets the same treatment, next.
First published on stepinto.dev.
Top comments (1)
340 ms just to
import anthropicis the number that stuck with me — our total article views went from 1,189 at the Nov 19 baseline to 2,142 by Dec 2, mostly on posts that led with one measured number like that.