A highly recommended article. The body of the article introduces four approaches to optimization: using better algorithms, using better data structures, using a lower-level programming language, and accepting less precise solutions. The beginning and end of the article put forward some lessons: we tend to be overly optimistic about performance optimization problems, we may sacrifice correctness for performance, we should not make premature and complex optimizations, and the breadth of optimization is more important than the depth of optimization.
TL;DR
Two kinds of thread pools and four ways to optimize programs make a solid pair; datetime.utcnow() is deprecated—time to audit your code—and screenshot-to-code turns images into HTML in one shot.
Articles & Tutorials
× 12Due to the GIL limitation, when using thread pools in Python, we need to be aware of whether the workload is CPU-bound or IO-bound, which leads to different choices on the number of threads and the target of the thread pool.
The utcnow() and utcfromtimestamp() methods of datetime.datetime are marked as "deprecated" in Python 3.12 and will be removed in a future version. The article discusses their drawbacks and explains why they are being deprecated. The replacements are datetime.now() and datetime.fromtimestamp() respectively.
This article introduces how to deploy Flask applications using different solutions such as Nginx+Gunicorn+Supervisor, Nginx+uWSGI+Supervisor, Waitress, and Meinheld, and analyzes their advantages and disadvantages.
This article introduces the implementation details of the CPython Global Interpreter Lock and the changes between Python 3.9 and the current 3.13 development version. One big difference is that in 3.9 and earlier, the GIL is released when executing many bytecodes, while in 3.13, only a small number of bytecodes are checked to see if the GIL is released.
There are many options for dependency management in Python, and this article introduces the combination of pip-compile and pip-tools.
The author categorizes bugs in programs into four types: type errors and linting errors, import-time exceptions, runtime exceptions, and silent errors. The strategy for handling them is to reduce the occurrence of later types of errors by transforming them into earlier types of errors.
Type hints are gaining popularity in Python, but how prevalent are they among core developers? The author analyzed the data and found that, of all core developers, about 53% have recent open-source contributions, and of those, 39% use type hints. Of those who joined the team in the last 3 years, 76% use type hints.
The author wanted to use asynchronous iterators returned by OpenAI, so he refactored his Flask project, which didn't support asynchronous operations, to Quart, which does. However, manually modifying the code would have been too time-consuming, so he came up with the idea of using AST parsing to modify the code and improve the efficiency of the project conversion.
The article uses a lot of intuitive graphics to illustrate the distribution of NumPy data and the process of data transformation, making it easy to understand NumPy data manipulation.
The traditional view is that composition is better than inheritance, but the author argues that Python doesn't support composition very well, and that using composition dogmatically can lead to problems. Therefore, the author provides a simple implementation approach.
In an era where data drives critical decision-making, interactive dashboards have become indispensable tools in industries such as business and scientific research. Streamlit and Shiny (including RShiny and PyShiny) are powerful frameworks, and this article introduces their respective advantages.
🎁Python Trending Weekly🎁 I will share a lot of content that is not included in the weekly issue on Telegram Channel. There are currently 1200+ students following. Welcome to join us!
🎁 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
× 12A new project that's blowing up, it uses GPT-4 Vision to generate code and DALL-E 3 to generate a similar looking UI to the screenshot. You can even input a URL to clone a website in real time! (19.4k stars)
Generate high-quality visualizations of SQLAlchemy ORM models, using Graphviz to render each model as a directed graph, making it easier to understand the relationships between tables in your database.
It reduces complexity by separating prompts, model parameters, and model-related logic from application code. The SDK is model-agnostic and extensible to any generative AI model.
It allows you to easily build scalable and maintainable APIs, with support for dependency injection, type annotations, decorators, and code generation.
It achieves human-level TTS synthesis by leveraging style diffusion and adversarial training with a large-scale speech language model (SLM). (star 2.7K)
Once installed, simply call pyjoke from the command line or add it to your .bashrc file to get a joke every time you open your terminal.
This library calls Google Translate's Text-to-Speech API, providing customizable sentence tokenizers specific to a language, and customizable text preprocessors. (2K stars)
A minimalist chat room application with both front-end and back-end code in a single file of only 115 lines. It uses SSE for back-end message pushing, does not rely on WebSockets, and supports user authentication, multi-user chat, online/offline notifications, and route protection. (Submitted by @yuxiaoy1)
Streamlit's component selection is relatively limited, and the style is relatively old. This project introduces the popular shadcn component library in the front end to Streamlit, making the UI more beautiful.
It can remove hard subtitles in videos without loss of resolution, generate files after removing subtitles, and use AI to fill the original subtitle area; it supports custom subtitle positions and supports automatic removal of all text in the entire video.
Turn your sketch drawings into vivid images in real time. You can change the model ID in the UI to use different models. (1.5K stars)
Perform high-precision astronomical computations, used to find the positions of planets, comets, or asteroids, determine the location of a particular celestial body, calculate the dates of the Moon's phases, convert between astronomical coordinate systems, determine the dates of the vernal and autumnal equinoxes, and more.
This article was first published at: /issues/28/