python

14 Articles

Honest Python: 15 Laws Against Mediocre Code

You cleared the beginner threshold. Your code runs. Congratulations, you just reached the level of functional mediocrity. These 15 laws will teach you to write honest code, the kind you won't have to apologise for.

The 7 things you should NOT use threads for in Python (that every programmer should know)

If you have been writing Python for more than 6 months and you still use threads to make your code faster, this article is going to hurt. Threads in Python do not work like they do in Java or C++.

Python Docker images in less than 50MB

A multi-stage Dockerfile that builds your Python project as wheels with the optimization flags and installs them without touching PyPI, so the final image stays small.

lxml in multi-stage Docker images

How to build a small multi-stage Docker image with lxml on Alpine: compile the wheel in one stage and copy only the .so files it needs into the final one.

Python: JSON vs Pickle

Which serializer is faster in Python, JSON or Pickle? A small benchmark measuring time and memory with the standard library, UltraJSON and Pickle protocols 4 and 5.

Measuring the performance of Python chunks in different environments

A tiny context manager for timing specific chunks of Python code, and how to switch it on only in development and staging without touching the source.

Wonderful Python Libraries #2: secure secret storage in Python

Cloud secret managers and Hashicorp Vault are client-server. For local scripts you need something lighter: Python keyring stores your secrets in the operating system's own secure storage.

Wonderful Python libraries, no. 1: Prompt Toolkit

First post in a series about my favourite Python libraries. Prompt Toolkit gives you autocompletion, syntax highlighting, history and ncurses dialogs in the terminal without writing ncurses code.

Efficient memory usage in Python with Zero-copy

Python has a lot of magic with memory under the hood and, in most cases, Inefficiently. Let's make it efficient with Zero-copy.

Auto-generating regular expressions from a wordlist with Python

Making regular expressions (REGEX) is sometimes an arduous task. If we need to create a REGEX that matches a set of words, we need to analyse them and include all the necessary conditions to match them. It’s very common in Web Apps, filters, or something else that has to match if a word matches with a set of allowed words.

Performance: Python vs NodeJS, trying to make a fair comparison (I)

Load tests with ab against a minimal NodeJS server on Express and a Python one on asyncio and aiohttp. Requests per second, timings and concurrent clients, with the numbers as they came out.

Threads, concurrency and advanced Python

Why Python threads are not real threads, what the GIL is, how to survive it, and a case where four threads take twice as long as one. Plus the in-person Python course in Madrid with Securízame.

Hiding information in odd places (I): boolean.io

How to hide a message in boolean.io, a service that stores booleans behind a URL, by turning it into bits and storing each one separately. With a Python script.

Python 3 asyncio vs threads vs processes: fetching web pages

First post of a series comparing asyncio, threads and processes in Python 3.4. This one measures how each of them does when downloading a batch of web pages.