Skip to content

Commit 79c7b78

Browse files
fix: update FastAPI to 0.112.2 (#1736)
* refactor: new FastAPI integration syntax * lint: fix confluent topic mypy * docs: generate API References * docs: fix FastAPI integration section * docs: make annotation private * chore: update FastAPI * lint: fix precommit * chore: trigger CI * chore: revert CI triggers --------- Co-authored-by: Lancetnik <[email protected]> Co-authored-by: Davor Runje <[email protected]>
1 parent 4944180 commit 79c7b78

File tree

42 files changed

+108
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+108
-136
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class Incoming(BaseModel):
318318
async def hello(m: Incoming):
319319
return {"response": "Hello, world!"}
320320

321-
app = FastAPI(lifespan=router.lifespan_context)
321+
app = FastAPI()
322322
app.include_router(router)
323323
```
324324

docs/create_api_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def create_api_docs(
346346

347347
def on_page_markdown(markdown, *, page, config, files):
348348
"""Mkdocs hook to update the edit URL for the public API pages."""
349-
if "public_api" in page.edit_url:
349+
if page.edit_url and "public_api" in page.edit_url:
350350
page.edit_url = page.edit_url.replace("public_api", "api")
351351

352352

docs/docs/en/getting-started/integrations/fastapi/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Just import a **StreamRouter** you need and declare the message handler in the s
2626

2727
{! includes/getting_started/integrations/fastapi/1.md !}
2828

29+
!!! warning
30+
If you are using **fastapi < 0.102.2** version, you should setup lifespan manually `#!python FastAPI(lifespan=router.lifespan_context)`
31+
2932
When processing a message from a broker, the entire message body is placed simultaneously in both the `body` and `path` request parameters. You can access them in any way convenient for you. The message header is placed in `headers`.
3033

3134
Also, this router can be fully used as an `HttpRouter` (of which it is the inheritor). So, you can
@@ -100,7 +103,7 @@ This way the core router collects all nested routers publishers and subscribers
100103

101104
### Custom lifespan
102105

103-
Otherwise, if you want to has multiple connections to different broker instances, you should start routers independently in your custom lifespan
106+
Otherwise, if you want to has multiple connections to different broker instances, you can just include them separately to the app (each router has own broker and connection in this case)
104107

105108
{! includes/getting_started/integrations/fastapi/multiple_lifespan.md !}
106109

docs/docs/en/release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ hide:
1818

1919
The current release is planned as a latest feature release before **0.6.0**. All other **0.5.19+** releases will contain only minor bugfixes and all the team work will be focused on next major one.
2020

21-
There a lot of changes we want to present you now though!
21+
There's a lot of changes we want to present you now though!
2222

2323
#### New RPC feature
2424

docs/docs_src/integrations/fastapi/confluent/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ async def hello(m: Incoming, logger: Logger, d=Depends(call)):
2121
async def hello_http():
2222
return "Hello, HTTP!"
2323

24-
app = FastAPI(lifespan=router.lifespan_context)
24+
app = FastAPI()
2525
app.include_router(router)

docs/docs_src/integrations/fastapi/confluent/depends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
router = fastapi.KafkaRouter("localhost:9092")
77

8-
app = FastAPI(lifespan=router.lifespan_context)
8+
app = FastAPI()
99

1010

1111
def broker():

docs/docs_src/integrations/fastapi/confluent/multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ async def nested_handler():
1414

1515
core_router.include_router(nested_router)
1616

17-
app = FastAPI(lifespan=core_router.lifespan_context)
17+
app = FastAPI()
1818
app.include_router(core_router)
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
from contextlib import asynccontextmanager
2-
31
from fastapi import FastAPI
42
from faststream.confluent.fastapi import KafkaRouter
53

6-
core_router = KafkaRouter()
7-
nested_router = KafkaRouter()
4+
one_router = KafkaRouter()
5+
another_router = KafkaRouter()
86

9-
@asynccontextmanager
10-
async def lifespan(app: FastAPI):
11-
async with (
12-
core_router.lifespan_context(app),
13-
nested_router.lifespan_context(app),
14-
):
15-
yield
7+
...
168

17-
app = FastAPI(lifespan=lifespan)
18-
app.include_router(core_router)
19-
app.include_router(nested_router)
9+
app = FastAPI()
10+
app.include_router(one_router)
11+
app.include_router(another_router)

docs/docs_src/integrations/fastapi/confluent/send.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
router = KafkaRouter("localhost:9092")
66

7-
app = FastAPI(lifespan=router.lifespan_context)
7+
app = FastAPI()
88

99

1010
@router.get("/")

docs/docs_src/integrations/fastapi/confluent/startup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ async def test(app: FastAPI):
1515
await router.broker.publish("Hello!", "test")
1616

1717

18-
app = FastAPI(lifespan=router.lifespan_context)
18+
app = FastAPI()
1919
app.include_router(router)

docs/docs_src/integrations/fastapi/kafka/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ async def hello(m: Incoming, logger: Logger, d=Depends(call)):
2121
async def hello_http():
2222
return "Hello, HTTP!"
2323

24-
app = FastAPI(lifespan=router.lifespan_context)
24+
app = FastAPI()
2525
app.include_router(router)

docs/docs_src/integrations/fastapi/kafka/depends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
router = fastapi.KafkaRouter("localhost:9092")
77

8-
app = FastAPI(lifespan=router.lifespan_context)
8+
app = FastAPI()
99

1010

1111
def broker():

docs/docs_src/integrations/fastapi/kafka/multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ async def nested_handler():
1414

1515
core_router.include_router(nested_router)
1616

17-
app = FastAPI(lifespan=core_router.lifespan_context)
17+
app = FastAPI()
1818
app.include_router(core_router)
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
from contextlib import asynccontextmanager
2-
31
from fastapi import FastAPI
42
from faststream.kafka.fastapi import KafkaRouter
53

6-
core_router = KafkaRouter()
7-
nested_router = KafkaRouter()
4+
one_router = KafkaRouter()
5+
another_router = KafkaRouter()
86

9-
@asynccontextmanager
10-
async def lifespan(app: FastAPI):
11-
async with (
12-
core_router.lifespan_context(app),
13-
nested_router.lifespan_context(app),
14-
):
15-
yield
7+
...
168

17-
app = FastAPI(lifespan=lifespan)
18-
app.include_router(core_router)
19-
app.include_router(nested_router)
9+
app = FastAPI()
10+
app.include_router(one_router)
11+
app.include_router(another_router)

docs/docs_src/integrations/fastapi/kafka/send.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
router = KafkaRouter("localhost:9092")
66

7-
app = FastAPI(lifespan=router.lifespan_context)
7+
app = FastAPI()
88

99

1010
@router.get("/")

docs/docs_src/integrations/fastapi/kafka/startup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ async def test(app: FastAPI):
1515
await router.broker.publish("Hello!", "test")
1616

1717

18-
app = FastAPI(lifespan=router.lifespan_context)
18+
app = FastAPI()
1919
app.include_router(router)

docs/docs_src/integrations/fastapi/nats/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ async def hello(m: Incoming, logger: Logger, d=Depends(call)):
2121
async def hello_http():
2222
return "Hello, HTTP!"
2323

24-
app = FastAPI(lifespan=router.lifespan_context)
24+
app = FastAPI()
2525
app.include_router(router)

docs/docs_src/integrations/fastapi/nats/depends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
router = fastapi.NatsRouter("nats://localhost:4222")
77

8-
app = FastAPI(lifespan=router.lifespan_context)
8+
app = FastAPI()
99

1010

1111
def broker():

docs/docs_src/integrations/fastapi/nats/multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ async def nested_handler():
1414

1515
core_router.include_router(nested_router)
1616

17-
app = FastAPI(lifespan=core_router.lifespan_context)
17+
app = FastAPI()
1818
app.include_router(core_router)
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
from contextlib import asynccontextmanager
2-
31
from fastapi import FastAPI
42
from faststream.nats.fastapi import NatsRouter
53

6-
core_router = NatsRouter()
7-
nested_router = NatsRouter()
4+
one_router = NatsRouter()
5+
another_router = NatsRouter()
86

9-
@asynccontextmanager
10-
async def lifespan(app: FastAPI):
11-
async with (
12-
core_router.lifespan_context(app),
13-
nested_router.lifespan_context(app),
14-
):
15-
yield
7+
...
168

17-
app = FastAPI(lifespan=lifespan)
18-
app.include_router(core_router)
19-
app.include_router(nested_router)
9+
app = FastAPI()
10+
app.include_router(one_router)
11+
app.include_router(another_router)

docs/docs_src/integrations/fastapi/nats/send.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
router = NatsRouter("nats://localhost:4222")
66

7-
app = FastAPI(lifespan=router.lifespan_context)
7+
app = FastAPI()
88

99

1010
@router.get("/")

docs/docs_src/integrations/fastapi/nats/startup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ async def test(app: FastAPI):
1515
await router.broker.publish("Hello!", "test")
1616

1717

18-
app = FastAPI(lifespan=router.lifespan_context)
18+
app = FastAPI()
1919
app.include_router(router)

docs/docs_src/integrations/fastapi/rabbit/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ async def hello(m: Incoming, logger: Logger, d=Depends(call)):
2121
async def hello_http():
2222
return "Hello, HTTP!"
2323

24-
app = FastAPI(lifespan=router.lifespan_context)
24+
app = FastAPI()
2525
app.include_router(router)

docs/docs_src/integrations/fastapi/rabbit/depends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
router = fastapi.RabbitRouter("amqp://guest:guest@localhost:5672/")
77

8-
app = FastAPI(lifespan=router.lifespan_context)
8+
app = FastAPI()
99

1010

1111
def broker():

docs/docs_src/integrations/fastapi/rabbit/multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ async def nested_handler():
1414

1515
core_router.include_router(nested_router)
1616

17-
app = FastAPI(lifespan=core_router.lifespan_context)
17+
app = FastAPI()
1818
app.include_router(core_router)
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
from contextlib import asynccontextmanager
2-
31
from fastapi import FastAPI
42
from faststream.rabbit.fastapi import RabbitRouter
53

6-
core_router = RabbitRouter()
7-
nested_router = RabbitRouter()
4+
one_router = RabbitRouter()
5+
another_router = RabbitRouter()
86

9-
@asynccontextmanager
10-
async def lifespan(app: FastAPI):
11-
async with (
12-
core_router.lifespan_context(app),
13-
nested_router.lifespan_context(app),
14-
):
15-
yield
7+
...
168

17-
app = FastAPI(lifespan=lifespan)
18-
app.include_router(core_router)
19-
app.include_router(nested_router)
9+
app = FastAPI()
10+
app.include_router(one_router)
11+
app.include_router(another_router)

docs/docs_src/integrations/fastapi/rabbit/send.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
router = RabbitRouter("amqp://guest:guest@localhost:5672/")
66

7-
app = FastAPI(lifespan=router.lifespan_context)
7+
app = FastAPI()
88

99

1010
@router.get("/")

docs/docs_src/integrations/fastapi/rabbit/startup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ async def test(app: FastAPI):
1515
await router.broker.publish("Hello!", "test")
1616

1717

18-
app = FastAPI(lifespan=router.lifespan_context)
18+
app = FastAPI()
1919
app.include_router(router)

docs/docs_src/integrations/fastapi/redis/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ async def hello(m: Incoming, logger: Logger, d=Depends(call)):
2121
async def hello_http():
2222
return "Hello, HTTP!"
2323

24-
app = FastAPI(lifespan=router.lifespan_context)
24+
app = FastAPI()
2525
app.include_router(router)

docs/docs_src/integrations/fastapi/redis/depends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
router = fastapi.RedisRouter("redis://localhost:6379")
77

8-
app = FastAPI(lifespan=router.lifespan_context)
8+
app = FastAPI()
99

1010

1111
def broker():

docs/docs_src/integrations/fastapi/redis/multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ async def nested_handler():
1414

1515
core_router.include_router(nested_router)
1616

17-
app = FastAPI(lifespan=core_router.lifespan_context)
17+
app = FastAPI()
1818
app.include_router(core_router)
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
from contextlib import asynccontextmanager
2-
31
from fastapi import FastAPI
42
from faststream.redis.fastapi import RedisRouter
53

6-
core_router = RedisRouter()
7-
nested_router = RedisRouter()
4+
one_router = RedisRouter()
5+
another_router = RedisRouter()
86

9-
@asynccontextmanager
10-
async def lifespan(app: FastAPI):
11-
async with (
12-
core_router.lifespan_context(app),
13-
nested_router.lifespan_context(app),
14-
):
15-
yield
7+
...
168

17-
app = FastAPI(lifespan=lifespan)
18-
app.include_router(core_router)
19-
app.include_router(nested_router)
9+
app = FastAPI()
10+
app.include_router(one_router)
11+
app.include_router(another_router)

docs/docs_src/integrations/fastapi/redis/send.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
router = RedisRouter("redis://localhost:6379")
66

7-
app = FastAPI(lifespan=router.lifespan_context)
7+
app = FastAPI()
88

99

1010
@router.get("/")

docs/docs_src/integrations/fastapi/redis/startup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ async def test(app: FastAPI):
1515
await router.broker.publish("Hello!", "test")
1616

1717

18-
app = FastAPI(lifespan=router.lifespan_context)
18+
app = FastAPI()
1919
app.include_router(router)

0 commit comments

Comments
 (0)