You have arrived to the appropriate location to get the latest information about what occurred in the Python community during the month of May 2021. If this is the case, then you have come to the proper spot.
May was a month filled with important happenings. The Pallets Projects, which is the home of many well-known frameworks such as Flask and Click, has announced the release of new major versions of all six of its main projects. PyCon US 2021 was a virtual conference that was organized by the Python Software Foundation (PSF). It was designed to simulate the in-person experience as closely as possible.
Let’s take a look back at some of the most important Python-related stories from the past.
month!
Microsoft Becomes the Third PSF Visionary Sponsor
In the recap of recent events that we published a month ago, we discussed the fact that Google and Bloomberg Engineering had become the first two PSF Visionary Sponsors. The PSF made the announcement at the end of April that Microsoft has upped the level of assistance it provides to that of a Visionary.
The Python Packaging Working Group is going to benefit from Microsoft’s financial assistance in the following ways:
As part of our financial sponsorship of the PSF in the amount of $150,000, we will be directing our funding toward the Packaging Working Group in order to assist with the development expenditures associated with making additional enhancements to PyPI and the packaging ecosystem. In light of the recently revealed security flaws, trustworthy supply chain is an important concern for both us and the Python community as a whole, and we are thrilled to be able to contribute to the long-term improvement of this situation. ( Original Language)
Brett Cannon, Steve Dower, Guido van Rossum, Eric Snow, and Barry Warsaw are the five Python core developers who work for Microsoft and contribute to Python on a part-time basis. In addition, Microsoft holds the position of Visionary sponsor for the Python project.
Check out Microsoft’s official statement if you want to learn more about the company’s support for Python and the Python Software Foundation (PSF).
You may gain an insider’s perspective on how Microsoft’s attitude on Python has evolved over the years by reading Steve Dower’s account of those developments. In the Real Python Podcast, you can also hear Brett Cannon discuss his experiences working with Python at Microsoft.
.
Pallets Releases New Major Versions of All Core Projects
The Pallets team and its numerous open source contributors have been toiling away over the last two years, and their efforts have now paid off in the form of the release of new major versions for all six of its key
projects:
Python 3.6 is now the bare minimum version that is supported by all six projects, since Python 2 and Python 3.5 have both been discontinued as options for support. Code that has been marked for deprecation in the past has been deleted, and additional code has been marked for deprecation.
Some of the most significant changes that will impact all six projects
include:
-
Renaming the default branch to
main
-
Adding comprehensive type annotations that make
type checking
user code more useful and provide better integrations with
IDEs
-
Using tools like
pre-commit
,
Black
, and
Flake8
to enforce a consistent style across all of the codebases and new pull requests
In addition to the fundamental shifts described above, individual projects include a number of enticing new features.
features.
Flask Gets Native
The results of the Python Developer Survey 2020 indicate that Flask is the most widely used web framework built using Python. The addition of native support for asyncio in Flask 2.0 should make the framework’s loyal users very pleased.
You can turn everything into a coroutine, from routes to error handlers to pre- and post-request functions, which enables you to construct views using async def and await.
:
@app.route("/get-data")
async def get_data():
data = await async_db_query(...)
return jsonify(data)
An asynchronous view with the name get data() has been created in the following example code snippet, which was taken from the Flask documentation. It first does an asynchronous query on the database, and then it provides the results in JSON format.
The support for asyncio in Flask does not come without any caveats. As Flask is still a Web Server Gateway Interface (WSGI) application, it is constrained by the same parameters as any other framework that uses the WSGI protocol. The documentation for Flask explains these various restrictions:
Running asynchronous functions requires the use of an event loop. Being a WSGI application, Flask makes use of a single worker to manage each individual request and response cycle. Flask will initiate an event loop on a thread when a request is made to an async view. The view function will then be executed inside the event loop, and the result will be returned.
Even with asynchronous views, each request will still use the time of one worker. The advantage is that you are able to execute asynchronous code inside a view, which enables you to do things like do several concurrent database queries, send HTTP requests to an external API, and so on. On the other hand, the number of requests that may be processed concurrently by your application will stay the same. (
) Original Source
Check see Async IO in Python: A Full Tutorial if you are unfamiliar with asynchronous programming. The article “Async in Flask 2.0,” which was featured in the PyCoder’s Weekly newsletter, also provides a summary of Flask’s newly added support for asyncio. You may get this information by clicking here.
In addition to support for native asyncio, Flask 2.0 includes several additional route decorators for commonly used HTTP methods. For instance, while using Flask version 1.x, you may use the @app.route() view to specify a route that supports the POST method.
decorator:
@app.route("/submit-form", methods=["POST"])
def submit_form():
return handle_form_data(request.form)
Using the @app.post() view in Flask 2.0 will allow you to reduce the length of this code.
decorator:
@app.post("/submit-form")
def submit_form():
return handle_form_data(request.form)
Just one modification makes a big difference in terms of how easily the text can be read.
In the official changelog, you can read about all of the modifications that were made to Flask 2.0.
.
Jinja Gets Improved Async Environments
In order for developers to include asyncio support in Jinja 2.x, they were need to use a patching mechanism and keep certain considerations in mind. The fact that Jinja 2.x is compatible with both Python 2.7 and Python 3.5 is one of the reasons behind this.
The patching mechanism has been eliminated in order to give a more natural asyncio experience for projects that are using Jinja 3.0. This is because all of the Pallets projects now only support Python versions 3.6 and above.
Changes made to Jinja 3.0 are documented in the official changelog, which can be accessed here.
.
Click Gets an Overhauled Shell Tab Completion System
Developing effective command-line interfaces (also known as CLIs) for applications may be a challenging task. The user-friendly API that the Click project provides helps to alleviate some of this load.
Tab completion is one of the features that shell users anticipate seeing in a command line interface (CLI). Tab completion is a function that recommends command names, option names, and choice values after a user has typed a few letters and pressed the Tab key.
Click has always supported shell tab completion, but the implementation was a nightmare, as David Lord, the developer of Pallets, pointed out in a March 2020 GitHub issue:
I’ve been attempting to examine [a pull request] that adds type-based completions, and it’s made me realize how very complicated completion is, both inside Click and with how the shells implement and describe their own systems….
[W]e are constantly forced to reimplement things that the shell ought to be taking care of for us, such as escaping special characters, inserting spaces (with the exception of directories), sorting, and other similar tasks. In addition, if the user wishes to provide their own completions, they are responsible for remembering to carry out all of those steps.
There is no justification for our simple need to return completions. Because we now support returning descriptions, it is likely that we can expand this capability further. If the completion script could be told by Click to utilize additional functions that Bash or ZSH give, don’t you think that would be a wonderful feature? (
) Original Source
By October 2020, Click’s shell tab completion technology had undergone a comprehensive makeover, and it now included built-in support for Bash, Zsh, and fish. The system may be expanded upon. You may add support for additional shells, and you can customize the completion recommendations on various levels.
The new completion mechanism that is now available in Click 8.0 is a huge gain for projects that want to provide users with a user-friendly command line interface (CLI) experience in the shell of their choice.
In the official changelog, you’ll discover a comprehensive summary of all of the modifications that have been made in Click 8.0.
.
PyCon US 2021 Connects Pythonistas Around the World
Pythonistas in the United States always look forward to the late spring as an exciting time of year. PyCon US, the biggest yearly conference dedicated to the programming language Python, is generally held around the months of April and May.
This year’s PyCon US was quite unique in comparison to prior iterations of the conference. PyCon US 2021 was supposed to take place in Pittsburgh, Pennsylvania; however, as a result of the COVID-19, it was changed to an event that would only take place online.
pandemic.
A Virtual Conference That Feels Like the Real Thing
PyCon US 2020 was also held online, however since the change to an online conference was made at the eleventh hour, the organizers had very little time to put together a genuine PyCon experience for attendees. This year, the PSF had plenty of time to organize, and as a result, they were able to provide an extraordinarily engaging event that was faithful to the spirit of previous PyCon US conferences.
Even though the conversations were taped ahead of time, the videos were not made accessible on demand but rather played according to a set timetable. Presenters were accessible in the chat rooms that were linked with each session to engage in conversation with attendees and respond to any queries they may have.
Python enthusiasts were able to contact with representatives from companies such as Microsoft, Google, Bloomberg, and many more via the conference’s online exhibition hall, which was another highlight of the event.
The well-executed open space and lounge area at PyCon 2021 was, however, the most interesting aspect of the conference. Open spaces are intimate gatherings, similar to meetups, that provide participants of a conference the opportunity to meet one another and engage in conversation on a certain topic. There were open areas for a wide variety of people, including Python writers, ham radio operators, community organizers, and many more.
The lounge portion of the conference included virtual tables, each of which allowed a certain number of attendees to participate in a videoconference. Even if the talk had already begun, anybody might join in by taking one of the available seats and contributing their thoughts. The lounge offered PyCon a really one-of-a-kind atmosphere, with all the spontaneity you’d expect at an in-person conference. It also successfully implemented a virtual hallway track, which is one of the distinguishing features of PyCon US.
As a result of moving PyCon US online, the conference is now available to more Python enthusiasts all over the world. Python users were freed from the financial strain of paying for transportation and lodging so that they could attend PyCon without leaving the comfort of their own homes and paying just the registration fee.
If you were unable to attend PyCon US 2021, you will soon be able to see the presentations that were given on YouTube. As this article was written, the videos were still in the process of postproduction; however, they should be accessible in the following days.
weeks.
The Future of Python Is Focused on Performance
One of the objectives of PyCon US is to bring together Python core developers and Python users to have a conversation about the present status of the language as well as the direction in which it is headed in the future. Maintainers of various Python implementations, such as CPython, PyPy, and Jython, gather together at the Python Language Summit once a year to discuss and find solutions to a variety of issues, exchange knowledge, and collaborate.
During this year’s Language Summit, there were a number of talks that were really interesting. Dino Viehland discussed the modifications that Instagram made to CPython as part of an internal performance-oriented project known as Cinder. These modifications included various upgrades to asynchronous I/O.
The inventor of Python, Guido van Rossum, has offered ideas for making CPython run more quickly. Van Rossum’s objective is to increase the speed of CPython by a factor of two in time for the release of Python 3.11. Those who execute CPU-intensive pure Python programs or who utilize tools and websites written in Python would gain the most from the improved performance.
Another interesting aspect of the Python Language Summit that took place this year was that the Python Software Foundation (PSF) provided Real Python’s very own Joanna Jablonski the chance to cover the presentations and conversations that took place at the summit in a series of blog articles. In the blog maintained by the PSF, you can discover all of her posts relating to the Language Summit.
.
What’s Next for Python?
Python had a busy month full of activities in May. At Real Python, we are really enthusiastic about the future of Python and can’t wait to find out what exciting new things are in store for us in the month of June.
Which of the recent Python-related announcements did you enjoy reading the most? Have we overlooked anything of note? If you let us know in the comments, we could include you in the summary of Python news we do the next month.
Happy Pythoning!