Python Trending Weekly
ISSUE 28

Python Trending Weekly #28 (2023-11-25)

2023-11-25 Season 1

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

Articles & Tutorials

× 12
01 Four Kinds of Optimization tratt.net

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.

02 Two Thread Pools, and Why Do We Need Them? pythonspeed.com

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

03 It's Time for a Change: datetime.utcnow() Is Now Deprecated blog.miguelgrinberg.com

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.

04 Deploying Python Web Applications biaodianfu.com

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.

05 Python GIL's Changing "Guarantees" stefan-marr.de

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.

06 Django Dependency Management with pip-compile and pip-tools learndjango.com

There are many options for dependency management in Python, and this article introduces the combination of pip-compile and pip-tools.

07 Types of Errors in Python Apps threeofwands.com

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.

08 How Many Python Core Devs Use Type Hints? blog.orsinium.dev

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.

09 Trying to Convert a Flask Project to Quart Using Python's ast Module juejin.cn

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.

10 A Visual Explanation of Python's NumPy Library solothought.com

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.

11 Composition vs Inheritance: I Beg to Differ coady.github.io

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.

12 Choosing the Right Data Dashboard Tool: The Unique Strengths of Streamlit and Shiny python-bloggers.com

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

× 12
01 screenshot-to-code: Generate HTML/Tailwind/JS code from a screenshot github.com

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

02 sqlalchemy_data_model_visualizer: Convert SQLAlchemy data models into beautiful SVG diagrams github.com

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.

A directed graph of database tables
03 aiconfig: A configuration-driven AI application development framework github.com

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.

04 PyNest: A framework built on FastAPI, following the modular architecture of NestJS github.com

It allows you to easily build scalable and maintainable APIs, with support for dependency injection, type annotations, decorators, and code generation.

05 StyleTTS2: A Near-Human Text-to-Speech Library github.com

It achieves human-level TTS synthesis by leveraging style diffusion and adversarial training with a large-scale speech language model (SLM). (star 2.7K)

06 pyjokes: A One-Liner Joke Generating Service for Programmers github.com

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.

07 gTTS: Interact with Google's Text-to-Speech API github.com

This library calls Google Translate's Text-to-Speech API, providing customizable sentence tokenizers specific to a language, and customizable text preprocessors. (2K stars)

08 chatfairy: A minimalist web chat room powered by Flask github.com

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)

Chat demo
09 streamlit-shadcn-ui: Use shadcn-ui components in Streamlit github.com

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.

10 video-subtitle-remover: Use AI to remove hard subtitles/watermarks from images/videos github.com

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.

11 flowty-realtime-lcm-canvas: Sketch-to-image demo using LCM and gradio library github.com

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)

12 pyephem: Scientific-grade astronomy computations library github.com

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/

ESC
↑↓ select · ↵ open175 issues