Reusing Pydantic validators and serializers

Posted on 2025-04-21 in Trucs et astuces • Tagged with Python, Pydantic

I’ll give some tips to reuse field and model validators and serializers. All my examples will use validators, but it works exactly the same for serializers.

Field validators

Assign the validator to a variable like so:

def _is_above_ten(value: int):
    if value > 10:
        return value

    raise ValueError(f"{value …

Continue reading

Using Pydantic with custom classes

Posted on 2025-04-19 in Programmation • Tagged with Python, Pydantic

Pydantic is an awesome data validation library for Python. It’s getting very popular these days because it’s fast, has lots of features and is pleasant to use. I’m using it at work and it personal projects. It’s one of the strong points of FastAPI, the new …


Continue reading

Converting jupyter notebooks

Posted on 2025-04-17 in Trucs et astuces • Tagged with Python

You can export a notebook directly from the interface under File > Save and Export Notebook As. You can also do it in CLI with:

jupyter nbconvert --execute --to <FORMAT> my_notebook.ipynb

The --execute will execute the notebook to make sure all output cells are up to date. Many export formats …


Continue reading

Sending all nginx logs to journald

Posted on 2025-04-13 in Trucs et astuces • Tagged with systemctl, Linux

As part of my work to uniformize my server setup around systemd, I decided to make nginx log everything with journald. By default, it logs accesses and errors in log files under /var/log/nginx. I already had one log file per vhost.

To do the change, I changed my …


Continue reading

Some tips on Python’s enums

Posted on 2025-04-12 in Programmation • Tagged with Python

I’d like to share a few tips I recently (re)discovered about Python’s enums. While interesting on its own, this article is also paving the way on a more advanced article I hope to write soon. Let’s dive right in!

auto

By using the function enum.auto …


Continue reading

PostgreSQL using ANY instead of IN

Posted on 2025-03-31 in Trucs et astuces • Tagged with PostgreSQL, Database

I recently learned while reading psycopg’s documentation (a Python driver for PostgreSQL), that you should use WHERE id = ANY(:values) instead of WHERE id IN :values when filtering over lists. That’s because the ANY operator works with empty list while IN doesn’t. Psycopg will also correctly adapt …


Continue reading

Monitor certificates statuses

Posted on 2025-03-30 in Trucs et astuces

Let’s encrypt recently announced they will stop sending emails when certificates must be renewed. Following this announcement, I created a small script to monitor the status of my certificates and receive an email if they are not renewed in time. Since it can be handy, here it is!

The …


Continue reading

From matomo to plausible

Posted on 2025-03-09 in Blog • Tagged with Web

For several years, I hosted my own Matomo instance to track traffic on my blog and projects while respecting the privacy of my users. It worked well, but it was the only service I had running on MariaDB. All the other ones are running on PostgreSQL. And I had several …


Continue reading

Writing a browser extension

Posted on 2025-02-16 in Programmation • Tagged with Web

I recently wrote a browser extension for Firefox and Chromium based browsers for my Legadilo (RSS feeds aggregator and articles saver) project. The goal is to make it easier and faster to save an article or to subscribe to a feed directly on a web page without forcing you to …


Continue reading

Using podman for containers

Posted on 2025-02-09 in Programmation • Tagged with Docker, podman, containers, systemctl, Linux

Podman is an alternative to Docker and Docker compose. It uses the same CLI interface than Docker and uses the same standardized image format. So you can use an image built with Docker with it or build an image and then use it with Docker. Its podman-compose command is compatible …


Continue reading