I Rewrote a 200-Line Python Script in Rust (Was It Worth It?)

Honest post-mortem: speed, DX, and the moment I missed dicts more than I expected.

I Rewrote a 200-Line Python Script in Rust (Was It Worth It?)

The script parsed gzipped log files, aggregated counts, and spat out CSV. Python handled it fine until someone dropped a 50 GB archive on a shared drive and asked for “by lunchtime.”

Rust wasn’t mandatory. Curiosity was.

What got better immediately

Runtime. The Rust version streamed lines without loading whole files into memory. Same laptop, same disk — wall clock went from “go get lunch” to “wait, it’s done?”

Single binary. No “which venv” emails. Ship one artifact, run it.

What hurt (real talk)

Iteration speed. Changing a data structure in Python is a conversation with the REPL. In Rust, the compiler is the strict friend who says “no” until you mean it.

I missed throwing dicts everywhere for intermediate shapes. Serde and structs are great when you know the shape; exploratory parsing felt heavier.

Tiny example: counting by hour

Python (the gist):

from collections import Counter
# ... read lines, parse timestamp, counter[hour] += 1

Rust (conceptually):

// HashMap<u8, u64> for hour -> count, parse with chrono, bump in loop

The Rust wasn’t shorter. It was obvious what could panic vs what couldn’t — once it compiled.

Laptop showing code on screen
Compiler green isn’t happiness; it’s the absence of a whole class of Friday surprises.

Verdict

Worth it for this job — heavy IO, predictable schema, needs to run on a server without Python installed.

Not worth it for one-off glue I’ll delete next week. Rust shines when the problem is boring and the stakes are “we run this every night.”

Packaging and deploy

cargo build --release gave us a binary we could drop on a VM without installing a runtime. CI cached dependencies after the first slow build. Document the glibc version you linked against if you move machines — “works on my laptop” dies quietly in prod.

Testing strategy

Unit tests for parsing edge cases; a golden file test for “this sample log produces this CSV.” Rust’s test runner is nothing fancy, but fast tests meant I actually ran them before each tweak.

When I’d pick Go instead

If the team already standardizes on Go, or if compile times for our crate graph grew painful, I’d be honest about switching horses. Rust isn’t magic — it’s a trade I liked for this workload.


I still write Python most days. Rust is the tool I reach for when “fast enough” stopped being true.