django-planet
March 3, 2023

More Batteries Please

in blog Carlton's latest posts
original entry More Batteries Please

I was rueing the lack of an HTTP parser in the Python stdlib, under the hashtag #MoreBatteries. Brett Cannon asked why I thought that belonged.

So…

One of my main companions when learning Python was Doug Hellmann’s Python Module of the Week series which became the Python Standard Library by Example book, and was ultimately updated for Python 3.

I was primarily working in other languages at the time, but was able to smuggle in Python for things like automation scripts, and test harnesses, and who knows what, all without bringing in a single external package. It was very much like the XKCD, import antigravity.

Yesterday, then, I was deeply frustrated. I wanted to write a simple async HTTP server. It didn’t have to be serious, but it did need to be clean/obvious/easy to understand. The server bit, no problem. But what about parsing the request? The http module has a server. Surely, there’s a parser in there? Well, kind of, but not really one you can (in any nice way) make use of for asyncio.

At this point, I’d have to bring in another dependency. I mentioned h11 because Tom Christie speaks highly of it. But it’s a different world when you need to stop what you’re doing, track down a package that might do what you need, and do the due diligence on it to decide if it’s trust-worthy.

For a certain way of looking at it, the whole point of Python was that it comes with a set of modules that let you do the bulk of the core tasks that you might be interested in. Without the need to find and pull-in unknown or untrusted packages. The point was that it’s batteries included.

Batteries take maintenance. They run out. They need to be replaced. I hear the calls to trim down the standard library. #LessBatteries even, but I think Python is giving up a good source of competitive advantage if it goes down this route.

It used to be that you couldn’t download packages. That’s fixed.

The problem now — beyond the dissonance of having to find a likely package — is that you can’t trust the packages you do download. Supply chain security, I think they call it. Having a trusted, powerful, standard library that comes with Python means I don’t have to worry about this until my needs become much more specialised. It means I can just get on with coding. That, to me, is Python.

So, more of this, please. #MoreBatteries.