The author of the article dislikes the asyncio library, believing that the design using async and await is very bad, it is incompatible with most libraries, and it does not meet some of the standards of the "Zen of Python". The author's recommended solution is gevent, mentioning its advantages. In addition, the author also recommends two related articles: Flask author Armin Ronacher's I don't understand Python's Asyncio, and SQLAlchemy author Mike Bayer's Asynchronous Python and Databases.
TL;DR
The headliner is a candid 'I hate asyncio' piece best read next to a gevent explainer; Meta's audiocraft and the AI coding assistant gpt-engineer are also popular picks.
Articles & Tutorials
× 15Gevent is a cooperative multitasking Python framework based on coroutines, using monkey patching to patch all code. This post is the first in a series introducing the basic implementation details of gevent, followed by Gevent Correctness and Gevent Performance.
ReactPy, which was recommended in the last issue of the newsletter, has recently become very popular. It supports writing React-style front-end applications in Python. Here is a simple getting started tutorial. In addition, we recommend that interested students read the official documentation.
How can we solve the circular dependency problem in Python simply and elegantly? The author examined the context management schemes of mainstream API frameworks (Django, Flask, FastAPI), and then introduced the scheme adopted by his own framework: borrowing the concept of object ownership in the Ray community, a simple ownership dictionary is implemented on a coroutine.
Tracking the code and data accessed during a Python function call can be useful for operations like drawing dependency graphs, debugging and profiling performance, and invalidating caches. This article explores one possible implementation, including a minimal working implementation in fewer than 100 lines of code. The author is a PhD in Computer Science from MIT.
This is an introductory tutorial that introduces the basic and advanced usage of the Python Typing module through concise examples.
wxPython is a cross-platform GUI framework based on the wxWidgets library, which was released in 1998. It has evolved to version 4.x, and this article provides a detailed introduction to its latest features.
This is a very serious article that introduces the basic concepts and advanced usage of decorators. The example section introduces several commonly used decorators in Django (@login_required, @permission_required, @csrf_exempt, @cache_page).
One of the trickiest things in multiprocessing is sharing data. This post introduces 7 ways to share Numpy arrays: passing arguments, using global variables, using the Queue, using the Pipe, using RawArray based on ctypes, using SharedMemory from Python 3.8, and using the manager from multiprocessing. This is a systematic and long article, which also cites some related articles by the author. It is highly recommended.
Time-series data refers to data collected at different points in time. This article introduces tools for analyzing time-series data in Python, including commonly used NumPy, pandas, and Matplotlib, as well as Tsfresh, Sktime, AutoTS, Prophet, Timescale, etc.
In the field of data analysis and machine learning, it is necessary to ensure the integrity and accuracy of the dataset as much as possible. Therefore, handling missing values is an essential link. This article first introduces the causes and patterns of missing data (missing completely at random, missing at random, and missing not at random), and then introduces common methods for handling missing values: deletion, filling, and interpolation.
This article compares the performance of Cython and CPython using 10 different benchmarks, covering a variety of scenarios and edge cases, including Fibonacci sequence, Fibonacci sequence (iterative), matrix multiplication, prime number generation, string concatenation, calculating mean, calculating mean (unoptimized), arithmetic operations, file operations, linear search, and bubble sort. Guess what the final conclusion is?
Server-Sent Events is a one-way HTTP-based communication protocol that allows a server to push data to clients in real time. This article explains how to implement streaming JSON events using FastAPI. This article is from the "FastAPI Pro Series". The other two articles are about how to use dynamic configuration and how to secure your API with API keys.
Middleware is a mechanism in FastAPI that allows you to intercept and modify HTTP requests and responses before they reach the route handlers. This article contains 20 interview questions related to middleware, authentication, and authorization.
Last week's newsletter sparked a discussion on "the number of Chinese Python contributors". @yihong0618 shared this contribution to CPython by @penguin-wwy on Twitter. The author found that LOAD_CONST + RETURN_VALUE appears frequently in the pystats documentation, so he submitted a new RETURN_CONST instruction. This contribution resulted in a performance improvement of about 10% in the Python 3.12 benchmark.
🎁 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
× 11When using Python commands or command-line tools, one pain point is the lack of autocompletion. After using argcomplete, you can press the tab key to automatically complete. It needs to be used with the argparse module, and currently supports two shells: bash and zsh.
This is a large language model that has systematically learned the Chinese legal knowledge system and can correctly understand legal concepts in common areas such as civil law, criminal law, administrative law, and procedural law. It can provide basic legal advice covering areas such as marriage, loans, maritime law, and criminal law.
This is a fully open-source, commercially available 100-billion-parameter Chinese-English foundation model, which adopts the Transformer autoregressive architecture and is pre-trained on a trillion-scale high-quality corpus. On the Zero-CLUE evaluation benchmark in Chinese, it significantly outperforms other models and ranks first among Chinese large models.
TigerBot is also a large language model open-sourced by a domestic team. According to the automatic evaluation on public NLP datasets in the OpenAI InstructGPT paper, TigerBot-7B achieves 96% of the comprehensive performance of the OpenAI model of the same size.
New Bing is integrated with ChatGPT, but it's not easy to use in China! This project's client is based on Angular, and the server is based on FastAPI and EdgeGPT. After deploying it locally, you can start using the client by running the server program. (Another recommended project is go-proxy-bingai, which is a New Bing demo site built with Vue3 and Go. It's available in China and doesn't require login.)
This is an open-source/on-premises alternative to GitHub Copilot that doesn't require a DBMS or cloud service, has a web UI, and supports consumer-grade GPUs.
A static blog generator with minimalist features, minimalist code, four built-in themes, and support for generating RSS. The project is based on Python 3.10 and mainly uses libraries such as arrow, click, jinja2, and mistune.
This is an AI engineer based on ChatGPT4. All you need to do is tell it what you need, and it will ask a few questions and then generate the entire project code. The provided demo video is amazing!
This is an open-source PyTorch library from FaceBook, featuring state-of-the-art EnCodec audio compressor/tokenizer, including the MusicGen text-to-music model, trained on an internal dataset of 10K high-quality music tracks, as well as music data from ShutterStock and Pond5.
There are many libraries for developing GUIs in Python, in addition to the aforementioned wxPython, such as Tkinter, PyQt, PySide, Kivy, and more. This website provides a wealth of learning resources related to GUIs.
This is an online e-book created with GitBook, translated from Microsoft Independent Researcher Anthony Shaw's "CPython Internals".
Podcasts & Videos
× 3This podcast episode is all about refactoring.
There are three lists that look exactly the same: [0]*3, [0,0,0], and [0 for _ in range(3)], but the memory calculated using sys.getsizeof() is completely different. Why is this? This Bilibili video analyzes the bytecode and CPython interpreter source code to provide a very hardcore analysis of the root cause. It's worth watching!
This echoes the title and the first content of this issue. asyncio is still the most mainstream asynchronous programming library, and it has gradually matured in recent years. It is necessary to learn it in depth. This is a Bilibili video, suitable for getting started and deepening understanding.