Skip to content

Commit

Permalink
feat: ASGI support (#1635)
Browse files Browse the repository at this point in the history
* feat: initial ASGI support

* docs: generate API References

* feat: add make_asyncapi_html method

* feat: detail make_asyncapi_asgi params

* refactor: reuse app.mount to add asyncapi url

* refactor: remove useless charset

* refactor: add AsgiFastStream args comment

* refactor: rename AsgiFastStream lifespan

* tests: cover asgi

* docs: add ASGI page

* tests: fix 3.8 compatibility

* chore: make detail tests CI output

* test: make asyncapi asgi test in-memory

* docs: add asgi and OTEL to Public API

* docs: run API generator

* fix: use classmethod

* test: increase confuent testclient timeout

* tests: fix confluent

* refactor: clarify BatchKafkaParser behavior

* lint: run ruff

* lint: fix mypy

* Update ASGI docs

* tests: fix confluent

* chore: bump dependencies

* chore: bump version

* chore: add kafka devcontainer

* refactor: optimize confluent a bit

* refactor: optimize confluent client calls

* docs: generate API

* docs: remove useless API

* chore: detail confluent tests

* tests: refactor to use custom args, kwargs for subscriber

* tests: fix confluent

* docs: generate API References

* tests: fix asyncapi FastAPI

* chore: revert FastAPI changes

* tests: increase confluent tests timeouts

* fix: fix Nats router subjects

* lint: fix formating

* tests: increase confluent tests timeouts

* lint: run ruff

* tests: remove explicit confluent address

* tests: run docs tests first

---------

Co-authored-by: Lancetnik <[email protected]>
Co-authored-by: Kumaran Rajendhiran <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2024
1 parent 9cd4664 commit 0112632
Show file tree
Hide file tree
Showing 311 changed files with 2,214 additions and 908 deletions.
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
"service": "python-3.12-faststream-studio",
"dockerComposeFile": [
"./docker-compose.yaml"
],
"shutdownAction": "stopCompose",
"forwardPorts": [
"kafka-faststream:9092"
],
"updateContentCommand": "bash .devcontainer/setup.sh",
"workspaceFolder": "/workspaces/faststream"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
33 changes: 33 additions & 0 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'

services:
python-3.12-faststream-studio: # nosemgrep
image: mcr.microsoft.com/devcontainers/python:3.12
container_name: python-3.12-faststream-studio
volumes:
- ../:/workspaces/faststream:cached
command: sleep infinity
network_mode: "host"

kafka-faststream: # nosemgrep
image: bitnami/kafka:3.5.0
container_name: kafka-faststream
ports:
- 9092:9092
environment:
KAFKA_ENABLE_KRAFT: "true"
KAFKA_CFG_NODE_ID: "1"
KAFKA_CFG_PROCESS_ROLES: "broker,controller"
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
KAFKA_CFG_LISTENERS: "PLAINTEXT://:9092,CONTROLLER://:9093"
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"
KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://127.0.0.1:9092"
KAFKA_BROKER_ID: "1"
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "1@kafka-faststream:9093"
ALLOW_PLAINTEXT_LISTENER: "true"
networks:
- faststream-network

networks:
faststream-network:
name: "${USER}-faststream-network"
7 changes: 7 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pip install uv

uv venv .venv

uv pip install -e ".[dev]"

source .venv/bin/activate
17 changes: 0 additions & 17 deletions .github/dependabot.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
4 changes: 2 additions & 2 deletions .github/workflows/pr_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: pip install --pre "pydantic>=2.0.0b2,<3.0.0"
- run: mkdir coverage
- name: Test
run: bash scripts/test.sh -m "(slow and (not nats and not kafka and not confluent and not rabbit and not redis)) or (not nats and not kafka and not confluent and not rabbit and not redis)"
run: bash scripts/test.sh -vv -m "(slow and (not nats and not kafka and not confluent and not rabbit and not redis)) or (not nats and not kafka and not confluent and not rabbit and not redis)"
env:
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.pydantic-version }}
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.pydantic-version }}
Expand Down Expand Up @@ -269,7 +269,7 @@ jobs:
run: pip install .[optionals,testing]
- run: mkdir coverage
- name: Test
run: bash scripts/test.sh -m "(slow and confluent) or confluent"
run: bash scripts/test.sh -vv -m "(slow and confluent) or confluent"
env:
COVERAGE_FILE: coverage/.coverage.confluent-py
CONTEXT: confluent-py
Expand Down
2 changes: 2 additions & 0 deletions docs/create_api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@


PUBLIC_API_FILES = [
"faststream/opentelemetry/__init__.py",
"faststream/asgi/__init__.py",
"faststream/asyncapi/__init__.py",
"faststream/__init__.py",
"faststream/nats/__init__.py",
Expand Down
35 changes: 33 additions & 2 deletions docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ search:
- [FastAPI Plugin](getting-started/integrations/fastapi/index.md)
- [Django](getting-started/integrations/django/index.md)
- [CLI commands](getting-started/cli/index.md)
- [ASGI](getting-started/asgi.md)
- [OpenTelemetry](getting-started/opentelemetry/index.md)
- [Logging](getting-started/logging.md)
- [Config Management](getting-started/config/index.md)
Expand Down Expand Up @@ -120,6 +121,12 @@ search:
- [Response](public_api/faststream/Response.md)
- [TestApp](public_api/faststream/TestApp.md)
- [apply_types](public_api/faststream/apply_types.md)
- asgi
- [AsgiFastStream](public_api/faststream/asgi/AsgiFastStream.md)
- [AsgiResponse](public_api/faststream/asgi/AsgiResponse.md)
- [get](public_api/faststream/asgi/get.md)
- [make_asyncapi_asgi](public_api/faststream/asgi/make_asyncapi_asgi.md)
- [make_ping_asgi](public_api/faststream/asgi/make_ping_asgi.md)
- asyncapi
- [get_app_schema](public_api/faststream/asyncapi/get_app_schema.md)
- [get_asyncapi_html](public_api/faststream/asyncapi/get_asyncapi_html.md)
Expand All @@ -131,6 +138,7 @@ search:
- [KafkaRouter](public_api/faststream/confluent/KafkaRouter.md)
- [TestApp](public_api/faststream/confluent/TestApp.md)
- [TestKafkaBroker](public_api/faststream/confluent/TestKafkaBroker.md)
- [TopicPartition](public_api/faststream/confluent/TopicPartition.md)
- kafka
- [KafkaBroker](public_api/faststream/kafka/KafkaBroker.md)
- [KafkaPublisher](public_api/faststream/kafka/KafkaPublisher.md)
Expand Down Expand Up @@ -164,6 +172,9 @@ search:
- [StreamSource](public_api/faststream/nats/StreamSource.md)
- [TestApp](public_api/faststream/nats/TestApp.md)
- [TestNatsBroker](public_api/faststream/nats/TestNatsBroker.md)
- opentelemetry
- [TelemetryMiddleware](public_api/faststream/opentelemetry/TelemetryMiddleware.md)
- [TelemetrySettingsProvider](public_api/faststream/opentelemetry/TelemetrySettingsProvider.md)
- rabbit
- [ExchangeType](public_api/faststream/rabbit/ExchangeType.md)
- [RabbitBroker](public_api/faststream/rabbit/RabbitBroker.md)
Expand Down Expand Up @@ -200,6 +211,23 @@ search:
- [apply_types](api/faststream/apply_types.md)
- app
- [FastStream](api/faststream/app/FastStream.md)
- asgi
- [AsgiFastStream](api/faststream/asgi/AsgiFastStream.md)
- [AsgiResponse](api/faststream/asgi/AsgiResponse.md)
- [get](api/faststream/asgi/get.md)
- [make_asyncapi_asgi](api/faststream/asgi/make_asyncapi_asgi.md)
- [make_ping_asgi](api/faststream/asgi/make_ping_asgi.md)
- app
- [AsgiFastStream](api/faststream/asgi/app/AsgiFastStream.md)
- factories
- [make_asyncapi_asgi](api/faststream/asgi/factories/make_asyncapi_asgi.md)
- [make_ping_asgi](api/faststream/asgi/factories/make_ping_asgi.md)
- handlers
- [get](api/faststream/asgi/handlers/get.md)
- response
- [AsgiResponse](api/faststream/asgi/response/AsgiResponse.md)
- websocket
- [WebSocketClose](api/faststream/asgi/websocket/WebSocketClose.md)
- asyncapi
- [get_app_schema](api/faststream/asyncapi/get_app_schema.md)
- [get_asyncapi_html](api/faststream/asyncapi/get_asyncapi_html.md)
Expand All @@ -214,6 +242,7 @@ search:
- [get_response_schema](api/faststream/asyncapi/message/get_response_schema.md)
- [parse_handler_params](api/faststream/asyncapi/message/parse_handler_params.md)
- proto
- [AsyncAPIApplication](api/faststream/asyncapi/proto/AsyncAPIApplication.md)
- [AsyncAPIProto](api/faststream/asyncapi/proto/AsyncAPIProto.md)
- schema
- [Channel](api/faststream/asyncapi/schema/Channel.md)
Expand Down Expand Up @@ -429,6 +458,7 @@ search:
- [KafkaRouter](api/faststream/confluent/KafkaRouter.md)
- [TestApp](api/faststream/confluent/TestApp.md)
- [TestKafkaBroker](api/faststream/confluent/TestKafkaBroker.md)
- [TopicPartition](api/faststream/confluent/TopicPartition.md)
- broker
- [KafkaBroker](api/faststream/confluent/broker/KafkaBroker.md)
- broker
Expand All @@ -441,8 +471,6 @@ search:
- [AsyncConfluentConsumer](api/faststream/confluent/client/AsyncConfluentConsumer.md)
- [AsyncConfluentProducer](api/faststream/confluent/client/AsyncConfluentProducer.md)
- [BatchBuilder](api/faststream/confluent/client/BatchBuilder.md)
- [MsgToSend](api/faststream/confluent/client/MsgToSend.md)
- [TopicPartition](api/faststream/confluent/client/TopicPartition.md)
- [check_msg_error](api/faststream/confluent/client/check_msg_error.md)
- [create_topics](api/faststream/confluent/client/create_topics.md)
- config
Expand Down Expand Up @@ -496,8 +524,11 @@ search:
- [KafkaRoute](api/faststream/confluent/router/KafkaRoute.md)
- [KafkaRouter](api/faststream/confluent/router/KafkaRouter.md)
- schemas
- [TopicPartition](api/faststream/confluent/schemas/TopicPartition.md)
- params
- [ConsumerConnectionParams](api/faststream/confluent/schemas/params/ConsumerConnectionParams.md)
- partition
- [TopicPartition](api/faststream/confluent/schemas/partition/TopicPartition.md)
- security
- [parse_security](api/faststream/confluent/security/parse_security.md)
- subscriber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: faststream.confluent.client.MsgToSend
::: faststream.asgi.AsgiFastStream
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/AsgiResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.AsgiResponse
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/app/AsgiFastStream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.app.AsgiFastStream
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/factories/make_asyncapi_asgi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.factories.make_asyncapi_asgi
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/factories/make_ping_asgi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.factories.make_ping_asgi
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.get
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/handlers/get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.handlers.get
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/make_asyncapi_asgi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.make_asyncapi_asgi
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/make_ping_asgi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.make_ping_asgi
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/response/AsgiResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.response.AsgiResponse
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asgi/websocket/WebSocketClose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asgi.websocket.WebSocketClose
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/asyncapi/proto/AsyncAPIApplication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.asyncapi.proto.AsyncAPIApplication
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: faststream.confluent.client.TopicPartition
::: faststream.confluent.TopicPartition
11 changes: 11 additions & 0 deletions docs/docs/en/api/faststream/confluent/schemas/TopicPartition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.confluent.schemas.TopicPartition
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: faststream.confluent.schemas.partition.TopicPartition
Loading

0 comments on commit 0112632

Please sign in to comment.