Framework
ag2ai/faststream avatar
ag2ai/faststream

FastStream: a typed async client for Kafka, RabbitMQ, NATS, Redis and MQTT

Asynchronous Python framework for event-driven services. A thin client for Kafka, RabbitMQ, NATS, Redis and MQTT with full access to native broker features, plus AsyncAPI docs, in-memory tests and observability out of the box.

5,357 stars408 forksPythonApache-2.0

At a glance

What is it?
FastStream wraps five brokers in FastAPI-style decorators, generates AsyncAPI docs from your handlers and runs subscribers in memory for tests. It is a thin client, not a broker abstraction, and that distinction decides whether it fits your service.
Who is it for?
Adopt FastStream if your service is Python, asyncio-based, and talks to one of the five supported brokers, and you want typed handlers plus a generated AsyncAPI document without writing either by hand. Do not adopt it if you need one abstraction that hides which broker is underneath, if you are on Python 3.9 or older, or if your consumers are not Python at all.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 30, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What FastStream actually solves for a Python service

Writing a consumer for Kafka or RabbitMQ in plain Python means repeating the same work in every service: connection setup, retry and reconnect logic, deserialization, validation, graceful shutdown, and a separate document describing the topics and queues that the neighbouring team keeps asking for. FastStream moves that scaffolding into decorators. A handler is a function with a typed parameter, and the framework handles parsing, lifecycle and documentation generation around it. The project describes itself as a thin client for Kafka, RabbitMQ, NATS, Redis and MQTT, with full access to native broker features.

The audience is narrow and specific. This is a library for Python teams building event-driven microservices on asyncio, where the broker is already chosen and the team wants less boilerplate rather than a new abstraction. The README states that if you know FastAPI, you already know FastStream, and points at the same decorators, type-driven validation, dependency injection and generated documentation, aimed at brokers instead of HTTP. That framing is honest about the intended reader: someone who has written FastAPI routes and now has to write a consumer.

The important word in the description is thin. FastStream is not a portable messaging layer that lets you swap RabbitMQ for Kafka by changing a string. The README says it is a client for your broker, not a layer above all of them, and lists broker-specific capabilities such as Kafka consumer groups and partitioning, RabbitMQ exchanges and DLQ, NATS JetStream and KeyValue, Redis Streams and MQTT QoS. Those features are reachable because the client does not flatten them.

How the framework sits between your handler and the broker

The mechanism is a decorator that registers a function as a subscriber, plus an object that represents the broker connection. The broker object is passed to the decorator, so the same handler shape works across brokers while the configuration object underneath carries broker-specific settings. FastStream then owns the connection lifecycle: it starts the broker, consumes messages, validates them against the handler's type annotation, calls the function, and acknowledges according to the acknowledgement mode you chose.

Serialization and validation are delegated to Pydantic or Msgspec, both named in the README. A handler that declares a typed parameter gets parsed input; a message that does not match the type is rejected before your code runs. The examples directory includes files such as e04_msg_filter.py, e06_manual_ack.py and e07_ack_immediately.py, which map onto the acknowledgement and filtering decisions you would otherwise write by hand.

Two pieces sit alongside the runtime. The first is AsyncAPI document generation: the README calls it a spec you never write, generated from your handlers, with an in-browser form for publishing test messages. The second is the in-memory test client, which runs subscribers and publishers without a broker, keeping validation intact. OpenTelemetry traces, Prometheus metrics and Kubernetes probes are also listed as coming with the framework through middlewares. The repository layout matches that story: faststream/ for the library, docs/, examples/, tests/, benchmarks/ and a docker-compose.yaml that defines the five brokers plus a Redis cluster for local work.

Installing FastStream and publishing a first message

FastStream is distributed on PyPI and requires Python 3.10 or newer, according to pyproject.toml. The README does not print a pip command in the excerpt, so install it the ordinary way for a Python package:

bash
pip install faststream

A broker still has to exist. The repository ships a docker-compose.yaml with a rabbitmq service on port 5672, kafka on 9092, nats on 4222 with management on 8222, and redis on 6379. For a first run, RabbitMQ is the least ceremony:

bash
docker compose up -d rabbitmq

The example files in examples/ are the intended starting point. e01_basic_consume.py and the e02_*_basic_publisher.py files cover the smallest producer and consumer pair. The README does not quote their contents, so read them in the repository rather than copying a snippet from a blog post; the decorator and broker object names have to match the version you installed.

For tests, the framework provides an in-memory client, and examples/e08_testing.py and examples/e09_testing_mocks.py are the files to open. The README's claim is that this runs your subscribers and publishers with validation intact, without containers and in milliseconds rather than minutes. That claim is about the test path only; it does not tell you how your handler behaves against a real broker.

Where the thin-client design costs you

The same decision that gives you Kafka consumer groups and RabbitMQ dead-letter queues means your application code is broker-shaped. A handler written for NATS JetStream is not the same handler as one written for Redis Streams, because the configuration object, the acknowledgement semantics and the failure modes differ. If your goal is a single codebase that can be pointed at any of the five brokers, FastStream is the wrong tool; it deliberately declines to be that layer.

Version churn is a second consideration. The project is at 0.7.6, with releases 0.7.5 and 0.7.4 in the weeks before it, and the README references a FastAPI plugin marked deprecated. A pre-1.0 version number is a factual signal about API stability, and the README's own table of contents includes a versioning policy section, which suggests the maintainers treat compatibility as something to document rather than assume. Pin the version and read the release notes before upgrading.

A third limit is scope. FastStream handles the client side of messaging in Python. It does not provision topics, manage broker clusters, or give you a dashboard for consumer lag. The docker-compose.yaml is for local development, not a deployment topology. Teams that expect a framework to cover operations will find that the boundary sits at the connection.

FastStream compared with a full event-driven framework

The closest point of comparison in this space is a framework that owns the whole application, not just the broker connection. FastStream's own answer is FastAPI: the README says the project is fully compatible with any HTTP framework you want, and that the API is small enough to onboard a teammate in an afternoon.

The practical difference is where the abstraction line falls. A full-stack event framework typically gives you one programming model across brokers and often its own runtime, at the cost of hiding broker-specific features. FastStream keeps the native client visible: NATS JetStream and KeyValue, Redis Streams, MQTT QoS and Kafka partitioning are reachable because the framework does not pretend the brokers are interchangeable. If you have already invested in broker-specific behaviour such as exchange types or consumer group rebalancing, that choice is the reason to pick FastStream over a unifying layer. If your priority is moving a service between brokers without touching handler code, the same choice is the reason to pick something else.

The testing story is the other axis. Running subscribers in memory with validation intact is a real difference from mocking a broker client by hand, and examples/e08_testing.py and examples/e09_testing_mocks.py show the intended shape. It does not replace an integration test against a real broker, and the README does not claim it does.

Maintenance, licence and upgrade cost

The repository is not archived. The last push was on 2026-09-22, and the most recent release listed is 0.7.6 from 2026-09-20, with 0.7.5 on 2026-08-27 and 0.7.4 on 2026-08-07. That is a steady release cadence over the preceding weeks, and the repository carries a justfile with lock-check, test, test-all and test-coverage recipes, plus a Dockerfile that pins uv 0.7.13 for the development environment.

The licence is Apache-2.0, declared in pyproject.toml with license-files pointing at LICENSE. Apache-2.0 permits commercial use and modification and includes an explicit patent grant; it also requires that you keep the licence and notices. Whether that fits your organisation's policy on dependencies is a question for your own review, not something this article can settle.

The upgrade cost is mostly the pre-1.0 API surface. A minor version can rename a configuration key or change how a broker object is constructed, and your handlers depend on exactly those names. The repository's own tooling reflects that concern: lock-check fails when uv.lock is out of sync with pyproject.toml, and the test suite is split by markers so the fast path excludes slow and connected tests. Mirroring that in your own project means pinning faststream, running your handler tests against the in-memory client on every change, and reserving the real-broker tests for the upgrade itself.

Editorial conclusion

Adopt FastStream if your service is Python, asyncio-based, and talks to one of the five supported brokers, and you want typed handlers plus a generated AsyncAPI document without writing either by hand. Do not adopt it if you need one abstraction that hides which broker is underneath, if you are on Python 3.9 or older, or if your consumers are not Python at all. Before committing, verify two things in your own environment: that the broker features you depend on are exposed by the FastStream client for that broker, and that your handlers behave under the in-memory test client the same way they do against a real broker.

Frequently asked questions

How to install FastStream?

It is published on PyPI as faststream and requires Python 3.10 or newer, according to pyproject.toml. Install it with pip install faststream, then start a broker; the repository's docker-compose.yaml defines rabbitmq on port 5672, kafka on 9092, nats on 4222 and redis on 6379.

How to use FastStream?

You register handlers with decorators that take a broker object, in the same style as FastAPI routes, and FastStream handles parsing, lifecycle and documentation generation. The examples directory is the starting point: e01_basic_consume.py and the e02_*_basic_publisher.py files cover the smallest consumer and producer.

Does FastStream work with FastAPI?

The README states that FastStream is fully compatible with any HTTP framework you want, and mentions a dedicated FastAPI plugin that it marks as deprecated. The examples directory contains a fastapi_integration folder for that case.

Is FastStream safe to use in production?

pyproject.toml classifies it as Production/Stable and the repository is not archived, with the last push on 2026-09-22. The current version is 0.7.6, so the API is still pre-1.0 and the README includes a versioning policy section.

Which message brokers does FastStream support?

Five, as first-class clients: Kafka, RabbitMQ, NATS, Redis and MQTT. The README lists broker-specific capabilities for each, including Kafka consumer groups and partitioning, RabbitMQ exchanges and DLQ, NATS JetStream and KeyValue, Redis Streams and MQTT QoS.

Official sources

  1. ag2ai/faststream on GitHub
  2. License: Apache-2.0
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/ag2ai-faststream.svg)](https://hysenlabs.com/projects/ag2ai-faststream)