Vinay

⇐ Back

What its like to write python in 2024

Wed Sep 18 2024


Introduction

Every CS student in any corner of this world probably knows python. It’s the 3rd most used language in the world according to stack overflow survey just behind Javascript and Html/CSS (not a programming language btw). But I think python got a very bad reputation of being the language of newbies and let me be clear right off the bat, its not a crime to be beginner friendly. A language easy to learn and fast enough to produce result (from starting a project to finishing it) should be considered as one of the greatest language ever! No? Ask Gophers, they love it. But we don’t seem to appreciate python enough. Sure it is appreciated but mostly in the AI community. But when its about web development, everyone wants to jump on latest javascript techstack. Everyday there’s new framework being conceived, a new runtime is born and another npm package being deprecated.

Well i admit that node did a great job of embracing javascript and made it a lot more useful than it actually is and there are real benefits of using it. But in 2024, python is not bad either. There’s a lot more going on inside the community than you might think and python has become a lot better than it was in 2009 (node initial release). Here’s a few of them.

No-GIL

The Python community has been asking for a no-gil interpreter for a long time and its here. Hey, but what is GIL?

GIL stands for global interpreter lock that python has since version 1.5. It’s essentially a mutex or to simply put it, a lock that allows only one thread to execute a python script. All of this to improve the stability and simplicity of python since its much easier to keep track of the data when multiple processes don’t have the ability to mutate them. You don’t have to keep track of each mutex on your own or how the data flows through them, interpreter takes care of all of that.

So now we’re finally getting an interpreter without a mutex. It’s available in ubuntu’s ppa repository and you can install it right now. Since python 3.13 is a pre release candidate as of now it’s not ready for production use yet, but once people start using it, things will start looking better and better from now on.

ASync/Await

Did you know python supports concurrency? What!! Crazy right?!. But hey there’s more!!!

Infact there’s a lot of ways to achieve concurrency in python. You can use asyncio which is officially part of Cpython and works in a similar way modern javascript concurrency works. Apart from asyncio we’ve trio and anyIO, which is built on top of asyncio and trio to achieve concurrency. You can go read about them and find out which serves your purpose best but for the most cases asyncio is good enough.

Another async library that is in very early development stage is asyncer by Sebastián who is the creater of fastAPI. It is written mainly to improve developer experience who are using AnyIo for concurrency and quite opinionated in its implementation.

Improved tooling

Every language needs a good tooling for anyone to start writing a good enough code that is actually useful in production. Every language making its debut since like 2015 comes with its own package manager, Lsp, formatter etc. Every language needs an ecosystem to breath in. Python is not so different. Pip, virtualenv are part of this python ecosystem.

Well there’s new sherif in town. Astral.sh is a company behind this new tooling. Uv and ruff are two new emerging tools that works really well with the existing ecosystem. Creating an environment installing packages and formatting codes is a big part of python ecosystem and these tools aims to make that process faster and easier (It’s written in rust btw).

Now there’s this debate that is it morally okay for them to just steal all the open source work that everyone put so much effort behind the tooling and making money out of it. Sure they rewrote this whole things in Rust but the idea remains the same.

Not only this but there’s many other tools like poetry, black and basedpython that aims to make setting up a project super easy and helps you find bug in your code as quickly as possible. Python also has now a configuration file to keep the settings for linters, type checkers, build-systems etc project wise. You can do this by creating pyproject.toml file in the root of your project. Read More about toml config file.

Types and annotations

Python is a dynamic language and its nice to write small scripts without fighting the type checker for eternity. But when you’re writing a library for others to use, you need types! Let’s say you are building a web application and you need to validate the user input. You need types! These are real problems and python has addressed this issue.

Type hints was added in python 3.5 (its been a while). There are no performance bottlenecks or gains when using it. It just purely there to make developer experience richer because you don’t want to jump to definition all the time just to find out what kind of argument a function expects. Types make it easier for you to understand what your code does. It’s really helpful combined with the power of an IDE or text editor.

Since then many types has been added to the python and there have been many life improvement updates. Pydantic is one library that emerged as life saviour in python world. It’s a data validation library which is similar to zod library in javascirpt.

Overall Ecosystem - Conclusion

The python community is growing faster than ever and as well as the ecosystem. You could make and deploy python web application on a server since the beginning of time but isn’t managed hosting GREAT? I mean look at javascript. You make a web app and you’re 3 clicks away from deploying it. Thanks to vercel and cloudflare. It’s easier than ever. Will python ever get to that point? I hope so!

The python runtime section in vercel and cloudfare worker docs mentions that its still in beta. Cloudflare uses Pyodide which is a port of Cpython to wasm (so technically not even python). Vercel doesn’t specifies such thing but they could or could not be using the actual python runtime. But the point is companies will only support python runtimes if people start using it.

You can make web apps, put it in a docker container and toss it into an EC2 instance, that’s probably the easiest way for you to start using it right now or you can just grind on a bare metal linux machine if you’re looking to have more fun (might write a blog on that as well).

How are you gonna write a web app in python? Well there’s number of framework that emerged in last decade or so. Fastapi, Django Ninja and Sanic to name a few and they all seem promising. ASGI servers like starlette and Uvicorn are one of the fastest web servers which can serve thousands of requests per second and sometimes can outperform even node. Don’t believe me? Check out this benchmark by Tech Empower.

So is it the year of PHP and Python again? I guess we will find out.


Liked the content? Share it!

Got any suggestions? Write me at itsvinay.in@gmail.com