Application
This is the source repository for Flask, the Python WSGI micro web framework. It contains the complete framework implementation (src/flask), its comprehensive test suite (tests), official example applications (Flaskr blog tutorial, JavaScript frontend integration, Celery task queue integration), and Sphinx documentation. This is the actual upstream Flask project that gets published to PyPI as the 'flask' package.
Key Features
- WSGI Application Core
- Sans-IO Base Architecture
- Blueprint System
- Context Management
- Signed Cookie Sessions
- Click CLI Infrastructure
- Multi-Source Configuration
- Async Route Support
- Signal System
- Flaskr Tutorial App
Coding Conventions
Standards and patterns used in this codebase
Use lazy imports via module-level __getattr__ for expensive or optional dependencies to improve startup time
In __init__.py, re-export all public API symbols explicitly, and use __getattr__ patterns for deferred loading of heavy modulesSeparate sans-IO (protocol-independent) base logic from WSGI-specific implementation using inheritance, placing base classes in sansio/ subpackage
flask/sansio/app.py contains App base class with routing and config logic; flask/app.py contains Flask(App) with WSGI-specific request handlingUse __future__ annotations import and provide full type hints on public API methods, with dedicated type checking tests to validate annotations
from __future__ import annotations at top of every module; tests/type_check/ contains static type validation filesUse pytest fixtures in conftest.py for test setup; provide reusable app and client fixtures; use fixture apps in tests/test_apps/ for integration scenarios
conftest.py defines app, app_ctx, req_ctx, and client fixtures; test apps are standalone packages under tests/test_apps/Use context-local proxy objects (via werkzeug.local.LocalProxy) for global-like access to request, app, session, and g, backed by context stacks
current_app, request, session, g are all LocalProxy objects defined in globals.py that look up values from the current contextUse decorator-based registration patterns for routes, error handlers, before/after request hooks, and CLI commands
@app.route('/path'), @app.errorhandler(404), @app.before_request, @app.cli.command()Support multiple configuration sources (mapping, Python files, TOML files, environment variables, prefixed env vars) through a Config class extending dict
Config class provides from_mapping(), from_file(), from_object(), from_prefixed_env() methods for flexible config loadingUse Sphinx with intersphinx mappings, custom extensions (singlehtml builder, github link tab), and pallets-sphinx-themes for documentation
docs/conf.py configures intersphinx for Python, Werkzeug, Click, Jinja, MarkupSafe, SQLAlchemy and uses version info from importlib.metadataKeep __main__.py minimal as a CLI entry point, delegating immediately to the CLI module's main function
from flask.cli import main; main()Use custom exception classes and convert HTTP exceptions from Werkzeug; provide both errorhandler decorator and register_error_handler method patterns
App handles HTTPException, unhandled exceptions via handle_exception/handle_http_exception methods with signal support for got_request_exceptionUse snake_case for functions, methods, and variables; PascalCase for classes; prefix internal/private attributes with underscore
class Flask, class Blueprint, def make_response, def _get_exc_class_and_code, _request_ctx_stackUse blinker-based signals for extensibility hooks, with named signals created via Namespace and graceful degradation when blinker is unavailable
request_started, request_finished, template_rendered, got_request_exception signals defined in signals module