Skip to content

Commit 395fd74

Browse files
authored
Support faststream 0.6 (#125)
* Support faststream 0.6 * Support faststream 0.6 * Support faststream 0.6 * Support faststream 0.6
1 parent 96f35fe commit 395fd74

File tree

9 files changed

+38
-137
lines changed

9 files changed

+38
-137
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ jobs:
1515
ci:
1616
uses: community-of-python/community-workflow/.github/workflows/preset.yml@main
1717
with:
18-
python-version: '["3.10","3.11","3.12","3.13"]'
18+
python-version: '["3.10","3.11","3.12","3.13", "3.14"]'
1919
secrets: inherit

docs/.vuepress/config.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

docs/README.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/get-started.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

microbootstrap/bootstrappers/faststream.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import typing_extensions
88
from faststream.asgi import AsgiFastStream, AsgiResponse
99
from faststream.asgi import get as handle_get
10+
from faststream.specification import AsyncAPI
1011

1112
from microbootstrap.bootstrappers.base import ApplicationBootstrapper
1213
from microbootstrap.config.faststream import FastStreamConfig
@@ -34,9 +35,11 @@ class FastStreamBootstrapper(ApplicationBootstrapper[FastStreamSettings, AsgiFas
3435

3536
def bootstrap_before(self: typing_extensions.Self) -> dict[str, typing.Any]:
3637
return {
37-
"title": self.settings.service_name,
38-
"version": self.settings.service_version,
39-
"description": self.settings.service_description,
38+
"specification": AsyncAPI(
39+
title=self.settings.service_name,
40+
version=self.settings.service_version,
41+
description=self.settings.service_description,
42+
),
4043
"on_shutdown": [self.teardown],
4144
"on_startup": [self.console_writer.print_bootstrap_table],
4245
"asyncapi_path": self.settings.asyncapi_path,
@@ -55,7 +58,7 @@ def is_ready(self) -> bool:
5558
def bootstrap_after(self, application: AsgiFastStream) -> AsgiFastStream: # type: ignore[override]
5659
if self.instrument_config.opentelemetry_middleware_cls and application.broker:
5760
application.broker.add_middleware(
58-
self.instrument_config.opentelemetry_middleware_cls(tracer_provider=self.tracer_provider)
61+
self.instrument_config.opentelemetry_middleware_cls(tracer_provider=self.tracer_provider),
5962
)
6063
return application
6164

@@ -82,13 +85,13 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
8285
self.instrument_config.prometheus_metrics_path,
8386
prometheus_client.make_asgi_app(prometheus_client.REGISTRY),
8487
),
85-
)
88+
),
8689
}
8790

8891
def bootstrap_after(self, application: AsgiFastStream) -> AsgiFastStream: # type: ignore[override]
8992
if self.instrument_config.prometheus_middleware_cls and application.broker:
9093
application.broker.add_middleware(
91-
self.instrument_config.prometheus_middleware_cls(registry=prometheus_client.REGISTRY)
94+
self.instrument_config.prometheus_middleware_cls(registry=prometheus_client.REGISTRY),
9295
)
9396
return application
9497

@@ -105,7 +108,9 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
105108
async def check_health(scope: typing.Any) -> AsgiResponse: # noqa: ANN401, ARG001
106109
return (
107110
AsgiResponse(
108-
json.dumps(self.render_health_check_data()).encode(), 200, headers={"content-type": "text/plain"}
111+
json.dumps(self.render_health_check_data()).encode(),
112+
200,
113+
headers={"content-type": "text/plain"},
109114
)
110115
if await self.define_health_status()
111116
else AsgiResponse(b"Service is unhealthy", 500, headers={"content-type": "application/json"})

microbootstrap/config/faststream.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44

55

66
if typing.TYPE_CHECKING:
7-
import faststream.asyncapi.schema as asyncapi
8-
from faststream.asgi.types import ASGIApp
9-
from faststream.broker.core.usecase import BrokerUsecase
10-
from faststream.types import AnyDict, AnyHttpUrl, Lifespan
7+
from fast_depends import Provider
8+
from fast_depends.library.serializer import SerializerProto
9+
from faststream._internal.basic_types import (
10+
AnyCallable,
11+
Lifespan,
12+
LoggerProto,
13+
)
14+
from faststream._internal.broker import BrokerUsecase
15+
from faststream._internal.context import ContextRepo
16+
from faststream.specification.base import SpecificationFactory
1117

1218

1319
@dataclasses.dataclass
1420
class FastStreamConfig:
1521
broker: BrokerUsecase[typing.Any, typing.Any] | None = None
16-
asgi_routes: typing.Sequence[tuple[str, ASGIApp]] = ()
22+
logger: LoggerProto | None = None
23+
provider: Provider | None = None
24+
serializer: SerializerProto | None = None
25+
context: ContextRepo | None = None
1726
lifespan: Lifespan | None = None
18-
terms_of_service: AnyHttpUrl | None = None
19-
license: asyncapi.License | asyncapi.LicenseDict | AnyDict | None = None
20-
contact: asyncapi.Contact | asyncapi.ContactDict | AnyDict | None = None
21-
tags: typing.Sequence[asyncapi.Tag | asyncapi.TagDict | AnyDict] | None = None
22-
external_docs: asyncapi.ExternalDocs | asyncapi.ExternalDocsDict | AnyDict | None = None
23-
identifier: str | None = None
24-
on_startup: typing.Sequence[typing.Callable[..., typing.Any]] = ()
25-
after_startup: typing.Sequence[typing.Callable[..., typing.Any]] = ()
26-
on_shutdown: typing.Sequence[typing.Callable[..., typing.Any]] = ()
27-
after_shutdown: typing.Sequence[typing.Callable[..., typing.Any]] = ()
27+
on_startup: typing.Sequence[AnyCallable] = ()
28+
after_startup: typing.Sequence[AnyCallable] = ()
29+
on_shutdown: typing.Sequence[AnyCallable] = ()
30+
after_shutdown: typing.Sequence[AnyCallable] = ()
31+
specification: SpecificationFactory | None = None

microbootstrap/instruments/opentelemetry_instrument.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pydantic
88
import structlog
9+
from faststream._internal.types import BrokerMiddleware
910
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
1011
from opentelemetry.instrumentation.dependencies import DependencyConflictError
1112
from opentelemetry.instrumentation.environment_variables import OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
@@ -31,7 +32,6 @@
3132

3233

3334
if typing.TYPE_CHECKING:
34-
import faststream
3535
from opentelemetry.context import Context
3636
from opentelemetry.metrics import Meter, MeterProvider
3737
from opentelemetry.trace import TracerProvider
@@ -64,21 +64,20 @@ class OpentelemetryConfig(BaseInstrumentConfig):
6464
default=[
6565
one_package_to_exclude.strip()
6666
for one_package_to_exclude in os.environ.get(OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, "").split(",")
67-
]
67+
],
6868
)
6969
opentelemetry_log_traces: bool = False
7070

7171

7272
@typing.runtime_checkable
73-
class FastStreamTelemetryMiddlewareProtocol(typing.Protocol):
73+
class FastStreamTelemetryMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
7474
def __init__(
7575
self,
7676
*,
7777
tracer_provider: TracerProvider | None = None,
7878
meter_provider: MeterProvider | None = None,
7979
meter: Meter | None = None,
8080
) -> None: ...
81-
def __call__(self, msg: typing.Any | None) -> faststream.BaseMiddleware: ... # noqa: ANN401
8281

8382

8483
class FastStreamOpentelemetryConfig(OpentelemetryConfig):

microbootstrap/instruments/prometheus_instrument.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import typing
33

44
import pydantic
5+
from faststream._internal.types import BrokerMiddleware
56

67
from microbootstrap.helpers import is_valid_path
78
from microbootstrap.instruments.base import BaseInstrumentConfig, Instrument
89

910

1011
if typing.TYPE_CHECKING:
11-
import faststream
1212
import prometheus_client
1313

1414

@@ -33,7 +33,7 @@ class FastApiPrometheusConfig(BasePrometheusConfig):
3333

3434

3535
@typing.runtime_checkable
36-
class FastStreamPrometheusMiddlewareProtocol(typing.Protocol):
36+
class FastStreamPrometheusMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
3737
def __init__(
3838
self,
3939
*,
@@ -42,7 +42,6 @@ def __init__(
4242
metrics_prefix: str = "faststream",
4343
received_messages_size_buckets: typing.Sequence[float] | None = None,
4444
) -> None: ...
45-
def __call__(self, msg: typing.Any | None) -> faststream.BaseMiddleware: ... # noqa: ANN401
4645

4746

4847
class FastStreamPrometheusConfig(BasePrometheusConfig):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ classifiers = [
2727
"Programming Language :: Python :: 3.11",
2828
"Programming Language :: Python :: 3.12",
2929
"Programming Language :: Python :: 3.13",
30+
"Programming Language :: Python :: 3.14",
3031
]
3132
dependencies = [
3233
"eval-type-backport>=0.2",

0 commit comments

Comments
 (0)