r/Python • Flask Maintainer • May 12 '21

News New major versions of Flask, Jinja, Click, and Werkzeug released!

Representing over two years of work from the Pallets team and contributors, new major versions Flask, Werkzeug, Jinja, Click, ItsDangerous, and MarkupSafe have been released on May 11, 2021. Check out our announcement on our blog: https://palletsprojects.com/blog/flask-2-0-released/, and retweet it to spread the word on Twitter as well: https://twitter.com/PalletsTeam/status/1392266507296514048

Every project has significant changes, and while we don't anticipate breaking things, it may take some time for extensions and other projects to catch up. Be sure to use tools like pip-compile and Dependabot to pin your dependencies and control when you upgrade.

Overall changes to every project include:

  • Drop Python 2 and Python 3.5 support. Python 3.6 and above is required, the latest version is recommended. Removing the compatibility code also gives a nice speedup.
  • Add comprehensive type annotations to all the libraries.
  • Better new contributor experience with updated contributing guide and consistent code style with tools like pre-commit and black.

Check out the changelog links for each project to see all of the great new features and changes. I've included some of the highlights here as well.

  • Flask 2.0
    • async def views and callbacks.
    • Nested blueprints.
    • Shortcut HTTP method route decorators like @app.post() and @app.delete().
    • Static files like CSS will show changes immediately instead of needing to clear the cache.
  • Werkzeug 2.0
    • multipart/form-data is parsed 15x faster, especially for large file uploads.
    • Getting ready for async support behind the scenes.
    • Improved test client experience.
    • Routing understands websocket URLs.
  • Jinja 3.0
    • Async support no longer requires patching.
    • Lots of weird scoping fixes.
    • I18N supports pgettext.
  • Click 8.0
    • Completely rewrote the shell tab completion system to be more accurate, customizable, and extensible to new shells.
    • Support for 256 and RGB color output.
    • Options can be given as a flag without a value to use a default value or trigger a prompt.
    • * and ~ patterns are expanded on Windows since its terminal doesn't do that automatically.
    • User-facing messages like validation errors can be translated.
  • ItsDangerous 2.0
  • MarkupSafe 2.0

Four years ago, each project had 150+ open issues, some going back a decade, and pages of open pull requests too. Over time I've grown the maintainer team and the community, and we've managed to cut down the backlog to a much more manageable size. I'm thankful for all contributions and support people have given, and I hope you all continue to build amazing applications with the Pallets projects.

653 Upvotes

38 comments sorted by

View all comments

26

u/[deleted] May 12 '21

Look out, FastAPI!

15

u/pantshee May 12 '21

FastAPI will benefit from it because a lot of users use Jinja with FastAPI

28

u/dogs_like_me May 12 '21

Nice to see Flask supporting async, but FastAPI still has the pydantic and swagger fanciness.

17

u/kingscolor May 12 '21

and ASGI

7

u/dogs_like_me May 12 '21

honestly, I have no idea what the difference is between WSGI with async support, and ASGI. Mind educating a networking noob like myself?

14

u/i_like_trains_a_lot1 May 12 '21

WSGI still works on the request-response cycle, and I assume async views just allow you to await other async code inside it.

ASGI extends WSGI to add an event-driver approach to network communications. That means that it supports long lived connections out of the box (eg. websocket, http2 but I might be wrong about this one), while still working with the classic request-response cycle.

Here is a more detailed explanation I found, hope it helps: https://medium.com/analytics-vidhya/difference-between-wsgi-and-asgi-807158ed1d4c

6

u/awesomeprogramer May 12 '21

Swagger?

19

u/kingscolor May 12 '21

OpenAPI (formerly, Swagger)

18

u/dogs_like_me May 12 '21

goddamnit I'm old.

4

u/its-Drac May 12 '21

Use flask apifairy for swagger/redoc

4

u/[deleted] May 12 '21

I don’t see how this makes flask a better api framework than fastapi. But I’d like for someone to explain it to me

5

u/pengekcs May 12 '21

I think it's just keeping it up with the rest of them fws. Good to have it, even if one does not use it (because of fastapi or any other cause)

2

u/dogs_like_me May 12 '21

I totally love fastapi, but I'm also not in denial that flask has a much bigger community. Flask adopting some of the benefits of fastapi is a much faster way to get those benefits out to the broader python userbase than expecting everyone to just move to fastapi.