Python

How to run Python in production

My previous article recommended that one should reconsider using Python in production. However, there’s one category of use case where Python is the dominant option for running production workloads. And that’s data analysis and machine learning. Almost all bleeding-edge work in data analysis and machine learning, especially around LLMs, happens in Python. So, here are some of my learnings on how to run Python in production. Project quality Package manager Python has a fragmented ecosystem of package managers. The only ones I can recommend are poetry and uv . After learning about uv on Hacker News , I decided to give it a try . uv is blazingly fast and manages the Python binary as well. It even supports migrations from other package managers. The only downside is that uv is still not on a stable release yet. ...

It is hard to recommend Python in production

It is hard to recommend Python in production

I started writing in the 2010s when Python 2 was going to be deprecated and Python 3 was too early to support. Python might have died there and then but was picked up by the data science and machine learning community, so, it survived. Running Python in production comes with various gotchas though. Python is resource-intensive Let’s consider a simple Docker image containing “Hello World”. Dockerfile 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # Build: docker buildx build -t python-fastapi -f Dockerfile_python . # Size: docker image inspect python-fastapi --format='{{.Size}}' | numfmt --to=iec-i # Run: docker run -it --rm --cpus=1 --memory=100m -p 8000:8000 python-fastapi FROM python:3.12-slim AS base WORKDIR /app RUN pip3 install --no-cache-dir fastapi==0.115.11 uvicorn==0.34.0 SHELL ["/bin/bash", "-c"] RUN echo -e "\ from fastapi import FastAPI\n\ app = FastAPI()\n\ @app.get('/')\n\ async def root():\n\ return {'message': 'Hello World'}\ " > /app/web_server.py ENTRYPOINT ["uvicorn", "web_server:app", "--host=0.0.0.0", "--port=8000", \ "--workers=4", "--limit-concurrency=32"] And a similar web server in Go. ...

Python logo

Best practices for using Python & Poetry inside Docker

The ultimate guide to using Poetry inside Docker

How to send HTML mails using Amazon SES (Simple Email Service)

As the title suggests, I was looking for a way to send HTML mails in python using Amazon SES but did not find anything (or maybe my search skills are bad). So, once I found the solution, I thought I might share it with everyone. The basic idea is that contents of the mail (raw-message) must be a JSON dictionary with “Data” as main key whose value is a key value pair containing entries with keys like “From”, “To” etc. Sample code can be seen below.