Developer's Flask Project Guide
Developer's Flask Project Guide
flask-without_docs.d ......................................................................................
.gitignore.............................................................................................5
.[Link] .................................................................................... 5
.editorconfig.........................................................................................5
.[Link].............................................................................5
.devcontainer............................................................................................
[Link]..............................................................................6
[Link].................................................................................6
[Link]..............................................................................................6
[Link] ................................................................................................ 7
[Link] ........................................................................................... 8
[Link]........................................................................................8
CODE_OF_CONDUCT.md..................................................................................10
.github...................................................................................................
pull_request_template.md........................................................................11
ISSUE_TEMPLATE ...............................................................................
[Link]............................................................................11
[Link].....................................................................................12
[Link]..................................................................................12
workflows.............................................................................................
[Link] ............................................................................... 12
[Link] ...................................................................................... 13
[Link].....................................................................................13
[Link]...................................................................................14
[Link] .................................................................................... 15
requirements............................................................................................
[Link]...........................................................................................18
[Link].............................................................................................18
[Link]...........................................................................................19
[Link]............................................................................................19
[Link] ......................................................................................... 19
[Link]......................................................................................19
[Link] ......................................................................................... 19
[Link] ......................................................................................... 19
[Link].....................................................................................20
[Link].....................................................................................20
[Link] ........................................................................................ 20
[Link]...........................................................................................21
[Link]............................................................................................22
examples ................................................................................................
celery.................................................................................................
make_celery.py ................................................................................ 25
[Link] ................................................................................ 25
[Link] ...................................................................................... 25
[Link]..............................................................................26
src .................................................................................................
task_app ......................................................................................
1
2
[Link].................................................................................26
[Link].................................................................................27
__init__.py..............................................................................27
templates...................................................................................
[Link]............................................................................28
javascript.............................................................................................
.gitignore.....................................................................................30
[Link] ................................................................................ 30
tests ...............................................................................................
[Link].................................................................................30
test_js_example.py ........................................................................ 31
[Link].....................................................................................31
[Link]....................................................................................32
js_example .......................................................................................
__init__.py.................................................................................32
[Link] .................................................................................... 32
templates ......................................................................................
[Link]..............................................................................33
[Link]...............................................................................33
[Link].................................................................................34
[Link]................................................................................34
tutorial...............................................................................................
.gitignore.....................................................................................35
[Link] ................................................................................ 35
[Link].....................................................................................36
[Link]....................................................................................37
tests ...............................................................................................
test_factory.py............................................................................37
[Link] .................................................................................... 37
test_db.py..................................................................................38
[Link].................................................................................38
test_auth.py................................................................................39
test_blog.py................................................................................40
flaskr ..............................................................................................
[Link]..................................................................................41
[Link]........................................................................................42
__init__.py.................................................................................42
static...........................................................................................
[Link]................................................................................43
[Link]......................................................................................45
[Link]......................................................................................47
templates ......................................................................................
[Link]................................................................................49
auth.........................................................................................
[Link]............................................................................49
[Link]........................................................................49
blog .........................................................................................
[Link] .......................................................................... 50
[Link] .......................................................................... 50
[Link]............................................................................50
[Link] .......................................................................................... 51
tests......................................................................................................
static .................................................................................................
[Link].....................................................................................73
[Link]....................................................................................73
[Link]....................................................................................73
3
test_subclassing.py..............................................................................74
templates.............................................................................................
nested .............................................................................................
[Link]..................................................................................74
[Link]........................................................................................74
simple_template.html ......................................................................... 74
template_filter.html ......................................................................... 74
context_template.html........................................................................74
template_test.html............................................................................74
_macro.html....................................................................................74
escaping_template.html.......................................................................74
non_escaping_template.txt ................................................................... 75
test_regression.py...............................................................................75
test_session_interface.py ...................................................................... 75
test_converters.py...............................................................................76
test_apps ............................................................................................
.flaskenv ...................................................................................... 76
.env ............................................................................................ 77
subdomaintestmodule............................................................................
static...........................................................................................
[Link]................................................................................77
__init__.py.................................................................................77
helloworld.........................................................................................
[Link]......................................................................................77
[Link] .................................................................................... 77
cliapp..............................................................................................
__init__.py.................................................................................77
[Link].................................................................................77
[Link].......................................................................................77
[Link].................................................................................77
[Link]..........................................................................78
inner1..........................................................................................
inner2.......................................................................................
__init__.py .......................................................................... 78
[Link]..............................................................................78
__init__.py..............................................................................78
[Link]..................................................................................78
blueprintapp......................................................................................
__init__.py.................................................................................78
apps............................................................................................
__init__.py..............................................................................78
frontend ....................................................................................
templates................................................................................
frontend..............................................................................
[Link] ..................................................................... 78
__init__.py .......................................................................... 79
admin.......................................................................................
templates................................................................................
admin.................................................................................
[Link] ..................................................................... 79
static.....................................................................................
[Link]...........................................................................79
css.....................................................................................
[Link]........................................................................79
__init__.py .......................................................................... 79
test_request.py .................................................................................. 79
4
test_json_tag.py.................................................................................80
test_logging.py .................................................................................. 82
test_async.py.....................................................................................83
test_instance_config.py.........................................................................85
type_check ..........................................................................................
typing_app_decorators.py .................................................................... 87
typing_error_handler.py......................................................................87
typing_route.py ............................................................................... 88
[Link].......................................................................................90
test_signals.py .................................................................................. 92
test_appctx.py....................................................................................94
test_views.py.....................................................................................97
test_config.py .................................................................................. 101
test_user_error_handler.py....................................................................105
test_reqctx.py .................................................................................. 109
test_json.py.....................................................................................114
test_helpers.py ................................................................................. 119
test_testing.py ................................................................................. 124
test_templating.py..............................................................................129
test_cli.py......................................................................................136
test_blueprints.py..............................................................................146
test_basic.py....................................................................................160
src........................................................................................................
flask...................................................................................................
[Link] ...................................................................................... 188
__main__.py...................................................................................188
[Link]....................................................................................188
[Link]....................................................................................188
[Link]....................................................................................189
__init__.py...................................................................................190
[Link] ..................................................................................... 191
[Link] ................................................................................ 192
[Link]..............................................................................194
[Link] ...................................................................................... 197
[Link] ................................................................................ 200
[Link]...................................................................................203
[Link]....................................................................................206
[Link] ..................................................................................... 211
[Link].........................................................................................216
[Link]...................................................................................222
json................................................................................................
__init__.py................................................................................228
[Link]................................................................................230
[Link]......................................................................................233
[Link]....................................................................................238
[Link].........................................................................................247
[Link].........................................................................................263
sansio..............................................................................................
[Link]..................................................................................285
[Link] ............................................................................. 285
[Link]................................................................................294
[Link]......................................................................................305
5
.gitignore
1 .idea/
2 .vscode/
3 .venv*/
4 venv*/
5 __pycache__/
6 dist/
7 .coverage*
8 htmlcov/
9 .tox/
10 docs/_build/
.[Link]
1 version: 2
2 build:
3 os: ubuntu-22.04
4 tools:
5 python: '3.12'
6 python:
7 install:
8 - requirements: requirements/[Link]
9 - method: pip
10 path: .
11 sphinx:
12 builder: dirhtml
13 fail_on_warning: true
.editorconfig
1 root = true
2
3 [*]
4 indent_style = space
5 indent_size = 4
6 insert_final_newline = true
7 trim_trailing_whitespace = true
8 end_of_line = lf
9 charset = utf-8
10 max_line_length = 88
11
12 [*.{css,html,js,json,jsx,scss,ts,tsx,yaml,yml}]
13 indent_size = 2
.[Link]
1 repos:
2 - repo: [Link]
3 rev: v0.7.3
4 hooks:
5 - id: ruff
6 - id: ruff-format
7 - repo: [Link]
8 rev: v5.0.0
9 hooks:
10 - id: check-merge-conflict
11 - id: debug-statements
12 - id: fix-byte-order-marker
13 - id: trailing-whitespace
14 - id: end-of-file-fixer
6
.devcontainer/[Link]
1 #!/bin/bash
2 set -e
3 python3 -m venv --upgrade-deps .venv
4 . .venv/bin/activate
5 pip install -r requirements/[Link]
6 pip install -e .
7 pre-commit install --install-hooks
.devcontainer/[Link]
1 {
2 "name": "pallets/flask",
3 "image": "[Link]/devcontainers/python:3",
4 "customizations": {
5 "vscode": {
6 "settings": {
7 "[Link]": "${workspaceFolder}/.venv",
8 "[Link]": true,
9 "[Link]": [
10 "-X",
11 "dev"
12 ]
13 }
14 }
15 },
16 "onCreateCommand": ".devcontainer/[Link]"
17 }
[Link]
1 # Flask
2
3 Flask is a lightweight [WSGI][] web application framework. It is designed
4 to make getting started quick and easy, with the ability to scale up to
5 complex applications. It began as a simple wrapper around [Werkzeug][]
6 and [Jinja][], and has become one of the most popular Python web
7 application frameworks.
8
9 Flask offers suggestions, but doesn't enforce any dependencies or
10 project layout. It is up to the developer to choose the tools and
11 libraries they want to use. There are many extensions provided by the
12 community that make adding new functionality easy.
13
14 [WSGI]: [Link]
15 [Werkzeug]: [Link]
16 [Jinja]: [Link]
17
18
19 ## A Simple Example
20
21 ```python
22 # save this as [Link]
23 from flask import Flask
24
25 app = Flask(__name__)
26
27 @[Link]("/")
28 def hello():
29 return "Hello, World!"
30 ```
31
32 ```
33 $ flask run
34 * Running on [Link] (Press CTRL+C to quit)
35 ```
36
7
37
38 ## Donate
39
40 The Pallets organization develops and supports Flask and the libraries
41 it uses. In order to grow the community of contributors and users, and
42 allow the maintainers to devote more time to the projects, [please
43 donate today][].
44
45 [please donate today]: [Link]
[Link]
1 [tox]
2 envlist =
3 py3{13,12,11,10,9}
4 pypy310
5 py313-min
6 py39-dev
7 style
8 typing
9 docs
10 skip_missing_interpreters = true
11
12 [testenv]
13 package = wheel
14 wheel_build_env = .pkg
15 envtmpdir = {toxworkdir}/tmp/{envname}
16 constrain_package_deps = true
17 use_frozen_constraints = true
18 deps =
19 -r requirements/[Link]
20 min: -r requirements/[Link]
21 dev: -r requirements/[Link]
22 commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs}
23
24 [testenv:style]
25 deps = pre-commit
26 skip_install = true
27 commands = pre-commit run --all-files
28
29 [testenv:typing]
30 deps = -r requirements/[Link]
31 commands =
32 mypy
33 pyright
34
35 [testenv:docs]
36 deps = -r requirements/[Link]
37 commands = sphinx-build -E -W -b dirhtml docs docs/_build/dirhtml
38
39 [testenv:update-actions]
40 labels = update
41 deps = gha-update
42 skip_install = true
43 commands = gha-update
44
45 [testenv:update-pre_commit]
46 labels = update
47 deps = pre-commit
48 skip_install = true
49 commands = pre-commit autoupdate -j4
50
51 [testenv:update-requirements]
52 labels = update
53 deps = pip-tools
54 skip_install = true
55 change_dir = requirements
56 commands =
57 pip-compile [Link] -q {posargs:-U}
58 pip-compile [Link] -q {posargs:-U}
8
[Link]
1 Copyright 2010 Pallets
2
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions are
5 met:
6
7 1. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 3. Neither the name of the copyright holder nor the names of its
15 contributors may be used to endorse or promote products derived from
16 this software without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[Link]
1 [project]
2 name = "Flask"
3 version = "3.1.0"
4 description = "A simple framework for building complex web applications."
5 readme = "[Link]"
6 license = {file = "[Link]"}
7 maintainers = [{name = "Pallets", email = "contact@[Link]"}]
8 classifiers = [
9 "Development Status :: 5 - Production/Stable",
10 "Environment :: Web Environment",
11 "Framework :: Flask",
12 "Intended Audience :: Developers",
13 "License :: OSI Approved :: BSD License",
14 "Operating System :: OS Independent",
15 "Programming Language :: Python",
16 "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
17 "Topic :: Internet :: WWW/HTTP :: WSGI",
18 "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
19 "Topic :: Software Development :: Libraries :: Application Frameworks",
20 "Typing :: Typed",
21 ]
22 requires-python = ">=3.9"
23 dependencies = [
24 "Werkzeug>=3.1",
25 "Jinja2>=3.1.2",
26 "itsdangerous>=2.2",
27 "click>=8.1.3",
28 "blinker>=1.9",
29 "importlib-metadata>=3.6; python_version < '3.10'",
30 ]
[Link] 9
31
32 [[Link]]
33 Donate = "[Link]
34 Documentation = "[Link]
35 Changes = "[Link]
36 Source = "[Link]
37 Chat = "[Link]
38
39 [[Link]-dependencies]
40 async = ["asgiref>=3.2"]
41 dotenv = ["python-dotenv"]
42
43 [[Link]]
44 flask = "[Link]:main"
45
46 [build-system]
47 requires = ["flit_core<4"]
48 build-backend = "flit_core.buildapi"
49
50 [[Link]]
51 name = "flask"
52
53 [[Link]]
54 include = [
55 "docs/",
56 "examples/",
57 "requirements/",
58 "tests/",
59 "[Link]",
60 "[Link]",
61 "[Link]",
62 ]
63 exclude = [
64 "docs/_build/",
65 ]
66
67 [[Link].ini_options]
68 testpaths = ["tests"]
69 filterwarnings = [
70 "error",
71 ]
72
73 [[Link]]
74 branch = true
75 source = ["flask", "tests"]
76
77 [[Link]]
78 source = ["src", "*/site-packages"]
79
80 [[Link]]
81 python_version = "3.9"
82 files = ["src/flask", "tests/type_check"]
83 show_error_codes = true
84 pretty = true
85 strict = true
86
87 [[[Link]]]
88 module = [
89 "asgiref.*",
90 "dotenv.*",
91 "cryptography.*",
92 "importlib_metadata",
93 ]
94 ignore_missing_imports = true
95
96 [[Link]]
97 pythonVersion = "3.9"
98 include = ["src/flask", "tests/type_check"]
99 typeCheckingMode = "basic"
100
101 [[Link]]
10
CODE_OF_CONDUCT.md
1 # Contributor Covenant Code of Conduct
2
3 ## Our Pledge
4
5 In the interest of fostering an open and welcoming environment, we as
6 contributors and maintainers pledge to making participation in our project and
7 our community a harassment-free experience for everyone, regardless of age, body
8 size, disability, ethnicity, sex characteristics, gender identity and expression,
9 level of experience, education, socio-economic status, nationality, personal
10 appearance, race, religion, or sexual identity and orientation.
11
12 ## Our Standards
13
14 Examples of behavior that contributes to creating a positive environment
15 include:
16
17 * Using welcoming and inclusive language
18 * Being respectful of differing viewpoints and experiences
19 * Gracefully accepting constructive criticism
20 * Focusing on what is best for the community
21 * Showing empathy towards other community members
22
23 Examples of unacceptable behavior by participants include:
24
25 * The use of sexualized language or imagery and unwelcome sexual attention or
26 advances
27 * Trolling, insulting/derogatory comments, and personal or political attacks
28 * Public or private harassment
29 * Publishing others' private information, such as a physical or electronic
30 address, without explicit permission
31 * Other conduct which could reasonably be considered inappropriate in a
32 professional setting
33
34 ## Our Responsibilities
35
36 Project maintainers are responsible for clarifying the standards of acceptable
37 behavior and are expected to take appropriate and fair corrective action in
38 response to any instances of unacceptable behavior.
39
40 Project maintainers have the right and responsibility to remove, edit, or
41 reject comments, commits, code, wiki edits, issues, and other contributions
42 that are not aligned to this Code of Conduct, or to ban temporarily or
43 permanently any contributor for other behaviors that they deem inappropriate,
44 threatening, offensive, or harmful.
11
45
46 ## Scope
47
48 This Code of Conduct applies both within project spaces and in public spaces
49 when an individual is representing the project or its community. Examples of
50 representing a project or community include using an official project e-mail
51 address, posting via an official social media account, or acting as an appointed
52 representative at an online or offline event. Representation of a project may be
53 further defined and clarified by project maintainers.
54
55 ## Enforcement
56
57 Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 reported by contacting the project team at report@[Link]. All
59 complaints will be reviewed and investigated and will result in a response that
60 is deemed necessary and appropriate to the circumstances. The project team is
61 obligated to maintain confidentiality with regard to the reporter of an incident.
62 Further details of specific enforcement policies may be posted separately.
63
64 Project maintainers who do not follow or enforce the Code of Conduct in good
65 faith may face temporary or permanent repercussions as determined by other
66 members of the project's leadership.
67
68 ## Attribution
69
70 This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 available at [Link]
72
73 [homepage]: [Link]
74
75 For answers to common questions about this code of conduct, see
76 [Link]
.github/pull_request_template.md
1 <!--
2 Before opening a PR, open a ticket describing the issue or feature the
3 PR will address. An issue is not required for fixing typos in
4 documentation, or other simple non-code changes.
5
6 Replace this comment with a description of the change. Describe how it
7 addresses the linked ticket.
8 -->
9
10 <!--
11 Link to relevant issues or previous PRs, one per line. Use "fixes" to
12 automatically close an issue.
13
14 fixes #<issue number>
15 -->
16
17 <!--
18 Ensure each step in [Link] is complete, especially the following:
19
20 - Add tests that demonstrate the correct behavior of the change. Tests
21 should fail without the change.
22 - Add or update relevant docs, in the docs folder and in code.
23 - Add an entry in [Link] summarizing the change and linking to the issue.
24 - Add `.. versionchanged::` entries in any relevant code docs.
25 -->
.github/ISSUE_TEMPLATE/[Link]
1 ---
2 name: Feature request
3 about: Suggest a new feature for Flask
4 ---
5
12
6 <!--
7 Replace this comment with a description of what the feature should do.
8 Include details such as links to relevant specs or previous discussions.
9 -->
10
11 <!--
12 Replace this comment with an example of the problem which this feature
13 would resolve. Is this problem solvable without changes to Flask, such
14 as by subclassing or using an extension?
15 -->
.github/ISSUE_TEMPLATE/[Link]
1 blank_issues_enabled: false
2 contact_links:
3 - name: Security issue
4 url: [Link]
5 about: Do not report security issues publicly. Create a private advisory.
6 - name: Questions
7 url: [Link]
8 about: Ask questions about your own code on the Discussions tab.
9 - name: Questions on
10 url: [Link]
11 about: Ask questions about your own code on our Discord chat.
.github/ISSUE_TEMPLATE/[Link]
1 ---
2 name: Bug report
3 about: Report a bug in Flask (not other projects which depend on Flask)
4 ---
5
6 <!--
7 This issue tracker is a tool to address bugs in Flask itself. Please use
8 GitHub Discussions or the Pallets Discord for questions about your own code.
9
10 Replace this comment with a clear outline of what the bug is.
11 -->
12
13 <!--
14 Describe how to replicate the bug.
15
16 Include a minimal reproducible example that demonstrates the bug.
17 Include the full traceback if there was an exception.
18 -->
19
20 <!--
21 Describe the expected behavior that should have happened but didn't.
22 -->
23
24 Environment:
25
26 - Python version:
27 - Flask version:
.github/workflows/[Link]
1 name: pre-commit
2 on:
3 pull_request:
4 push:
5 branches: [main, stable]
6 jobs:
7 main:
8 runs-on: ubuntu-latest
9 steps:
13
.github/workflows/[Link]
1 name: Lock inactive closed issues
2 # Lock closed issues that have not received any further activity for two weeks.
3 # This does not close open issues, only humans may do that. It is easier to
4 # respond to new issues with fresh examples rather than continuing discussions
5 # on old issues.
6
7 on:
8 schedule:
9 - cron: '0 0 * * *'
10 permissions:
11 issues: write
12 pull-requests: write
13 concurrency:
14 group: lock
15 jobs:
16 lock:
17 runs-on: ubuntu-latest
18 steps:
19 - uses: dessant/lock-threads@1bf7ec25051fe7c00bdd17e6a7cf3d7bfb7dc771 # v5.0.1
20 with:
21 issue-inactive-days: 14
22 pr-inactive-days: 14
23 discussion-inactive-days: 14
.github/workflows/[Link]
1 name: Tests
2 on:
3 push:
4 branches: [main, stable]
5 paths-ignore: ['docs/**', '*.md', '*.rst']
6 pull_request:
7 paths-ignore: [ 'docs/**', '*.md', '*.rst' ]
8 jobs:
9 tests:
10 name: ${{ [Link] || [Link] }}
11 runs-on: ${{ [Link] || 'ubuntu-latest' }}
12 strategy:
13 fail-fast: false
14 matrix:
15 include:
16 - {python: '3.13'}
17 - {python: '3.12'}
18 - {name: Windows, python: '3.12', os: windows-latest}
19 - {name: Mac, python: '3.12', os: macos-latest}
20 - {python: '3.11'}
21 - {python: '3.10'}
22 - {python: '3.9'}
23 - {name: PyPy, python: 'pypy-3.10', tox: pypy310}
24 - {name: Minimum Versions, python: '3.12', tox: py-min}
25 - {name: Development Versions, python: '3.9', tox: py-dev}
26 steps:
27 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28 - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
29 with:
30 python-version: ${{ [Link] }}
31 allow-prereleases: true
32 cache: pip
14
33 cache-dependency-path: requirements*/*.txt
34 - run: pip install tox
35 - run: tox run -e ${{ [Link] || format('py{0}', [Link]) }}
36 typing:
37 runs-on: ubuntu-latest
38 steps:
39 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
40 - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
41 with:
42 python-version: '3.x'
43 cache: pip
44 cache-dependency-path: requirements*/*.txt
45 - name: cache mypy
46 uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
47 with:
48 path: ./.mypy_cache
49 key: mypy|${{ hashFiles('[Link]') }}
50 - run: pip install tox
51 - run: tox run -e typing
.github/workflows/[Link]
1 name: Publish
2 on:
3 push:
4 tags:
5 - '*'
6 jobs:
7 build:
8 runs-on: ubuntu-latest
9 outputs:
10 hash: ${{ [Link] }}
11 steps:
12 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
13 - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
14 with:
15 python-version: '3.x'
16 cache: pip
17 cache-dependency-path: requirements*/*.txt
18 - run: pip install -r requirements/[Link]
19 # Use the commit date instead of the current date during the build.
20 - run: echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
21 - run: python -m build
22 # Generate hashes used for provenance.
23 - name: generate hash
24 id: hash
25 run: cd dist && echo "hash=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT
26 - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
27 with:
28 path: ./dist
29 provenance:
30 needs: [build]
31 permissions:
32 actions: read
33 id-token: write
34 contents: write
35 # Can't pin with hash due to how this workflow works.
36 uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
37 with:
38 base64-subjects: ${{ [Link] }}
39 create-release:
40 # Upload the sdist, wheels, and provenance to a GitHub release. They remain
41 # available as build artifacts for a while as well.
42 needs: [provenance]
43 runs-on: ubuntu-latest
44 permissions:
45 contents: write
46 steps:
47 - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
48 - name: create release
15
49 run: >
50 gh release create --draft --repo ${{ [Link] }}
51 ${{ github.ref_name }}
52 *.[Link]/* artifact/*
53 env:
54 GH_TOKEN: ${{ [Link] }}
55 publish-pypi:
56 needs: [provenance]
57 # Wait for approval before attempting to upload to PyPI. This allows reviewing the
58 # files in the draft release.
59 environment:
60 name: publish
61 url: [Link] github.ref_name }}
62 runs-on: ubuntu-latest
63 permissions:
64 id-token: write
65 steps:
66 - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
67 - uses: pypa/gh-action-pypi-publish@15c56dba361d8335944d31a2ecd17d700fc7bcbc # v1.12.2
68 with:
69 packages-dir: artifact/
[Link]
1 How to contribute to Flask
2 ==========================
3
4 Thank you for considering contributing to Flask!
5
6
7 Support questions
8 -----------------
9
10 Please don't use the issue tracker for this. The issue tracker is a tool
11 to address bugs and feature requests in Flask itself. Use one of the
12 following resources for questions about using Flask or issues with your
13 own code:
14
15 - The ``#questions`` channel on our Discord chat:
16 [Link]
17 - Ask on `Stack Overflow`_. Search with Google first using:
18 ``site:[Link] flask {search term, exception message, etc.}``
19 - Ask on our `GitHub Discussions`_ for long term discussion or larger
20 questions.
21
22 .. _Stack Overflow: [Link]
23 .. _GitHub Discussions: [Link]
24
25
26 Reporting issues
27 ----------------
28
29 Include the following information in your post:
30
31 - Describe what you expected to happen.
32 - If possible, include a `minimal reproducible example`_ to help us
33 identify the issue. This also helps check that the issue is not with
34 your own code.
35 - Describe what actually happened. Include the full traceback if there
36 was an exception.
37 - List your Python and Flask versions. If possible, check if this
38 issue is already fixed in the latest releases or the latest code in
39 the repository.
40
41 .. _minimal reproducible example: [Link]
42
43
44 Submitting patches
45 ------------------
46
[Link] 16
47 If there is not an open issue for what you want to submit, prefer
48 opening one for discussion before working on a PR. You can work on any
49 issue that doesn't have an open PR linked to it or a maintainer assigned
50 to it. These show up in the sidebar. No need to ask if you can work on
51 an issue that interests you.
52
53 Include the following in your patch:
54
55 - Use `Black`_ to format your code. This and other tools will run
56 automatically if you install `pre-commit`_ using the instructions
57 below.
58 - Include tests if your patch adds or changes code. Make sure the test
59 fails without your patch.
60 - Update any relevant docs pages and docstrings. Docs pages and
61 docstrings should be wrapped at 72 characters.
62 - Add an entry in ``[Link]``. Use the same style as other
63 entries. Also include ``.. versionchanged::`` inline changelogs in
64 relevant docstrings.
65
66 .. _Black: [Link]
67 .. _pre-commit: [Link]
68
69
70 First time setup using GitHub Codespaces
71 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
73 `GitHub Codespaces`_ creates a development environment that is already set up for the
74 project. By default it opens in Visual Studio Code for the Web, but this can
75 be changed in your GitHub profile settings to use Visual Studio Code or JetBrains
76 PyCharm on your local computer.
77
78 - Make sure you have a `GitHub account`_.
79 - From the project's repository page, click the green "Code" button and then "Create
80 codespace on main".
81 - The codespace will be set up, then Visual Studio Code will open. However, you'll
82 need to wait a bit longer for the Python extension to be installed. You'll know it's
83 ready when the terminal at the bottom shows that the virtualenv was activated.
84 - Check out a branch and `start coding`_.
85
86 .. _GitHub Codespaces: [Link]
87 .. _devcontainer:
,→ [Link]
88
89 First time setup in your local environment
90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91
92 - Make sure you have a `GitHub account`_.
93 - Download and install the `latest version of git`_.
94 - Configure git with your `username`_ and `email`_.
95
96 .. code-block:: text
97
98 $ git config --global [Link] 'your name'
99 $ git config --global [Link] 'your email'
100
101 - Fork Flask to your GitHub account by clicking the `Fork`_ button.
102 - `Clone`_ your fork locally, replacing ``your-username`` in the command below with
103 your actual username.
104
105 .. code-block:: text
106
107 $ git clone [Link]
108 $ cd flask
109
110 - Create a virtualenv. Use the latest version of Python.
111
112 - Linux/macOS
113
114 .. code-block:: text
115
116 $ python3 -m venv .venv
[Link] 17
117 $ . .venv/bin/activate
118
119 - Windows
120
121 .. code-block:: text
122
123 > py -3 -m venv .venv
124 > .venv\Scripts\activate
125
126 - Install the development dependencies, then install Flask in editable mode.
127
128 .. code-block:: text
129
130 $ python -m pip install -U pip
131 $ pip install -r requirements/[Link] && pip install -e .
132
133 - Install the pre-commit hooks.
134
135 .. code-block:: text
136
137 $ pre-commit install --install-hooks
138
139 .. _GitHub account: [Link]
140 .. _latest version of git: [Link]
141 .. _username: [Link]
142 .. _email:
,→ [Link]
143 .. _Fork: [Link]
144 .. _Clone:
,→ [Link]
145
146 .. _start coding:
147
148 Start coding
149 ~~~~~~~~~~~~
150
151 - Create a branch to identify the issue you would like to work on. If you're
152 submitting a bug or documentation fix, branch off of the latest ".x" branch.
153
154 .. code-block:: text
155
156 $ git fetch origin
157 $ git checkout -b your-branch-name origin/2.0.x
158
159 If you're submitting a feature addition or change, branch off of the "main" branch.
160
161 .. code-block:: text
162
163 $ git fetch origin
164 $ git checkout -b your-branch-name origin/main
165
166 - Using your favorite editor, make your changes, `committing as you go`_.
167
168 - If you are in a codespace, you will be prompted to `create a fork`_ the first
169 time you make a commit. Enter ``Y`` to continue.
170
171 - Include tests that cover any code changes you make. Make sure the test fails without
172 your patch. Run the tests as described below.
173 - Push your commits to your fork on GitHub and `create a pull request`_. Link to the
174 issue being addressed with ``fixes #123`` in the pull request description.
175
176 .. code-block:: text
177
178 $ git push --set-upstream origin your-branch-name
179
180 .. _committing as you go:
,→ [Link]
181 .. _create a fork:
,→ [Link]
182 .. _create a pull request:
,→ [Link]
18
183
184 .. _Running the tests:
185
186 Running the tests
187 ~~~~~~~~~~~~~~~~~
188
189 Run the basic test suite with pytest.
190
191 .. code-block:: text
192
193 $ pytest
194
195 This runs the tests for the current environment, which is usually
196 sufficient. CI will run the full suite when you submit your pull
197 request. You can run the full test suite with tox if you don't want to
198 wait.
199
200 .. code-block:: text
201
202 $ tox
203
204
205 Running test coverage
206 ~~~~~~~~~~~~~~~~~~~~~
207
208 Generating a report of lines that do not have test coverage can indicate
209 where to start contributing. Run ``pytest`` using ``coverage`` and
210 generate a report.
211
212 If you are using GitHub Codespaces, ``coverage`` is already installed
213 so you can skip the installation command.
214
215 .. code-block:: text
216
217 $ pip install coverage
218 $ coverage run -m pytest
219 $ coverage html
220
221 Open ``htmlcov/[Link]`` in your browser to explore the report.
222
223 Read more about `coverage <[Link]
224
225
226 Building the docs
227 ~~~~~~~~~~~~~~~~~
228
229 Build the docs in the ``docs`` directory using Sphinx.
230
231 .. code-block:: text
232
233 $ cd docs
234 $ make html
235
236 Open ``_build/html/[Link]`` in your browser to view the docs.
237
238 Read more about `Sphinx <[Link]
requirements/[Link]
1 build
requirements/[Link]
1 -r [Link]
2 -r [Link]
3 -r [Link]
4 pre-commit
5 tox
19
requirements/[Link]
1 pytest
2 asgiref
3 greenlet ; python_version < "3.11"
4 python-dotenv
requirements/[Link]
1 pallets-sphinx-themes
2 sphinx
3 sphinxcontrib-log-cabinet
4 sphinx-tabs
requirements/[Link]
1 mypy
2 pyright
3 pytest
4 types-contextvars
5 types-dataclasses
6 asgiref
7 cryptography
8 python-dotenv
requirements/[Link]
1 werkzeug==3.1.0
2 jinja2==3.1.2
3 markupsafe==2.1.1
4 itsdangerous==2.2.0
5 click==8.1.3
6 blinker==1.9.0
requirements/[Link]
1 #
2 # This file is autogenerated by pip-compile with Python 3.13
3 # by the following command:
4 #
5 # pip-compile [Link]
6 #
7 build==1.2.2.post1
8 # via -r [Link]
9 packaging==24.2
10 # via build
11 pyproject-hooks==1.2.0
12 # via build
requirements/[Link]
1 #
2 # This file is autogenerated by pip-compile with Python 3.13
3 # by the following command:
4 #
5 # pip-compile [Link]
6 #
7 asgiref==3.8.1
8 # via -r [Link]
9 iniconfig==2.0.0
10 # via pytest
11 packaging==24.2
20
12 # via pytest
13 pluggy==1.5.0
14 # via pytest
15 pytest==8.3.3
16 # via -r [Link]
17 python-dotenv==1.0.1
18 # via -r [Link]
requirements/[Link]
1 [Link]
2 [Link]
3 [Link]
4 [Link]
5 [Link]
6 [Link]
requirements/[Link]
1 #
2 # This file is autogenerated by pip-compile with Python 3.13
3 # by the following command:
4 #
5 # pip-compile [Link]
6 #
7 blinker==1.9.0
8 # via -r [Link]
9 click==8.1.3
10 # via -r [Link]
11 itsdangerous==2.2.0
12 # via -r [Link]
13 jinja2==3.1.2
14 # via -r [Link]
15 markupsafe==2.1.1
16 # via
17 # -r [Link]
18 # jinja2
19 # werkzeug
20 werkzeug==3.1.0
21 # via -r [Link]
requirements/[Link]
1 #
2 # This file is autogenerated by pip-compile with Python 3.13
3 # by the following command:
4 #
5 # pip-compile [Link]
6 #
7 asgiref==3.8.1
8 # via -r [Link]
9 cffi==1.17.1
10 # via cryptography
11 cryptography==43.0.3
12 # via -r [Link]
13 iniconfig==2.0.0
14 # via pytest
15 mypy==1.13.0
16 # via -r [Link]
17 mypy-extensions==1.0.0
18 # via mypy
19 nodeenv==1.9.1
20 # via pyright
21 packaging==24.2
22 # via pytest
23 pluggy==1.5.0
21
24 # via pytest
25 pycparser==2.22
26 # via cffi
27 pyright==1.1.389
28 # via -r [Link]
29 pytest==8.3.3
30 # via -r [Link]
31 python-dotenv==1.0.1
32 # via -r [Link]
33 types-contextvars==[Link]
34 # via -r [Link]
35 types-dataclasses==0.6.6
36 # via -r [Link]
37 typing-extensions==4.12.2
38 # via
39 # mypy
40 # pyright
requirements/[Link]
1 #
2 # This file is autogenerated by pip-compile with Python 3.13
3 # by the following command:
4 #
5 # pip-compile [Link]
6 #
7 alabaster==1.0.0
8 # via sphinx
9 babel==2.16.0
10 # via sphinx
11 certifi==2024.8.30
12 # via requests
13 charset-normalizer==3.4.0
14 # via requests
15 docutils==0.21.2
16 # via
17 # sphinx
18 # sphinx-tabs
19 idna==3.10
20 # via requests
21 imagesize==1.4.1
22 # via sphinx
23 jinja2==3.1.4
24 # via sphinx
25 markupsafe==3.0.2
26 # via jinja2
27 packaging==24.2
28 # via
29 # pallets-sphinx-themes
30 # sphinx
31 pallets-sphinx-themes==2.3.0
32 # via -r [Link]
33 pygments==2.18.0
34 # via
35 # sphinx
36 # sphinx-tabs
37 requests==2.32.3
38 # via sphinx
39 snowballstemmer==2.2.0
40 # via sphinx
41 sphinx==8.1.3
42 # via
43 # -r [Link]
44 # pallets-sphinx-themes
45 # sphinx-notfound-page
46 # sphinx-tabs
47 # sphinxcontrib-log-cabinet
48 sphinx-notfound-page==1.0.4
49 # via pallets-sphinx-themes
50 sphinx-tabs==3.4.7
22
51 # via -r [Link]
52 sphinxcontrib-applehelp==2.0.0
53 # via sphinx
54 sphinxcontrib-devhelp==2.0.0
55 # via sphinx
56 sphinxcontrib-htmlhelp==2.1.0
57 # via sphinx
58 sphinxcontrib-jsmath==1.0.1
59 # via sphinx
60 sphinxcontrib-log-cabinet==1.0.1
61 # via -r [Link]
62 sphinxcontrib-qthelp==2.0.0
63 # via sphinx
64 sphinxcontrib-serializinghtml==2.0.0
65 # via sphinx
66 urllib3==2.2.3
67 # via requests
requirements/[Link]
1 #
2 # This file is autogenerated by pip-compile with Python 3.13
3 # by the following command:
4 #
5 # pip-compile [Link]
6 #
7 alabaster==1.0.0
8 # via
9 # -r /Users/david/Projects/flask/requirements/[Link]
10 # sphinx
11 asgiref==3.8.1
12 # via
13 # -r /Users/david/Projects/flask/requirements/[Link]
14 # -r /Users/david/Projects/flask/requirements/[Link]
15 babel==2.16.0
16 # via
17 # -r /Users/david/Projects/flask/requirements/[Link]
18 # sphinx
19 cachetools==5.5.0
20 # via tox
21 certifi==2024.8.30
22 # via
23 # -r /Users/david/Projects/flask/requirements/[Link]
24 # requests
25 cffi==1.17.1
26 # via
27 # -r /Users/david/Projects/flask/requirements/[Link]
28 # cryptography
29 cfgv==3.4.0
30 # via pre-commit
31 chardet==5.2.0
32 # via tox
33 charset-normalizer==3.4.0
34 # via
35 # -r /Users/david/Projects/flask/requirements/[Link]
36 # requests
37 colorama==0.4.6
38 # via tox
39 cryptography==43.0.3
40 # via -r /Users/david/Projects/flask/requirements/[Link]
41 distlib==0.3.9
42 # via virtualenv
43 docutils==0.21.2
44 # via
45 # -r /Users/david/Projects/flask/requirements/[Link]
46 # sphinx
47 # sphinx-tabs
48 filelock==3.16.1
49 # via
50 # tox
requirements/[Link] 23
51 # virtualenv
52 identify==2.6.2
53 # via pre-commit
54 idna==3.10
55 # via
56 # -r /Users/david/Projects/flask/requirements/[Link]
57 # requests
58 imagesize==1.4.1
59 # via
60 # -r /Users/david/Projects/flask/requirements/[Link]
61 # sphinx
62 iniconfig==2.0.0
63 # via
64 # -r /Users/david/Projects/flask/requirements/[Link]
65 # -r /Users/david/Projects/flask/requirements/[Link]
66 # pytest
67 jinja2==3.1.4
68 # via
69 # -r /Users/david/Projects/flask/requirements/[Link]
70 # sphinx
71 markupsafe==3.0.2
72 # via
73 # -r /Users/david/Projects/flask/requirements/[Link]
74 # jinja2
75 mypy==1.13.0
76 # via -r /Users/david/Projects/flask/requirements/[Link]
77 mypy-extensions==1.0.0
78 # via
79 # -r /Users/david/Projects/flask/requirements/[Link]
80 # mypy
81 nodeenv==1.9.1
82 # via
83 # -r /Users/david/Projects/flask/requirements/[Link]
84 # pre-commit
85 # pyright
86 packaging==24.2
87 # via
88 # -r /Users/david/Projects/flask/requirements/[Link]
89 # -r /Users/david/Projects/flask/requirements/[Link]
90 # -r /Users/david/Projects/flask/requirements/[Link]
91 # pallets-sphinx-themes
92 # pyproject-api
93 # pytest
94 # sphinx
95 # tox
96 pallets-sphinx-themes==2.3.0
97 # via -r /Users/david/Projects/flask/requirements/[Link]
98 platformdirs==4.3.6
99 # via
100 # tox
101 # virtualenv
102 pluggy==1.5.0
103 # via
104 # -r /Users/david/Projects/flask/requirements/[Link]
105 # -r /Users/david/Projects/flask/requirements/[Link]
106 # pytest
107 # tox
108 pre-commit==4.0.1
109 # via -r [Link]
110 pycparser==2.22
111 # via
112 # -r /Users/david/Projects/flask/requirements/[Link]
113 # cffi
114 pygments==2.18.0
115 # via
116 # -r /Users/david/Projects/flask/requirements/[Link]
117 # sphinx
118 # sphinx-tabs
119 pyproject-api==1.8.0
120 # via tox
121 pyright==1.1.389
requirements/[Link] 24
193 # -r /Users/david/Projects/flask/requirements/[Link]
194 # requests
195 virtualenv==20.27.1
196 # via
197 # pre-commit
198 # tox
examples/celery/make_celery.py
1 from task_app import create_app
2
3 flask_app = create_app()
4 celery_app = flask_app.extensions["celery"]
examples/celery/[Link]
1 [project]
2 name = "flask-example-celery"
3 version = "1.0.0"
4 description = "Example Flask application with Celery background tasks."
5 readme = "[Link]"
6 classifiers = ["Private :: Do Not Upload"]
7 dependencies = ["flask", "celery[redis]"]
8
9 [build-system]
10 requires = ["flit_core<4"]
11 build-backend = "flit_core.buildapi"
12
13 [[Link]]
14 name = "task_app"
15
16 [[Link]]
17 src = ["src"]
examples/celery/[Link]
1 Background Tasks with Celery
2 ============================
3
4 This example shows how to configure Celery with Flask, how to set up an API for
5 submitting tasks and polling results, and how to use that API with JavaScript. See
6 [Flask's documentation about Celery]([Link]
7
8 From this directory, create a virtualenv and install the application into it. Then run a
9 Celery worker.
10
11 ```shell
12 $ python3 -m venv .venv
13 $ . ./.venv/bin/activate
14 $ pip install -r [Link] && pip install -e .
15 $ celery -A make_celery worker --loglevel INFO
16 ```
17
18 In a separate terminal, activate the virtualenv and run the Flask development server.
19