A long article begins with a strange question: a program written in Rust is slower than Python!? In the process of locating the root cause, the author repeatedly obtained the result that the Rust solution was slower than Python, and even the C version code was slower than Python! Going deeper and deeper, using various positioning methods, it was finally discovered that it was a problem with the AMD CPU kernel!
TL;DR
A counterintuitive benchmark shows Rust's std fs slower than Python! Also inside: parallelism with subinterpreters, Polars in a Pandas world, and marker for fast PDF-to-Markdown conversion.
Articles & Tutorials
× 12What are the functions for getting timestamps in Python? How do they perform? The article took 7 functions for performance measurement and found that time.time() is the fastest. After the article was published, it caused some controversy, so the author wrote a second article, comparing Win10, WSL2, and Ubuntu20, and also added a comparison of Python 3.10 and 3.12. (Attached: The second article on performance comparison)
Python is easy to learn and use because it leaves a lot of the complex work to the interpreter, which makes it suitable for prototyping and rapid application development. Go is also simple, but it has more rules than Python and is more performant. The author suggests playing to the strengths of both.
In Pandas 2.2.0, DataFrame.apply can specify a new numba engine to achieve parallelized operations. The article introduces the working principle of this engine, the application scenarios it supports and what it cannot do, and provides data for multiple performance tests.
The author, one of the maintainers of Flask, listed a to-do list for Flask contributors to work on. Most of us don't have experience maintaining open-source projects, so we may not be able to imagine the huge amount of non-coding stuff that maintainers have to do. (BTW: Flask lost its position as the second most starred web framework this week, being surpassed by FastAPI.)
Python 3.12 exposed an API for subinterpreters. What can you do with it? How does it compare to threads and processes, and what are the performance implications? What happens when you try to use it for web development? The author experimented with a development version of Python 3.13, and the results were a mixed bag of surprises and crashes. Here's hoping for a truly GIL-less Python next year!
The article selects 10 well-known libraries in the Python community and provides their corresponding alternative libraries. The most uncontroversial one is probably Ruff replacing Pylint, and others include: Taipy/Streamlit, Polars/Pandas, Dask/PySpark, PyTorch/TensorFlow, etc.
Polars is a faster, more memory-efficient, and easier-to-use data processing library that can serve as a drop-in replacement for Pandas. But how can you integrate it with third-party libraries that you rely on? This article shows you several approaches to achieve a seamless transition from Pandas to Polars.
Soft keywords are keywords that can be reassigned. The author wanted to use regular expressions to find all soft keywords from Python's latest grammar file. It turned out that only the following two lines of code are needed to do the trick (the following is the result of Python 3.12, i.e. there are 4 soft keywords now):
>>> import keyword
>>> keyword.softkwlist
['_', 'case', 'match', 'type']
To deal with his kid's questions, the author built a "robot dad". He used Eleven Labs for voice cloning, Picovoice for wake word detection, and finally called the ChatGPT API to get answers.
The article lists more than ten best practice rules for REST APIs, explaining what the rules mean and how to implement them. In addition, the author made fun of several widely used APIs from companies as counterexamples of the rules.
The article introduces several ways to debug Asyncio code, including enabling its debug log, running the event loop in debug mode, customizing debug information, etc. (P.S. Its sister article How to Profile Asyncio Programs analyzes slow programs and hot functions.)
🎁 Python Trending Weekly 🎁 organizes its content into seasons, with every 30 issues forming a season. The highlights from the first season have been compiled for your convenience. You can access them online here (Chinese).
Projects & Resources
× 12Supports converting multiple file formats to Markdown, can remove headers/footers, convert equations to LaTeX, format code blocks and tables, and also supports multiple languages. (Star 2.3K) (Attached: The effect of converting the entire PDF version of "Think Python" after conversion)
This project curates a list of libraries, tools, articles, and books, primarily focused on profiling, database, caching, serialization, task processing, and monitoring.
A data model code generator that supports multiple input types (OpenAPI, JSON, YAML, CSV, Python dictionaries, GraphQL) and outputs Pydantic, dataclass, TypeDict, and other types. (2k stars)
It uses datamodel-code-generator to generate Pydantic models and quickly generates a FastAPI project based on an OpenAPI formatted interface file. It supports custom templates and allows passing custom variables to custom templates.
A kanban application implemented in a command-line window, featuring pretty tables, separation of configuration and data, automatic task creation, and task tracking.
A simple and high-performance task queue framework based on Asyncio and Redis. It provides a simple UI to view task queues, status, and execution details.
A high-performance graphics library using Numpy for numerical operations and Qt's GraphicsView framework for 2D display and OpenGL for 3D display. (3.5K stars)
A GUI toolkit for building cross-platform desktop applications. Supports macOS, Windows, Linux (GTK), Android, iOS, and single-page web apps. (3.9k stars)
It provides a decorator to monitor metrics like request rate, error rate, and latency for functions, helping you identify and debug issues in your code. It supports querying and analyzing with Prometheus, out-of-the-box Grafana dashboards, custom alerting, and has a low runtime overhead.
Some standard libraries in Python are implemented in pure Python, which can be a performance bottleneck. This project compiles type-checked standard libraries with mypyc to C code, resulting in 2-4x speedups over the original versions. Currently, tomllib and difflib are done, with asyncio, urllib, zipfile, argparse, and uuid planned.
It leverages GPT to transpile higher version Python code to Python versions for target environments, enabling backward-compatible execution. For example, it can transpile match-case code from Python 3.10+ to if-else code that can run on lower Python versions.
Supports 4 languages: Chinese, English, Japanese, and Korean, and can record audio from a microphone online. It supports text-to-speech and voice changing. (1.3k stars)
Podcasts & Videos
× 2Pixi is a Conda-based package manager written in Rust.
Ruff is a Python linter+formatter written in Rust, and it's the fastest at both.
Discussion & Questions
× 2A popular discussion thread on Reddit with nearly 700 comments that will take a while to get through...
Named arguments in functions improve readability, but can also make code verbose and repetitive. The author proposes a syntactic sugar to simplify the writing of variable assignments, which has received support from several core developers.