mathspp.com feed

https://mathspp.com/blog

30 posts

Tech

Subscribe via RSS

  1. Migrating to Python 3.15

    This practical guide tells you what to pay attention to when migrating to Python 3.15. This short article walks you through the main things to keep in mind when migrating your code to Python 3.15: backwards-compatible features: features released in 3.15 that you can start using because they're backwards compatible backwards-incompatible features: features released in 3.15 that you can only start using if your project only targets Python 3.15+ features that are now 100% supported: features…

    0 ▲
  2. Python abi3t: what is it?

    Learn what the abi3t and the limited C API are and what that means for Python users. This article explains what the limited C API and the abi3t are to Python developers who don't have experience with C extensions. 15 days of Python 3.15 To celebrate the release of Python 3.15, over the next 15 business days I'll be writing about a new 3.15 feature every day. Explained clearly and with examples so you don't have to sift through the changelog. Subscribe to receive this free email series:

    0 ▲
  3. Thread-safe iterators

    Learn how to write and use thread-safe iterators in Python 3.15. This article shows how to write and use iterators in a thread-safe manner using the new tools from Python 3.15: threading.serialize_iterator threading.synchronized_iterator 15 days of Python 3.15 To celebrate the release of Python 3.15, over the next 15 business days I'll be writing about a new 3.15 feature every day. Explained clearly and with examples so you don't have to sift through the changelog. Subscribe to receive this…

    0 ▲
  4. 4 upgrades to the Python standard library in 3.15

    Learn about 4 of the most exciting updates made to the Python standard library in 3.15. This article highlights 4 of the most exciting updates made to the Python standard library in 3.15: new object_hook in json.load: together with frozendict this unlocks a very powerful use case new module math.integer: new module that introduces integer arithmetic functions new re.prefixmatch function: clarifies some confusion that typically arises when using re.match new asyncio.TaskGroup.cancel function:…

    0 ▲
  5. Typing improvements in Python 3.15

    This article goes over the major improvements made to the typing module in Python 3.15. Since static type hinting is becoming more and more popular in the Python world, every Python release brings with it major improvements to the world of typing. This article goes over the main improvements made to typing in Python 3.15 like the improvements to TypedDict, the addition of typing.TypeForm, or the addition of the decorator typing.disjoint_base. 15 days of Python 3.15 To celebrate the release of…

    0 ▲
  6. TypedDict with extra items

    Learn how to define a TypedDict that accepts extra items of a given type. A TypedDict is a type constructor that allows creating specialised types for dictionaries that have a fixed set of string keys: from typing import TypedDict class Movie(TypedDict): title: str year: int The snippet above creates a new type Movie that represents dictionaries with the key "title" and a string value, and the key "year" and an integer value: forrest_gump = {"title": "Forrest Gump", "year": 1994} In Python…

    0 ▲
  7. Module profiling overview

    Learn about the new module profiling that was introduced in Python 3.15 to organise the built-in profiling tools. The standard library module profiling organises the built-in profiling tools that Python has into a single namespace. Introduced in Python 3.15, it gives access to two different profilers: a sampling profiler called Tachyon, and a tracing profiler. This article will present an overview of those two profilers. 15 days of Python 3.15 To celebrate the release of Python 3.15, over the…

    0 ▲
  8. Tachyon: sampling profiling in Python

    Learn how to use Tachyon, Python's sampling profiler. “Tachyon” is a new sampling profiler that was introduced in Python 3.15. It provides a CLI that allows running and profiling scripts or attaching to running processes. Tachyon logoIn this article you'll learn what statistical profiling is and how to use the Tachyon CLI to identify performance bottlenecks in your code. 15 days of Python 3.15 To celebrate the release of Python 3.15, over the next 15 business days I'll be writing about a new…

    0 ▲
  9. DX improvements in Python 3.15

    Learn about the top 3 developer experience improvements from Python 3.15 This article covers the top 3 improvements made to the developer experience of Python 3.15 users: improved error messages more colours default UTF-8 encoding 15 days of Python 3.15 To celebrate the release of Python 3.15, over the next 15 business days I'll be writing about a new 3.15 feature every day. Explained clearly and with examples so you don't have to sift through the changelog. Subscribe to receive this free email…

    0 ▲
  10. Startup configuration files

    Learn how to use startup configuration files to run package entry points when the Python interpreter starts up. A startup configuration file is a file with the extension .start. Starting from Python 3.15, the Python interpreter uses startup configuration files to run package entry points when the interpreter starts up. Here is an example of a simple startup configuration file that installs error-links when the Python interpreter starts: error_links:install The entry point error_links:install…

    0 ▲
  11. Unpacking inside comprehensions

    Learn how to use the unpacking operator inside list comprehensions. Starting with Python 3.15, you can use the asterisk * to unpack inside list comprehensions: nested = [[0, 1, 2], [3, 4], [], [5, 6, 7]] flattened = [*sublist for sublist in nested] print(flattened) # [0, 1, 2, 3, 4, 5, 6, 7] This new unpacking feature also works with set comprehensions, dictionary comprehensions, and generator expressions. This article explains the syntax, the alternatives in Python 3.14 or earlier, and shows…

    0 ▲
  12. frozendict built-in

    Learn how to use the new frozendict built-in to create and manipulate immutable dictionaries. Python 3.15 introduced a new built-in data type: the frozendict. A frozendict is an immutable dictionary that can be created with the built-in of the same name: version_info = frozendict( {"major": 3, "minor": 15, "patch": 0} ) The dictionary literal syntax using the curly braces {} creates a regular dictionary, so you must always use the built-in frozendict to create a new frozen dictionary. In this…

    0 ▲
  13. Sentinel built-in

    Learn how to use the sentinel built-in from Python 3.15 for placeholder values. Python 3.15 introduced the new sentinel built-in. The sentinel built-in can be used to create placeholder values: NOTHING = sentinel("NOTHING") A placeholder created by sentinel is the more idiomatic way to provide default arguments or return values where None wouldn't be usable. 15 days of Python 3.15 To celebrate the release of Python 3.15, over the next 15 business days I'll be writing about a new 3.15 feature…

    0 ▲
  14. Explicit lazy imports

    Learn how to use lazy imports to speed up the startup time of your Python applications. Python 3.15 introduced explicit lazy imports. An explicit lazy import is an import statement that starts with the keyword lazy: import json lazy import math lazy from pathlib import Path The module json is imported normally, but math and Path are imported lazily. If an import is lazy, the module will only be loaded when it is needed instead of being loaded immediately when Python encounters the import…

    0 ▲
  15. The 5 most exciting new features of Python 3.15

    This article explains the 5 best new features of Python 3.15 with clear examples and explanations. Python 3.15 has been published and it packs plenty of new features and improvements over Python 3.14. This article explores the five most exciting new features of Python 3.15: Lazy imports New built-in frozendict New built-in sentinel Unpacking inside comprehensions Tachyon, a new sampling profiler You'll get the elevator pitch of each feature and you'll see a couple of examples of their usage. By…

    0 ▲
  16. TIL #146 – Using maturin through uv

    Today I learned how to setup a Rust project that can be called from Python with PyO3 and maturin through uv. When you follow the PyO3 getting started guide to create a simple Rust project that can be called from Python, the instructions you get assume you'll use a global Python installation to create a virtual environment and to install maturin into it. You can use uv through maturin, but if your project also has a Rust binary, things may break. When you run a command like cargo run, cargo will…

    0 ▲
  17. Why OOP exists

    Learn the fundamental principles behind OOP and how they connect to the syntax of Python. Introduction Welcome! This article will teach you the core ideas behind object-oriented programming, commonly known as OOP. This is the article I wish I read many years ago, when I was first learning about OOP in Python. If you're new to OOP, this article will explain why OOP exists, how it works, and how to work with OOP in Python. If you think you already know OOP, this article will change the way you…

    0 ▲
  18. Python quiz: EuroPython 2026 edition

    Replay the EuroPython 2026 Python quiz. These are the questions asked during the EuroPython 2026 quiz. They will test your knowledge of the Python language, the community, and of EuroPython 2026. Since we were celebrating 25 years of EuroPython at EuroPython 2026, some questions also touched on that theme. (Unless explicitly stated, questions refer to CPython 3.14.) Note that the version of the quiz presented here is less interactive than the one presented at the conference. Questions In 25…

    0 ▲
  19. itertools cheatsheet

    Cheatsheet with visual diagrams that explain how the iterables from itertools work. This cheatsheet contains diagrams that explain how the iterables from the module itertools work in a visual way. Download this cheatsheet Download this cheatsheet

    0 ▲
  20. Write a coding agent from first principles: better tools

    Improve the capabilities of your agent by providing it with better tools. Introduction This tutorial builds on the coding agent you implemented in the tutorial “Write a coding agent from first principles”. In this tutorial, you'll take your agent and improve its capabilities by implementing the text edit and bash command tools that Anthropic provides. Why use Anthropic's tools? In the previous tutorial you implemented a coding agent that has a few tools that it can use to read, write, and…

    0 ▲
  21. Write a coding agent from first principles

    Learn how to write a coding agent in Python in this tutorial that teaches how to interact with an LLM through an API, how to manage the context, and how to do tool calling. Introduction This tutorial will show you how to create your own coding agent from first principles. By doing so, you'll understand how coding agents work under the hood. Prerequisites To be able to follow this tutorial, you'll need prior Python experience: this tutorial is not suitable for people who don't have programming…

    0 ▲
  22. TIL #145 – collections.deque is implemented in blocks

    Today I learned that collections.deque is implemented as a doubly-linked list of blocks. collections.deque I've written about the data structure deque from the module collections extensively. In particular, I wrote a deque tutorial with plenty of practical example use cases of deque. Today, after some discussion during a cohort I was teaching, a student sent a link to the collections.deque source code where a comment explains some of the lower-level details of how a deque is implemented.…

    0 ▲
  23. TIL #144 – Sentinel built-in

    Today I learned Python 3.15 will get a new sentinel built-in. Sentinel values are unique placeholder values that are commonly used in programming. Python 3.15 ships with a new built-in sentinel that can be used to create new sentinel values: # Python 3.15+ >>> MISSING = sentinel("MISSING") >>> MISSING MISSING Before this PEP, the most common sentinel idiom used the built-in object: MISSING = object() def my_function(some_arg=MISSING): if some_arg is MISSING: ... # Handle the sentinel In the…

    0 ▲
  24. TIL #143 – Resolve a lazy import manually

    Learn how to work around the Python machinery to resolve an explicit lazy import manually. A couple of articles ago I wrote about how you could inspect a lazy import. Apparently, you can use a similar trick to check the attributes and methods that a lazy import has: >>> lazy import json >>> dir(globals()["json"]) ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__',…

    0 ▲
  25. Personal highlights of PyCon Lithuania 2026

    In this article I share my personal highlights of PyCon Lithuania 2026. Shout out to the organisers and volunteers This was my second time at PyCon Lithuania and, for the second time in a row, I leave with the impression that everything was very well organised and smooth. Maybe the organisers and volunteers were stressed out all the time — organising a conference is never easy — but everything looked under control all the time...

    0 ▲
  26. Who wants to be a millionaire: iterables edition

    Play this short quiz to test your Python knowledge! At PyCon Lithuania 2026 I did a lightning talk where I presented a “Who wants to be a millionaire?” Python quiz, themed around iterables. There's a whole performance during the lightning talk which was recorded and will be eventually linked to from here. This article includes only the four questions, the options presented, and a basic system that allows you to check whether...

    0 ▲
  27. uv skills for coding agents

    This article shares two skills you can add to your coding agents so they use uv workflows. I have fully adopted uv into my workflows and most of the time I want my coding agents to use uv workflows as well, like when running any Python code or managing and running scripts that may or may not have dependencies. To make this more convenient for me, I created two SKILL.md files for two of the most common workflows that the coding...

    0 ▲
  28. Indexable iterables

    Learn how objects are automatically iterable if you implement integer indexing. Introduction An iterable in Python is any object you can traverse through with a for loop. Iterables are typically containers and iterating over the iterable object allows you to access the elements of the container. This article will show you how you can create your own iterable objects through the implementation of integer indexing. Indexing with...

    0 ▲
  29. Ask the LLM to write code for it

    This article covers a useful LLM pattern where you ask the LLM to write code to solve a problem instead of asking it to solve the problem directly. The problem of merging two transcripts I had two files that contained two halves of the transcript of an audio recording and I wanted to use an LLM to merge the two halves. There were three reasons that stopped me from simply copying part 2 and pasting it after part 1: the two tra...

    0 ▲
  30. Cyclic trapezoid animation

    See an animation of a trapezoid innscribed in a circle, built with some maths and the help of an LLM. The animation My brother asked for my help to build an animation of a trapezoid inscribed in a circle that kept changing his shape. With a bit of maths and the help of ChatGPT for the UI, I created the animation you can see below. Under the animation you can find a control panel that allows you to tweak some animation paramete...

    0 ▲