Python Trending Weekly
ISSUE 29

Python Trending Weekly #29 (2023-12-02)

2023-12-02 Season 1

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 12 Projects 12 Media 2
🦄

Articles & Tutorials

× 12
01 Rust std fs slower than Python! Really!? mp.weixin.qq.com

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!

02 Which Python timestamp function is the fastest? dataroc.ca

What 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)

Time taken for 500,000 calls
03 Python Is Easy, Go Is Simple, But Simple != Easy preslav.me

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.

04 Unlocking C-level performance in df.apply with Numba labs.quansight.org

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.

05 A Random List of Flask Maintainer To-Dos davidism.com

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.)

06 Running Python Concurrency with Subinterpreters tonybaloney.github.io

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!

Growth of workload and execution time
07 New Open Source vs. Old Open Source dev.to

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.

08 Using Polars in a Pandas World pythonspeed.com

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.

09 What are Python's soft keywords? mathspp.com

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']
10 Building a Robot Dad with Python blog.untrod.com

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.

11 How (and How Not) to Design REST APIs github.com

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.

12 How to Debug Asyncio Programs? superfastpython.com

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

× 12
01 marker: Efficiently convert PDF/EPUB/MOBI to Markdown github.com

Supports 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)

Comparison with Nougat in speed and accuracy
02 awesome-django-performance: Curated list of resources for profiling and optimizing Django projects github.com

This project curates a list of libraries, tools, articles, and books, primarily focused on profiling, database, caching, serialization, task processing, and monitoring.

03 datamodel-code-generator: Convert JSON/YAML to Pydantic models github.com

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)

04 fastapi-code-generator: Create FastAPI applications with OpenAPI files github.com

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.

05 kanban-python: A kanban application in your terminal github.com

A kanban application implemented in a command-line window, featuring pretty tables, separation of configuration and data, automatic task creation, and task tracking.

Example of the kanban application
06 saq: Simple Async Queue github.com

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.

07 pyqtgraph: Data Visualization and GUI Tools for Scientific/Engineering Applications github.com

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)

08 Toga: Native Python, Native OS GUI Toolkit github.com

A GUI toolkit for building cross-platform desktop applications. Supports macOS, Windows, Linux (GTK), Android, iOS, and single-page web apps. (3.9k stars)

09 autometrics-py: A function-level metrics monitoring tool github.com

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.

10 compiled: Compiled variants of Python standard library github.com

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.

11 transpyler-gpt: A GPT-powered Python transpiler to make code run on older versions github.com

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.

12 clone-voice: A voice cloning tool with a web interface github.com

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)

clone-voice: A voice cloning tool with a web interface
🐢

Podcasts & Videos

× 2
01 Talk Python To Me #439: Pixi a fast package manager talkpython.fm

Pixi is a Conda-based package manager written in Rust.

02 Mouse Vs Python #23: The Ruff Formatter with Charlie Marsh blog.pythonlibrary.org

Ruff is a Python linter+formatter written in Rust, and it's the fastest at both.

🥂

Discussion & Questions

× 2
01 What's the coolest thing you've done with Python? reddit.com

A popular discussion thread on Reddit with nearly 700 comments that will take a while to get through...

02 Syntactic Sugar to Encourage Use of Named Arguments discuss.python.org

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.

ESC
↑↓ select · ↵ open175 issues