Python News

Python News: What's New From May 2021?

by David Amos May 31, 2021 community

If you want to get up to speed on what happened in the world of Python in May 2021, then you’ve come to the right place to get your news!

May was a month of big events. The Pallets Projects, home to popular frameworks like Flask and Click, released new major versions of all six of its core projects. The Python Software Foundation (PSF) hosted PyCon US 2021, a virtual conference that delivered an authentic in-person experience.

Let’s dive into the biggest Python news from the past month!

Microsoft Becomes the Third PSF Visionary Sponsor

In last month’s news roundup, we covered how Google and Bloomberg Engineering became the first two PSF Visionary Sponsors. At the end of April, the PSF also announced that Microsoft increased its support to the Visionary level.

Microsoft is directing its financial support to the Python Packaging Working Group:

As part of our $150K financial sponsorship of the PSF, we will be focusing our funds to the Packaging Working Group to help with development costs for further improvements to PyPI and the packaging ecosystem. With recently disclosed security vulnerabilities, trusted supply chain is a critical issue for us and the Python community, and we are excited to help contribute to long-term improvements. (Source)

In addition to its Visionary sponsor status, Microsoft also has five Python core developers on staff that contribute to Python part-time: Brett Cannon, Steve Dower, Guido van Rossum, Eric Snow, and Barry Warsaw.

For more information about Microsoft’s support for Python and the PSF, check out its official announcement.

Check out Steve Dower’s account to get an inside scoop on how Microsoft’s position toward Python has changed over the years. You can also listen to Brett Cannon share his experience with Python at Microsoft on the Real Python Podcast.

Pallets Releases New Major Versions of All Core Projects

Two years of hard work from the Pallets team and its many open source contributors has culminated in the release of new major versions for all six of its core projects:

All six projects have dropped support for Python 2 and Python 3.5, making Python 3.6 the minimum supported version. Previously deprecated code has been removed, and some new deprecations have been added.

Some of the major changes affecting 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

Besides the sweeping changes listed above, individual projects have several attractive new features.

Flask Gets Native asyncio Support

According to the Python Developer Survey 2020, Flask is the most popular Python web framework. Flask 2.0’s native asyncio support is sure to keep the framework’s fans happy.

You can make everything from routes to error handlers to pre- and post-request functions into coroutines, which means you can define views using async def and await:

@app.route("/get-data")
async def get_data():
    data = await async_db_query(...)
    return jsonify(data)

In this example code snippet, taken from the Flask docs, an asynchronous view called get_data() is defined. It makes an asynchronous database query and then returns the data in JSON format.

Flask’s asyncio support is not without its caveats. Flask is still a Web Server Gateway Interface (WSGI) application and is subject to the same limitations as any other WSGI framework. Flask’s documentation describes these limitations:

Async functions require an event loop to run. Flask, as a WSGI application, uses one worker to handle one request/response cycle. When a request comes in to an async view, Flask will start an event loop in a thread, run the view function there, then return the result.

Each request still ties up one worker, even for async views. The upside is that you can run async code within a view, for example to make multiple concurrent database queries, HTTP requests to an external API, etc. However, the number of requests your application can handle at one time will remain the same. (Source)

If you’re new to asynchronous programming, check out Async IO in Python: A Complete Walkthrough. You can also get a breakdown of Flask’s new asyncio support from the article Async in Flask 2.0, which was featured in the PyCoder’s Weekly newsletter.

In addition to native asyncio support, Flask 2.0 also adds some new route decorators for common HTTP methods. For example, in Flask 1.x, you declare a route supporting the POST method using the @app.route() view decorator:

@app.route("/submit-form", methods=["POST"])
def submit_form():
    return handle_form_data(request.form)

In Flask 2.0, you can shorten this code using the @app.post() view decorator:

@app.post("/submit-form")
def submit_form():
    return handle_form_data(request.form)

That’s a small change but a significant improvement in readability!

You can find all the changes in Flask 2.0 in the official changelog.

Jinja Gets Improved Async Environments

asyncio support in Jinja 2.x required a patching system as well as some caveats developers needed to keep in mind. One of the reasons for this is that Jinja 2.x supports Python 2.7 and Python 3.5.

Now that all of the Pallets projects only support Python 3.6+, the patching system was removed to provide a more natural asyncio experience for projects using Jinja 3.0.

You can find all the changes in Jinja 3.0 in the official changelog.

Click Gets an Overhauled Shell Tab Completion System

Building great command-line interfaces (CLI) for an application can be a chore. The Click project helps ease this burden with its friendly API.

One of the features shell users expect from a CLI is tab completion, which suggests command names, option names, and choice values when a user types a few characters and presses Tab.

Click has always supported shell tab completion, but the implementation was messy, as Pallets maintainer David Lord noted on a March 2020 GitHub issue:

I’ve been trying to review [a pull request] which adds type-based completions, and it made me realize just how messy completion is, both within Click and with how the shells implement and document their systems.…

[W]e keep having to re-implement things that the shell should be doing, such as escaping special characters, adding spaces (except for directories), sorting, etc. And if the user wants to provide their own completions, they have to remember to do all that too.

There’s no reason we just have to return completions. We already support returning descriptions, presumably we could extend that more. Wouldn’t it be cool if Click could indicate to the completion script that it should use other functions that Bash or ZSH provide? (Source)

By October 2020, Click’s shell tab completion system had been completely overhauled with built-in support for Bash, Zsh, and fish. The system is extensible. You can add support for other shells, and the completion suggestions are customizable on multiple levels.

The new completion system, now available in Click 8.0, is a big win for projects that wish to offer users a friendly CLI experience in their favorite shell.

You can find a complete list of changes in Click 8.0 over on the official changelog.

PyCon US 2021 Connects Pythonistas Around the World

Late spring is always an exciting time for Pythonistas in the United States. PyCon US, the largest annual convention devoted to Python, traditionally takes place in April or May.

This year, PyCon US was a little bit different from previous conferences. Originally slated to take place in Pittsburgh, Pennsylvania, PyCon US 2021 transitioned to an online-only event due to the COVID-19 pandemic.

A Virtual Conference That Feels Like the Real Thing

PyCon US 2020 was also virtual, but the last-minute transition to an online conference left the organizers little time to prepare an authentic PyCon experience. This year, the PSF had ample time to plan, and it delivered an incredibly engaging event true to the spirit of past PyCon US conferences.

Although talks were prerecorded, the videos were played on a schedule rather than being made available on demand. Each talk had a chat room associated with it, and presenters were available to interact with participants and answer questions.

The conference also featured a virtual expo hall that connected Pythonistas to various organizations in the Python world, including Microsoft, Google, Bloomberg, and more.

The most engaging part of PyCon 2021, though, was the well-executed open space and lounge area. Open spaces are small, meetup-like events that allow conference attendees to meet and interact with one another around a common interest. There were open spaces for Python authors, ham radio operators, community organizers, and so much more.

The conference’s lounge area included virtual tables that let a limited number of people join a videoconference. Anyone could grab an available chair and participate in the conversation, even if it had already started. The lounge gave PyCon a genuinely unique vibe, with all the spontaneity you’d expect at an in-person conference, effectively implementing a virtual hallway track, which is one of the hallmarks of PyCon US.

Moving PyCon US online made the conference accessible to more Pythonistas around the globe. No longer burdened by travel and accommodation expenses, Python enthusiasts could join PyCon from the comfort of their own homes for just the price of admission.

If you missed PyCon US 2021, you’ll soon be able to watch the talks on YouTube. The videos were still in postproduction at the time of writing but should be available in the coming weeks.

The Future of Python Is Focused on Performance

One of the goals of PyCon US is to bring together Python core developers and Python users to discuss the current state of and vision for the future of the language. Each year, the Python Language Summit brings together maintainers of Python implementations, such as CPython, PyPy, and Jython, to share information and solve problems.

This year’s Language Summit featured several exciting presentations. Dino Viehland talked about improvements Instagram made to CPython in its internal performance-oriented project called Cinder, including several enhancements to asynchronous I/O.

Python creator Guido van Rossum presented plans to make CPython faster. Van Rossum’s goal is to double CPython’s speed in time for Python 3.11. The increased performance would primarily benefit users who run CPU-intensive pure Python code or use tools and websites built in Python.

Another exciting feature of this year’s Python Language Summit is that the PSF gave Real Python’s own Joanna Jablonski the opportunity to cover the summit’s presentations and discussions in a series of blog posts. You can find all of her articles about the Language Summit on the PSF blog.

What’s Next for Python?

May was an eventful month for Python. At Real Python, we’re excited about Python’s future and can’t wait to see what new things are in store for us in June.

What’s your favorite piece of Python news from May? Did we miss anything notable? Let us know in the comments, and we might feature you in next month’s Python news roundup.

Happy Pythoning!

🐍 Python Tricks 💌

Get a short & sweet Python Trick delivered to your inbox every couple of days. No spam ever. Unsubscribe any time. Curated by the Real Python team.

Python Tricks Dictionary Merge

About David Amos

David Amos David Amos

David is a writer, programmer, and mathematician passionate about exploring mathematics through code.

» More about David

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Master Real-World Python Skills With Unlimited Access to Real Python

Join us and get access to hundreds of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

Master Real-World Python Skills
With Unlimited Access to Real Python

Join us and get access to hundreds of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

What Do You Think?

Real Python Comment Policy: The most useful comments are those written with the goal of learning from or helping out other readers—after reading the whole article and all the earlier comments. Complaints and insults generally won’t make the cut here.

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Keep Learning

Related Tutorial Categories: community