Skip to content
Myr

Merge pull request #4335 from pallets/drop-python-3.6

Before adoption: this commit came in with the history the project adopted, so no landing records it.

drop Python 3.6

authored by David Lord · committed by GitHub · parents 3c36d04, df806c8 · Browse files · 15 files+178 added−82 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

15 files+178 added−82 removed

  • tests:+0 added−13 removed
  • other:+178 added−69 removed

15 files+178 added−82 removed

modified:.github/workflows/tests.yaml-1 removed
modified:docs/deploying/wsgi-standalone.rst+145 added-36 removed
1Standalone WSGI Containers2==========================1Standalone WSGI Servers2=======================34There are popular servers written in Python that contain WSGI applications and5serve HTTP. These servers stand alone when they run; you can proxy to them6from your web server. Note the section on :ref:`deploying-proxy-setups` if you7run into issues.4Most WSGI servers also provide HTTP servers, so they can run a WSGI5application and make it available externally.67It may still be a good idea to run the server behind a dedicated HTTP8server such as Apache or Nginx. See :ref:`deploying-proxy-setups` if you9run into issues with that.101112Gunicorn13--------1412`Gunicorn`_ 'Green Unicorn' is a WSGI HTTP Server for UNIX. It's a pre-fork13worker model ported from Ruby's Unicorn project. It supports both `eventlet`_14and `greenlet`_. Running a Flask application on this server is quite simple::15`Gunicorn`_ is a WSGI and HTTP server for UNIX. To run a Flask16application, tell Gunicorn how to import your Flask app object.1716 $ gunicorn myproject:app18.. code-block:: text1918`Gunicorn`_ provides many command-line options -- see ``gunicorn -h``.19For example, to run a Flask application with 4 worker processes (``-w204``) binding to localhost port 4000 (``-b 127.0.0.1:4000``)::20 $ gunicorn -w 4 -b 0.0.0.0:5000 your_project:app2122 $ gunicorn -w 4 -b 127.0.0.1:4000 myproject:app22The ``-w 4`` option uses 4 workers to handle 4 requests at once. The23``-b 0.0.0.0:5000`` serves the application on all interfaces on port245000.2524The ``gunicorn`` command expects the names of your application module or25package and the application instance within the module. If you use the26application factory pattern, you can pass a call to that::26Gunicorn provides many options for configuring the server, either27through a configuration file or with command line options. Use28``gunicorn --help`` or see the docs for more information.2928 $ gunicorn "myproject:create_app()"30The command expects the name of your module or package to import and31the application instance within the module. If you use the application32factory pattern, you can pass a call to that.3334.. code-block:: text3536 $ gunicorn -w 4 -b 0.0.0.0:5000 "myproject:create_app()"373839Async with Gevent or Eventlet40~~~~~~~~~~~~~~~~~~~~~~~~~~~~~4142The default sync worker is appropriate for many use cases. If you need43asynchronous support, Gunicorn provides workers using either `gevent`_44or `eventlet`_. This is not the same as Python's ``async/await``, or the45ASGI server spec.4647When using either gevent or eventlet, greenlet>=1.0 is required,48otherwise context locals such as ``request`` will not work as expected.49When using PyPy, PyPy>=7.3.7 is required.5051To use gevent:5253.. code-block:: text5455 $ gunicorn -k gevent -b 0.0.0.0:5000 your_project:app5657To use eventlet:5859.. code-block:: text6061 $ gunicorn -k eventlet -b 0.0.0.0:5000 your_project:app626364.. _Gunicorn: https://gunicorn.org/65.. _gevent: http://www.gevent.org/66.. _eventlet: https://eventlet.net/67.. _greenlet: https://greenlet.readthedocs.io/en/latest/686970uWSGI35--------71-----7237`uWSGI`_ is a fast application server written in C. It is very configurable38which makes it more complicated to setup than gunicorn.73`uWSGI`_ is a fast application server written in C. It is very74configurable, which makes it more complicated to setup than Gunicorn.75It also provides many other utilities for writing robust web76applications. To run a Flask application, tell Gunicorn how to import77your Flask app object.7840Running `uWSGI HTTP Router`_::79.. code-block:: text8042 $ uwsgi --http 127.0.0.1:5000 --module myproject:app81 $ uwsgi --master -p 4 --http 0.0.0.0:5000 -w your_project:app8244For a more optimized setup, see :doc:`configuring uWSGI and NGINX <uwsgi>`.83The ``-p 4`` option uses 4 workers to handle 4 requests at once. The84``--http 0.0.0.0:5000`` serves the application on all interfaces on port855000.8687uWSGI has optimized integration with Nginx and Apache instead of using88a standard HTTP proxy. See :doc:`configuring uWSGI and Nginx <uwsgi>`.899091Async with Gevent92~~~~~~~~~~~~~~~~~9394The default sync worker is appropriate for many use cases. If you need95asynchronous support, uWSGI provides workers using `gevent`_. It also96supports other async modes, see the docs for more information. This is97not the same as Python's ``async/await``, or the ASGI server spec.9899When using gevent, greenlet>=1.0 is required, otherwise context locals100such as ``request`` will not work as expected. When using PyPy,101PyPy>=7.3.7 is required.102103.. code-block:: text104105 $ uwsgi --master --gevent 100 --http 0.0.0.0:5000 -w your_project:app106107.. _uWSGI: https://uwsgi-docs.readthedocs.io/en/latest/47.. _uWSGI HTTP Router: https://uwsgi-docs.readthedocs.io/en/latest/HTTP.html#the-uwsgi-http-https-router108109110Gevent50-------111------11252`Gevent`_ is a coroutine-based Python networking library that uses53`greenlet`_ to provide a high-level synchronous API on top of `libev`_54event loop::113Prefer using `Gunicorn`_ with Gevent workers rather than using Gevent114directly. Gunicorn provides a much more configurable and115production-tested server. See the section on Gunicorn above.116117`Gevent`_ allows writing asynchronous, coroutine-based code that looks118like standard synchronous Python. It uses `greenlet`_ to enable task119switching without writing ``async/await`` or using ``asyncio``.120121It provides a WSGI server that can handle many connections at once122instead of one per worker process.123124`Eventlet`_, described below, is another library that does the same125thing. Certain dependencies you have, or other consideration, may affect126which of the two you choose to use127128To use gevent to serve your application, import its ``WSGIServer`` and129use it to run your ``app``.130131.. code-block:: python132133 from gevent.pywsgi import WSGIServer57 from yourapplication import app134 from your_project import app13559 http_server = WSGIServer(('', 5000), app)136 http_server = WSGIServer(("", 5000), app)137 http_server.serve_forever()13862.. _Gevent: http://www.gevent.org/63.. _greenlet: https://greenlet.readthedocs.io/en/latest/64.. _libev: http://software.schmorp.de/pkg/libev.html139140Eventlet141--------142143Prefer using `Gunicorn`_ with Eventlet workers rather than using144Eventlet directly. Gunicorn provides a much more configurable and145production-tested server. See the section on Gunicorn above.146147`Eventlet`_ allows writing asynchronous, coroutine-based code that looks148like standard synchronous Python. It uses `greenlet`_ to enable task149switching without writing ``async/await`` or using ``asyncio``.150151It provides a WSGI server that can handle many connections at once152instead of one per worker process.153154`Gevent`_, described above, is another library that does the same155thing. Certain dependencies you have, or other consideration, may affect156which of the two you choose to use157158To use eventlet to serve your application, import its ``wsgi.server``159and use it to run your ``app``.160161.. code-block:: python162163 import eventlet164 from eventlet import wsgi165 from your_project import app166167 wsgi.server(eventlet.listen(("", 5000), app)168169170Twisted Web171-----------172173`Twisted Web`_ is the web server shipped with `Twisted`_, a mature,174non-blocking event-driven networking library. Twisted Web comes with a175standard WSGI container which can be controlled from the command line using72the ``twistd`` utility::176the ``twistd`` utility:177178.. code-block:: text179180 $ twistd web --wsgi myproject.app181182This example will run a Flask application called ``app`` from a module named183``myproject``.184185Twisted Web supports many flags and options, and the ``twistd`` utility does186as well; see ``twistd -h`` and ``twistd web -h`` for more information. For187example, to run a Twisted Web server in the foreground, on port 8080, with an82application from ``myproject``::188application from ``myproject``:189190.. code-block:: text191192 $ twistd -n web --port tcp:8080 --wsgi myproject.app193194.. _Twisted: https://twistedmatrix.com/trac/195.. _Twisted Web: https://twistedmatrix.com/trac/wiki/TwistedWeb196197198.. _deploying-proxy-setups:199200Proxy Setups201------------
61 unmodified lines
modified:docs/async-await.rst+7 added-2 removed
5 unmodified lines
6.. versionadded:: 2.078Routes, error handlers, before request, after request, and teardown9functions can all be coroutine functions if Flask is installed with the10``async`` extra (``pip install flask[async]``). It requires Python 3.7+11where ``contextvars.ContextVar`` is available. This allows views to be10``async`` extra (``pip install flask[async]``). This allows views to be11defined with ``async def`` and use ``await``.1213.. code-block:: python14
13 unmodified lines
28 Python 3.8 has a bug related to asyncio on Windows. If you encounter29 something like ``ValueError: set_wakeup_fd only works in main thread``,30 please upgrade to Python 3.9.3132.. admonition:: Using ``async`` with greenlet3334 When using gevent or eventlet to serve an application or patch the35 runtime, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is36 required.373839Performance40-----------4142Async functions require an event loop to run. Flask, as a WSGI
89 unmodified lines
modified:docs/cli.rst+3 added-4 removed
110 unmodified lines
111shell with the :func:`shell <cli.shell_command>` command. An application112context will be active, and the app instance will be imported. ::113114 $ flask shell115 Python 3.6.2 (default, Jul 20 2017, 03:52:27)116 [GCC 7.1.1 20170630] on linux117 App: example118 Instance: /home/user/Projects/hello/instance115 Python 3.10.0 (default, Oct 27 2021, 06:59:51) [GCC 11.1.0] on linux116 App: example [production]117 Instance: /home/david/Projects/pallets/flask/instance118 >>>119120Use :meth:`~Flask.shell_context_processor` to add other automatic imports.121
532 unmodified lines
modified:docs/extensiondev.rst+3 added-3 removed
320 unmodified lines
3216. The documentation must use the ``flask`` theme from the322 `Official Pallets Themes`_. A link to the documentation or project323 website must be in the PyPI metadata or the readme.3247. For maximum compatibility, the extension should support the same325 versions of Python that Flask supports. 3.6+ is recommended as of326 2020. Use ``python_requires=">= 3.6"`` in ``setup.py`` to indicate327 supported versions.325 versions of Python that Flask supports. 3.7+ is recommended as of326 December 2021. Use ``python_requires=">= 3.7"`` in ``setup.py`` to327 indicate supported versions.328329.. _PyPI: https://pypi.org/search/?c=Framework+%3A%3A+Flask330.. _mailinglist: https://mail.python.org/mailman/listinfo/flask331.. _Discord server: https://discord.gg/pallets
1 unmodified line
modified:docs/installation.rst+13 added-3 removed
4 unmodified lines
5Python Version6--------------78We recommend using the latest version of Python. Flask supports Python93.6 and newer.93.7 and newer.1011``async`` support in Flask requires Python 3.7+ for ``contextvars.ContextVar``.111312Dependencies13------------1415These distributions will be installed automatically when installing Flask.
32 unmodified lines
48.. _python-dotenv: https://github.com/theskumar/python-dotenv#readme49.. _watchdog: https://pythonhosted.org/watchdog/505152greenlet53~~~~~~~~5455You may choose to use gevent or eventlet with your application. In this56case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is57required.5859These are not minimum supported versions, they only indicate the first60versions that added necessary features. You should use the latest61versions of each.626364Virtual environments65--------------------6667Use a virtual environment to manage the dependencies for your project, both in
78 unmodified lines
modified:requirements/dev.txt+1 added-1 removed
36 unmodified lines
37filelock==3.3.238 # via39 # tox40 # virtualenv41greenlet==1.1.241greenlet==1.1.2 ; python_version < "3.11"42 # via -r requirements/tests.in43identify==2.3.344 # via pre-commit45idna==3.3
118 unmodified lines
modified:requirements/tests.in+1 added-1 removed
1pytest2asgiref3blinker4greenlet4greenlet ; python_version < "3.11"5python-dotenv
modified:requirements/tests.txt+1 added-1 removed
8 unmodified lines
9attrs==21.2.010 # via pytest11blinker==1.412 # via -r requirements/tests.in13greenlet==1.1.213greenlet==1.1.2 ; python_version < "3.11"14 # via -r requirements/tests.in15iniconfig==1.1.116 # via pytest17packaging==21.2
13 unmodified lines
modified:src/flask/json/__init__.py+1 added-6 removed
1import dataclasses2import decimal3import io4import json as _json5import typing as t
10 unmodified lines
16if t.TYPE_CHECKING:17 from ..app import Flask18 from ..wrappers import Response1919try:20 import dataclasses21except ImportError:22 # Python < 3.723 dataclasses = None # type: ignore202521class JSONEncoder(_json.JSONEncoder):22 """The default JSON encoder. Handles extra types compared to the23 built-in :class:`json.JSONEncoder`.24
328 unmodified lines
modified:src/flask/app.py-8 removed
14 unmodified lines
15from werkzeug.exceptions import BadRequest16from werkzeug.exceptions import BadRequestKeyError17from werkzeug.exceptions import HTTPException18from werkzeug.exceptions import InternalServerError19from werkzeug.local import ContextVar19from werkzeug.routing import BuildError20from werkzeug.routing import Map21from werkzeug.routing import MapAdapter22from werkzeug.routing import RequestRedirect
1596 unmodified lines
1619 raise RuntimeError(1620 "Install Flask with the 'async' extra in order to use async views."1621 ) from None16221624 # Check that Werkzeug isn't using its fallback ContextVar class.1625 if ContextVar.__module__ == "werkzeug.local":1626 raise RuntimeError(1627 "Async cannot be used with this combination of Python "1628 "and Greenlet versions."1629 )16301623 return asgiref_async_to_sync(func)16241625 def make_response(self, rv: ResponseReturnValue) -> Response:1626 """Convert the return value from a view function to an instance of
457 unmodified lines
modified:tests/test_async.py-11 removed
1import asyncio2import sys23import pytest45from flask import Blueprint
71 unmodified lines
7778 return app798082@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")81@pytest.mark.parametrize("path", ["/", "/home", "/bp/", "/view", "/methodview"])82def test_async_route(path, async_app):83 test_client = async_app.test_client()84 response = test_client.get(path)
1 unmodified line
86 response = test_client.post(path)87 assert b"POST" in response.get_data()888992@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")90@pytest.mark.parametrize("path", ["/error", "/bp/error"])91def test_async_error_handler(path, async_app):92 test_client = async_app.test_client()93 response = test_client.get(path)94 assert response.status_code == 4129596100@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")97def test_async_before_after_request():98 app_first_called = False99 app_before_called = False100 app_after_called = False
48 unmodified lines
149 assert app_after_called150 test_client.get("/bp/")151 assert bp_before_called152 assert bp_after_called157158159@pytest.mark.skipif(sys.version_info >= (3, 7), reason="should only raise Python < 3.7")160def test_async_runtime_error():161 app = Flask(__name__)162 with pytest.raises(RuntimeError):163 app.async_to_sync(None)
modified:tests/test_basic.py-2 removed
1import gc2import re3import sys3import time4import uuid5import weakref6from datetime import datetime
1314 unmodified lines
1321 rv = flask.make_response(flask.jsonify(msg), 200)1322 assert rv.mimetype == "application/vnd.api+json"132313241326@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")1325def test_json_dump_dataclass(app, req_ctx):1326 from dataclasses import make_dataclass13271328 Data = make_dataclass("Data", [("name", str)])
698 unmodified lines
modified:setup.cfg+2 added-2 removed
33 unmodified lines
34[options]35packages = find:36package_dir = = src37include_package_data = true38python_requires = >= 3.638python_requires = >= 3.739# Dependencies are in setup.py for GitHub's dependency graph.4041[options.packages.find]42where = src
44 unmodified lines
87 src/flask/__init__.py: F4018889[mypy]90files = src/flask91python_version = 3.691python_version = 3.792allow_redefinition = True93disallow_subclassing_any = True94# disallow_untyped_calls = True95# disallow_untyped_defs = True
22 unmodified lines
modified:tox.ini+1 added-1 removed
1[tox]2envlist =3 py3{11,10,9,8,7,6},pypy373 py3{11,10,9,8,7},pypy3{8,7}4 py39-click75 style6 typing7 docs
24 unmodified lines