python

105 posts tagged “python”.

  1. 2024
  2. Controlling the style of dumped YAML using PyYAML

    I had a list of Python dictionaries I wanted to output as YAML, but I wanted to control the style of the output.

    1 min read
  3. TOML in Python

    I finally got around to fully learning TOML. Some notes, including how to read and write it from Python. The data structure A TOML file is a document that contains a dictionary of key value pairs.

    2 min read
  4. Generating a calendar week grid with the Python Calendar module

    I needed to generate a grid calendar that looks like this (design by Natalie Downe): The Python standard library calendar module has a utility function that really helps here: Outputs:

    1 min read
  5. Emulating a big-endian s390x with QEMU

    I got a bug report concerning my sqlite-fts4 project running on PPC64 and s390x architectures. The s390x is an IBM mainframe architecture, which I found glamorous!

    1 min read
  6. Python packages with pyproject.toml and nothing else

    I've been using and for my Python packages for a long time: I like that it works without me having to think about installing and learning any additional tools such as Flit or pip-tools or Poetry or…

    5 min read
  7. Trying out Python packages with ipython and uvx

    I figured out a really simple pattern for experimenting with new Python packages today: This command will work if you have uv installed and nothing else.

    1 min read
  8. os.remove() on Windows fails if the file is already open

    I puzzled over this one for quite a while this morning. I had this test that was failing with Windows on Python 3.11: The test checks that the option to my constructor deletes and re-creates the file.

    1 min read
  9. Trying out free-threaded Python on macOS

    Inspired by py-free-threading.github.io I decided to try out a beta of Python 3.13 with the new free-threaded mode enabled, which removes the GIL.

    2 min read
  10. Deploying Python web apps as AWS Lambda functions

    I've been wanting to figure out how to do this for years. Today I finally put all of the pieces together for it. AWS Lambda can host functions written in Python.

    6 min read
  11. Configuring Dependabot for a Python project

    GitHub's Dependabot can automatically file PRs with bumps to dependencies when new versions of them are available.

    1 min read
  12. 2023
  13. Formatting thousands in Jinja

    Here's how to format a number in Jinja with commas for thousands, without needing any custom filters or template functions: {{ "{:,}".format(row count) }} Output looks like this: 179,119 Bonus: here's…

    1 min read
  14. Packaging a Python app as a standalone binary with PyInstaller

    PyInstaller can take a Python script and bundle it up as a standalone executable for macOS, Linux and apparently Windows too (I've not tried it on Windows yet).

    1 min read
  15. Freezing requirements with pip-tools

    I tried pip-tools for the first time today to pin the requirements for the natbat/pillarpointstewards Django app. The pip-tools README is really good. Here's how I'm using it.

    1 min read
  16. Running PyPy on macOS using Homebrew

    Towards Inserting One Billion Rows in SQLite Under A Minute includes this snippet: All I had to do was run my existing code, without any change, using PyPy.

    1 min read
  17. Compile and run a new SQLite version with the existing sqlite3 Python library on macOS

    I've been trying to figure this out for years. Previous notes include Using LD PRELOAD to run any version of SQLite with Python (Linux only), and Building a specific version of SQLite with pysqlite on…

    1 min read
  18. Using Fabric with an SSH public key

    Inspired by this tweet by Mike Driscoll I decided to try using Fabric to run commands over SSH from a Python script, using a public key for authentication.

    1 min read
  19. Planning parallel downloads with TopologicalSorter

    For complicated reasons I found myself wanting to write Python code to resolve a graph of dependencies and produce a plan for efficiently executing them, in parallel where possible.

    1 min read
  20. Annotated explanation of David Beazley's dataklasses

    David Beazley on Twitter: So, I just published this deliciously evil spin on dataclasses. It's tiny and the resulting classes import about 15-20 faster than dataclasses.

    1 min read
  21. Check spelling using codespell

    Today I discovered codespell via this Rich commit. is a really simple spell checker that can be run locally or incorporated into a CI flow. codespell is designed to run against source code.

    1 min read
  22. CLI tools hidden in the Python standard library

    Seth Michael Larson pointed out that the Python module can be used as a CLI tool like this: This is a neat Python feature: modules with a block that are available on Python's standard import path can…

    2 min read