mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-22 12:58:11 -05:00
Compare commits
2 Commits
use-extern
...
integrate-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
174a3e0976 | ||
|
|
2a0d5ee2af |
@@ -6,29 +6,13 @@ For that, you can use the `WSGIMiddleware` and use it to wrap your WSGI applicat
|
||||
|
||||
## Using `WSGIMiddleware` { #using-wsgimiddleware }
|
||||
|
||||
/// info
|
||||
|
||||
This requires installing `a2wsgi` for example with `pip install a2wsgi`.
|
||||
|
||||
///
|
||||
|
||||
You need to import `WSGIMiddleware` from `a2wsgi`.
|
||||
You need to import `WSGIMiddleware`.
|
||||
|
||||
Then wrap the WSGI (e.g. Flask) app with the middleware.
|
||||
|
||||
And then mount that under a path.
|
||||
|
||||
{* ../../docs_src/wsgi/tutorial001_py39.py hl[1,3,23] *}
|
||||
|
||||
/// note
|
||||
|
||||
Previously, it was recommended to use `WSGIMiddleware` from `fastapi.middleware.wsgi`, but it is now deprecated.
|
||||
|
||||
It’s advised to use the `a2wsgi` package instead. The usage remains the same.
|
||||
|
||||
Just ensure that you have the `a2wsgi` package installed and import `WSGIMiddleware` correctly from `a2wsgi`.
|
||||
|
||||
///
|
||||
{* ../../docs_src/wsgi/tutorial001_py39.py hl[2:3,3] *}
|
||||
|
||||
## Check it { #check-it }
|
||||
|
||||
|
||||
@@ -35,3 +35,11 @@ It can be imported from `fastapi`:
|
||||
```python
|
||||
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
||||
```
|
||||
|
||||
::: fastapi.middleware.wsgi.WSGIMiddleware
|
||||
|
||||
It can be imported from `fastapi`:
|
||||
|
||||
```python
|
||||
from fastapi.middleware.wsgi import WSGIMiddleware
|
||||
```
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from a2wsgi import WSGIMiddleware
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.wsgi import WSGIMiddleware
|
||||
from flask import Flask, request
|
||||
from markupsafe import escape
|
||||
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
from starlette.middleware.wsgi import (
|
||||
WSGIMiddleware as WSGIMiddleware,
|
||||
) # pragma: no cover # noqa
|
||||
from starlette.middleware.wsgi import WSGIMiddleware as WSGIMiddleware # noqa
|
||||
|
||||
@@ -178,7 +178,6 @@ tests = [
|
||||
"strawberry-graphql>=0.200.0,<1.0.0",
|
||||
"types-orjson==3.6.2",
|
||||
"types-ujson==5.10.0.20240515",
|
||||
"a2wsgi>=1.9.0,<=2.0.0",
|
||||
]
|
||||
translations = [
|
||||
"gitpython==3.1.45",
|
||||
|
||||
@@ -10,6 +10,7 @@ from typing import Annotated
|
||||
import git
|
||||
import typer
|
||||
import yaml
|
||||
from doc_parsing_utils import check_translation
|
||||
from github import Github
|
||||
from pydantic_ai import Agent
|
||||
from rich import print
|
||||
@@ -119,9 +120,30 @@ def translate_page(
|
||||
]
|
||||
)
|
||||
prompt = "\n\n".join(prompt_segments)
|
||||
print(f"Running agent for {out_path}")
|
||||
result = agent.run_sync(prompt)
|
||||
out_content = f"{result.output.strip()}\n"
|
||||
|
||||
MAX_ATTEMPTS = 3
|
||||
for attempt_no in range(1, MAX_ATTEMPTS + 1):
|
||||
print(f"Running agent for {out_path} (attempt {attempt_no}/{MAX_ATTEMPTS})")
|
||||
result = agent.run_sync(prompt)
|
||||
out_content = f"{result.output.strip()}\n"
|
||||
try:
|
||||
check_translation(
|
||||
doc_lines=out_content.splitlines(),
|
||||
en_doc_lines=original_content.splitlines(),
|
||||
lang_code=language,
|
||||
auto_fix=False,
|
||||
path=str(out_path),
|
||||
)
|
||||
break # Exit loop if no errors
|
||||
except ValueError as e:
|
||||
print(
|
||||
f"Translation check failed on attempt {attempt_no}/{MAX_ATTEMPTS}: {e}"
|
||||
)
|
||||
continue # Retry if not reached max attempts
|
||||
else: # Max retry attempts reached
|
||||
print(f"Translation failed for {out_path} after {MAX_ATTEMPTS} attempts")
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
print(f"Saving translation to {out_path}")
|
||||
out_path.write_text(out_content, encoding="utf-8", newline="\n")
|
||||
|
||||
|
||||
16
uv.lock
generated
16
uv.lock
generated
@@ -7,18 +7,6 @@ resolution-markers = [
|
||||
"python_full_version < '3.10'",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "a2wsgi"
|
||||
version = "1.10.10"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "typing-extensions", marker = "python_full_version < '3.11'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/9a/cb/822c56fbea97e9eee201a2e434a80437f6750ebcb1ed307ee3a0a7505b14/a2wsgi-1.10.10.tar.gz", hash = "sha256:a5bcffb52081ba39df0d5e9a884fc6f819d92e3a42389343ba77cbf809fe1f45", size = 18799, upload-time = "2025-06-18T09:00:10.843Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/02/d5/349aba3dc421e73cbd4958c0ce0a4f1aa3a738bc0d7de75d2f40ed43a535/a2wsgi-1.10.10-py3-none-any.whl", hash = "sha256:d2b21379479718539dc15fce53b876251a0efe7615352dfe49f6ad1bc507848d", size = 17389, upload-time = "2025-06-18T09:00:09.676Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ag-ui-protocol"
|
||||
version = "0.1.10"
|
||||
@@ -1070,7 +1058,6 @@ standard-no-fastapi-cloud-cli = [
|
||||
|
||||
[package.dev-dependencies]
|
||||
dev = [
|
||||
{ name = "a2wsgi" },
|
||||
{ name = "anyio", extra = ["trio"] },
|
||||
{ name = "black" },
|
||||
{ name = "cairosvg" },
|
||||
@@ -1144,7 +1131,6 @@ github-actions = [
|
||||
{ name = "smokeshow" },
|
||||
]
|
||||
tests = [
|
||||
{ name = "a2wsgi" },
|
||||
{ name = "anyio", extra = ["trio"] },
|
||||
{ name = "coverage", version = "7.10.7", source = { registry = "https://pypi.org/simple" }, extra = ["toml"], marker = "python_full_version < '3.10'" },
|
||||
{ name = "coverage", version = "7.13.1", source = { registry = "https://pypi.org/simple" }, extra = ["toml"], marker = "python_full_version >= '3.10'" },
|
||||
@@ -1211,7 +1197,6 @@ provides-extras = ["standard", "standard-no-fastapi-cloud-cli", "all"]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [
|
||||
{ name = "a2wsgi", specifier = ">=1.9.0,<=2.0.0" },
|
||||
{ name = "anyio", extras = ["trio"], specifier = ">=3.2.1,<5.0.0" },
|
||||
{ name = "black", specifier = "==25.1.0" },
|
||||
{ name = "cairosvg", specifier = "==2.8.2" },
|
||||
@@ -1281,7 +1266,6 @@ github-actions = [
|
||||
{ name = "smokeshow", specifier = ">=0.5.0" },
|
||||
]
|
||||
tests = [
|
||||
{ name = "a2wsgi", specifier = ">=1.9.0,<=2.0.0" },
|
||||
{ name = "anyio", extras = ["trio"], specifier = ">=3.2.1,<5.0.0" },
|
||||
{ name = "coverage", extras = ["toml"], specifier = ">=6.5.0,<8.0" },
|
||||
{ name = "dirty-equals", specifier = "==0.9.0" },
|
||||
|
||||
Reference in New Issue
Block a user