{"id":26917464,"url":"https://github.com/ag2ai/faststream","last_synced_at":"2026-03-01T10:02:15.211Z","repository":{"id":64987422,"uuid":"572911222","full_name":"ag2ai/faststream","owner":"ag2ai","description":"FastStream is a powerful and easy-to-use Python framework for building asynchronous services interacting with event streams such as Apache Kafka, RabbitMQ, NATS and Redis.","archived":false,"fork":false,"pushed_at":"2025-05-12T17:04:09.000Z","size":482671,"stargazers_count":3897,"open_issues_count":95,"forks_count":226,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-05-12T18:23:12.530Z","etag":null,"topics":["asyncapi","asyncio","distributed-systems","fastkafka","faststream","kafka","nats","propan","python","rabbitmq","redis","stream-processing"],"latest_commit_sha":null,"homepage":"https://faststream.airt.ai/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ag2ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-01T09:46:18.000Z","updated_at":"2025-05-12T16:51:50.000Z","dependencies_parsed_at":"2023-09-21T19:27:51.931Z","dependency_job_id":"774cdb36-aa98-482d-860f-e03cb1d6e476","html_url":"https://github.com/ag2ai/faststream","commit_stats":{"total_commits":579,"total_committers":20,"mean_commits":28.95,"dds":0.697754749568221,"last_synced_commit":"fbded68f4318f82be4ecd97bfbf50030f16ee7d9"},"previous_names":["airtai/fast-kafka-api","airtai/faststream","ag2ai/faststream"],"tags_count":108,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag2ai%2Ffaststream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag2ai%2Ffaststream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag2ai%2Ffaststream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag2ai%2Ffaststream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ag2ai","download_url":"https://codeload.github.com/ag2ai/faststream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052692,"owners_count":22006716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncapi","asyncio","distributed-systems","fastkafka","faststream","kafka","nats","propan","python","rabbitmq","redis","stream-processing"],"created_at":"2025-04-01T20:18:39.425Z","updated_at":"2026-03-01T10:02:15.193Z","avatar_url":"https://github.com/ag2ai.png","language":"Python","readme":"# FastStream\n\n\u003cb\u003eEffortless event stream integration for your services\u003c/b\u003e\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n[![Trendshift](https://trendshift.io/api/badge/repositories/3043)](https://trendshift.io/repositories/3043)\n\n[![Test Passing](https://github.com/ag2ai/faststream/actions/workflows/pr_tests.yaml/badge.svg?branch=main)](https://github.com/ag2ai/faststream/actions/workflows/pr_tests.yaml)\n[![Coverage](https://coverage-badge.samuelcolvin.workers.dev/ag2ai/faststream.svg)](https://coverage-badge.samuelcolvin.workers.dev/redirect/ag2ai/faststream)\n[![Downloads](https://static.pepy.tech/personalized-badge/faststream?period=month\u0026units=international_system\u0026left_color=grey\u0026right_color=green\u0026left_text=downloads/month)](https://www.pepy.tech/projects/faststream)\n[![Package version](https://img.shields.io/pypi/v/faststream?label=PyPI)](https://pypi.org/project/faststream)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/faststream.svg)](https://pypi.org/project/faststream)\\\n[![CodeQL](https://github.com/ag2ai/faststream/actions/workflows/pr_codeql.yaml/badge.svg)](https://github.com/ag2ai/faststream/actions/workflows/pr_codeql.yaml)\n[![Dependency Review](https://github.com/ag2ai/faststream/actions/workflows/pr_dependency-review.yaml/badge.svg)](https://github.com/ag2ai/faststream/actions/workflows/pr_dependency-review.yaml)\n[![License](https://img.shields.io/github/license/ag2ai/faststream.svg)](https://github.com/ag2ai/faststream/blob/main/LICENSE)\n[![Code of Conduct](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/ag2ai/faststream/blob/main/.github/CODE_OF_CONDUCT.md)\\\n[![Discord](https://img.shields.io/discord/1085457301214855171?logo=discord\u0026label=EN)](https://discord.gg/qFm6aSqq59)\n[![FastStream](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fag2ai%2Ffaststream%2Fmain%2Fdocs%2Fdocs%2Fassets%2Fimg%2Fshield.json)](https://faststream.ag2.ai)\n[![Telegram](https://img.shields.io/badge/-telegram-black?color=blue\u0026logo=telegram\u0026label=RU)](https://t.me/python_faststream)\\\n[![Gurubase](https://img.shields.io/badge/Gurubase-Ask%20FastStream%20Guru-006BFF)](https://gurubase.io/g/faststream)\n\u003c/div\u003e\n\n---\n\n## Features\n\n[**FastStream**](https://faststream.ag2.ai/latest/) simplifies the process of writing producers and consumers for message queues, handling all the\nparsing, networking and documentation generation automatically.\n\nMaking streaming microservices has never been easier. Designed with junior developers in mind, **FastStream** simplifies your work while keeping the door open for more advanced use cases. Here's a look at the core features that make **FastStream** a go-to framework for modern, data-centric microservices.\n\n- [**Multiple Brokers**](#unified-api): **FastStream** provides a suitable API to work across multiple message brokers ([**Kafka**](https://kafka.apache.org/), [**RabbitMQ**](https://www.rabbitmq.com/), [**NATS**](https://nats.io/), [**Redis**](https://redis.io/) support)\n\n- [**Built-in Serialization**](#writing-app-code): Leverage [**Pydantic**](https://docs.pydantic.dev/) or [**Msgspec**](https://jcristharif.com/msgspec/) validation capabilities to serialize and validate incoming messages\n\n- [**Automatic Docs**](#project-documentation): Stay ahead with automatic [**AsyncAPI**](https://www.asyncapi.com/) documentation\n\n- **Intuitive**: Full-typed editor support makes your development experience smooth, catching errors before they reach runtime\n\n- [**Powerful Dependency Injection System**](#dependencies): Manage your service dependencies efficiently with **FastStream**'s built-in DI system\n\n- [**Testable**](#testing-the-service): Supports in-memory tests, making your CI/CD pipeline faster and more reliable\n\n- **Extensible**: Use extensions for lifespans, custom serialization and middleware\n\n- [**Integrations**](#any-framework): **FastStream** is fully compatible with any HTTP framework you want ([**FastAPI**](#fastapi-plugin) especially)\n\nThat's **FastStream** in a nutshell - easy, efficient, and powerful. Whether you're just starting with streaming microservices or looking to scale, **FastStream** has got you covered.\n\n---\n\n**Documentation**: \u003ca href=\"https://faststream.ag2.ai/latest/\" target=\"_blank\"\u003ehttps://faststream.ag2.ai/latest/\u003c/a\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eTable of Contents\u003c/b\u003e\u003c/summary\u003e\n\n- [Features](#features)\n- [Versioning Policy](#versioning-policy)\n- [Installation](#installation)\n- [Quick Start](#writing-app-code)\n  - [Pydantic serialization](#pydantic-serialization)\n  - [Msgspec serialization](#msgspec-serialization)\n  - [Unified API](#unified-api)\n- [Testing](#testing-the-service)\n- [CLI](#running-the-application)\n- [AsyncAPI Documentation](#project-documentation)\n- [Dependencies](#dependencies)\n- [Integrations](#http-frameworks-integrations)\n  - [Any Framework](#any-framework)\n  - [**FastAPI** Plugin](#fastapi-plugin)\n- [Stay in touch](#stay-in-touch)\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eProject History\u003c/b\u003e\u003c/summary\u003e\n\n**FastStream** is a package based on the ideas and experiences gained from [**FastKafka**](https://github.com/airtai/fastkafka) and [**Propan**](https://github.com/lancetnik/propan). By joining our forces, we picked up the best from both packages and created a unified way to write services capable of processing streamed data regardless of the underlying protocol.\n\u003c/details\u003e\n\n---\n\n## Versioning Policy\n\nFastStream has a stable public API. Only major updates may introduce breaking changes.\n\nPrior to FastStream's 1.0 release, each minor update is considered a major and can introduce breaking changes, but these changes were communicated through two-versions deprecation warnings prior to being fully removed. So features deprecated in the 0.4 version were only removed in version 0.6.\n\nOur team is working toward the stable 1.0 version.\n\n## Installation\n\n**FastStream** works on **Linux**, **macOS**, **Windows** and most **Unix**-style operating systems.\nYou can install it with `pip` as usual:\n\n```sh\npip install 'faststream[kafka]'\n# or\npip install 'faststream[confluent]'\n# or\npip install 'faststream[rabbit]'\n# or\npip install 'faststream[nats]'\n# or\npip install 'faststream[redis]'\n```\n\n---\n\n## Writing app code\n\n**FastStream** brokers provide convenient function decorators `@broker.subscriber`\nand `@broker.publisher` to allow you to delegate the actual process of:\n\n- consuming and producing data to Event queues, and\n\n- decoding and encoding JSON-encoded messages\n\nThese decorators make it easy to specify the processing logic for your consumers and producers, allowing you to focus on the core business logic of your application without worrying about the underlying integration.\n\nAlso, **FastStream** uses [**Pydantic**](https://docs.pydantic.dev/) to parse input\nJSON-encoded data into Python objects, making it easy to work with structured data in your applications, so you can serialize your input messages just using type annotations.\n\nHere is an example Python app using **FastStream** that consumes data from an incoming data stream and outputs the data to another one:\n\n```python\nfrom faststream import FastStream\nfrom faststream.kafka import KafkaBroker\n# from faststream.confluent import KafkaBroker\n# from faststream.rabbit import RabbitBroker\n# from faststream.nats import NatsBroker\n# from faststream.redis import RedisBroker\n\nbroker = KafkaBroker(\"localhost:9092\")\n# broker = RabbitBroker(\"amqp://guest:guest@localhost:5672/\")\n# broker = NatsBroker(\"nats://localhost:4222/\")\n# broker = RedisBroker(\"redis://localhost:6379/\")\n\napp = FastStream(broker)\n\n@broker.subscriber(\"in\")\n@broker.publisher(\"out\")\nasync def handle_msg(user: str, user_id: int) -\u003e str:\n    return f\"User: {user_id} - {user} registered\"\n```\n\n### Pydantic serialization\n\nAlso, **Pydantic**’s [`BaseModel`](https://docs.pydantic.dev/usage/models/) class allows you\nto define messages using a declarative syntax, making it easy to specify the fields and types of your messages.\n\n```python\nfrom pydantic import BaseModel, Field, PositiveInt\nfrom faststream import FastStream\nfrom faststream.kafka import KafkaBroker\n\nbroker = KafkaBroker(\"localhost:9092\")\napp = FastStream(broker)\n\nclass User(BaseModel):\n    user: str = Field(..., examples=[\"John\"])\n    user_id: PositiveInt = Field(..., examples=[\"1\"])\n\n@broker.subscriber(\"in\")\n@broker.publisher(\"out\")\nasync def handle_msg(data: User) -\u003e str:\n    return f\"User: {data.user} - {data.user_id} registered\"\n```\n\nBy default we use **PydanticV2** written in **Rust** as serialization library, but you can downgrade it manually, if your platform has no **Rust** support - **FastStream** will work correctly with **PydanticV1** as well.\n\nTo choose the **Pydantic** version, you can install the required one using the regular\n\n```shell\npip install pydantic==1.X.Y\n```\n\n**FastStream** (and **FastDepends** inside) should work correctly with almost any version.\n\n### Msgspec serialization\n\nMoreover, **FastStream** is not tied to any specific serialization library, so you can use any preferred one. Fortunately, we provide a built‑in alternative for the most popular **Pydantic** replacement - [**Msgspec**](https://jcristharif.com/msgspec/).\n\n```python\nfrom fast_depends.msgspec import MsgSpecSerializer\nfrom faststream.kafka import KafkaBroker\n\nbroker = KafkaBroker(serializer=MsgSpecSerializer())\n```\n\nYou can read more about the feature in the [documentation](https://faststream.ag2.ai/latest/gettings-started/subscription/msgspec/).\n\n### Unified API\n\nAt first glance, **FastStream** unifies various broker backends under a single API. However, a completely unified API inevitably results in missing features. We do not want to limit users' choices. If you prefer Kafka over Redis, there is a reason. Therefore, we support all native broker features you need.\n\nConsequently, our unified API has a relatively limited scope:\n\n```python\nfrom faststream.[broker] import [Broker], [Broker]Message\n\nbroker = [Broker](*servers)\n\n@broker.subscriber([source])  # Kafka topic / RMQ queue / NATS subject / etc\n@broker.publisher([destination])  # topic / routing key / subject / etc\nasync def handler(msg: [Broker]Message) -\u003e None:\n    await msg.ack()  # control brokers' acknowledgement policy\n\n...\n\nawait broker.publish(\"Message\", [destiination])\n```\n\nBeyond this scope you can use any broker-native features you need:\n\n* **Kafka** - specific partition reads, partitioner control, consumer groups, batch processing, etc.\n* **RabbitMQ** - all exchange types, Redis Streams, RPC, manual channel configuration, DLQ, etc.\n* **NATS** - core and Push/Pull JetStream subscribers, KeyValue, ObjectStorage, RPC, etc.\n* **Redis** - Pub/Sub, List, Stream subscribers, consumer groups, acknowledgements, etc.\n\nYou can find detailed information about all supported features in **FastStream**’s broker‑specific documentation.\n\nIf a particular feature is missing or not yet supported, you can always fall back to the native broker client/connection for those operations.\n\n---\n\n## Testing the service\n\nThe service can be tested using the `TestBroker` context managers, which, by default, puts the Broker into \"testing mode\".\n\nThe Tester will redirect your `subscriber` and `publisher` decorated functions to the InMemory brokers, allowing you to quickly test your app without the need for a running broker and all its dependencies.\n\nUsing pytest, the test for our service would look like this:\n\n```python\n\nimport pytest\nimport pydantic\nfrom faststream.kafka import TestKafkaBroker\n\n\n@pytest.mark.asyncio\nasync def test_correct():\n    async with TestKafkaBroker(broker) as br:\n        await br.publish({\n            \"user\": \"John\",\n            \"user_id\": 1,\n        }, \"in\")\n\n@pytest.mark.asyncio\nasync def test_invalid():\n    async with TestKafkaBroker(broker) as br:\n        with pytest.raises(pydantic.ValidationError):\n            await br.publish(\"wrong message\", \"in\")\n```\n\n---\n\n## Running the application\n\nThe application can be started using built-in **FastStream** CLI command.\n\nBefore running the service, install **FastStream CLI** using the following command:\n\n```shell\npip install \"faststream[cli]\"\n```\n\nTo run the service, use the **FastStream CLI** command and pass the module (in this case, the file where the app implementation is located) and the app symbol to the command.\n\n```shell\nfaststream run basic:app\n```\n\nAfter running the command, you should see the following output:\n\n```shell\nINFO     - FastStream app starting...\nINFO     - input_data |            - `HandleMsg` waiting for messages\nINFO     - FastStream app started successfully! To exit press CTRL+C\n```\n\nAlso, **FastStream** provides you with a great hot reload feature to improve your Development Experience\n\n```shell\nfaststream run basic:app --reload\n```\n\nAnd multiprocessing horizontal scaling feature as well:\n\n```shell\nfaststream run basic:app --workers 3\n```\n\nYou can learn more about **CLI** features [here](https://faststream.ag2.ai/latest/getting-started/cli/)\n\n---\n\n## Project Documentation\n\n**FastStream** automatically generates documentation for your project according to the [**AsyncAPI**](https://www.asyncapi.com/) specification. You can work with both generated artifacts and place a web view of your documentation on resources available to related teams.\n\nThe availability of such documentation significantly simplifies the integration of services: you can immediately see what channels and message formats the application works with. And most importantly, it won't cost anything - **FastStream** has already created the docs for you!\n\n![HTML-page](https://github.com/ag2ai/faststream/blob/main/docs/docs/assets/img/AsyncAPI-basic-html-short.png?raw=true)\n\n---\n\n## Dependencies\n\n**FastStream** (thanks to [**FastDepends**](https://lancetnik.github.io/FastDepends/)) has a dependency management system similar to `pytest fixtures` and `FastAPI Depends` at the same time. Function arguments declare which dependencies you want are needed, and a special decorator delivers them from the global Context object.\n\n```python\nfrom typing import Annotated\nfrom faststream import Depends, Logger\n\nasync def base_dep(user_id: int) -\u003e bool:\n    return True\n\n@broker.subscriber(\"in-test\")\nasync def base_handler(user: str,\n                       logger: Logger,\n                       dep: Annotated[bool, Depends(base_dep)]):\n    assert dep is True\n    logger.info(user)\n```\n\n---\n\n## HTTP Frameworks integrations\n\n### Any Framework\n\nYou can use **FastStream** `MQBrokers` without a `FastStream` application.\nJust *start* and *stop* them according to your application's lifespan.\n\n```python\nfrom aiohttp import web\n\nfrom faststream.kafka import KafkaBroker\n\nbroker = KafkaBroker(\"localhost:9092\")\n\n@broker.subscriber(\"test\")\nasync def base_handler(body):\n    print(body)\n\nasync def start_broker(app):\n    await broker.start()\n\nasync def stop_broker(app):\n    await broker.stop()\n\nasync def hello(request):\n    return web.Response(text=\"Hello, world\")\n\napp = web.Application()\napp.add_routes([web.get(\"/\", hello)])\napp.on_startup.append(start_broker)\napp.on_cleanup.append(stop_broker)\n\nif __name__ == \"__main__\":\n    web.run_app(app)\n```\n\n### **FastAPI** Plugin\n\nAlso, **FastStream** can be used as part of **FastAPI**.\n\nJust import a **StreamRouter** you need and declare the message handler with the same `@router.subscriber(...)` and `@router.publisher(...)` decorators.\n\n```python\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\n\nfrom faststream.kafka.fastapi import KafkaRouter\n\nrouter = KafkaRouter(\"localhost:9092\")\n\nclass Incoming(BaseModel):\n    m: dict\n\n@router.subscriber(\"test\")\n@router.publisher(\"response\")\nasync def hello(m: Incoming):\n    return {\"response\": \"Hello, world!\"}\n\napp = FastAPI()\napp.include_router(router)\n```\n\nMore integration features can be found [here](https://faststream.ag2.ai/latest/getting-started/integrations/fastapi/)\n\n---\n\n## Benchmarks\nWe use codspeed to run benchmarks for both FastStream itself and raw clients.\n\n## Stay in touch\n\nPlease show your support and stay in touch by:\n\n- giving our [GitHub repository](https://github.com/ag2ai/faststream/) a star, and\n\n- joining our [EN Discord server](https://discord.gg/qFm6aSqq59)\n\n- joining our [RU Telegram group](https://t.me/python_faststream)\n\nYour support helps us to stay in touch with you and encourages us to\ncontinue developing and improving the framework. Thank you for your\nsupport!\n\n---\n\n## Contributors\n\nThanks to all of these amazing people who made the project better!\n\n\u003ca href=\"https://github.com/ag2ai/faststream/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=ag2ai/faststream\"/\u003e\n\u003c/a\u003e\n","funding_links":[],"categories":["Python","FastStream"],"sub_categories":["Table of Content"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fag2ai%2Ffaststream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fag2ai%2Ffaststream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fag2ai%2Ffaststream/lists"}