Rodrigo Girão Serrão: 4 upgrades to the Python standard library in 3.15

Wait 5 sec.

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 casenew module math.integer: new module that introduces integer arithmetic functionsnew re.prefixmatch function: clarifies some confusion that typically arises when using re.matchnew asyncio.TaskGroup.cancel function: ergonomic way of cancelling all the tasks in a task group15 days of Python 3.15To 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: Enroll for free 🐍🚀 If you want, you can also check the schedule of the upcoming emails.New object_hook in json.loadThe function json.load now has a parameter object_hook, which can be set to a callable.When set, JSON objects that are decoded into dictionaries are passed to object_hook and replaced by their result.For example, suppose you have the following JSON data in a file data.json:{ "name": { "first": "Rodrigo", "last": "Girão Serrão" }, "interests": [ "Python", "Rust", "AI" ]}Define an object hook and use it when loading the data:import jsondef object_hook(d): print(f"Inside object_hook with {d = }.") return dwith open("data.json", "r") as f: data = json.load(f, object_hook=object_hook)Running this code produces two lines of output:Inside object_hook with d = {'first': 'Rodrigo', 'last': 'Girão Serrão'}.Inside object_hook with d = {'name': {'first': 'Rodrigo', 'last': 'Girão...