{"id":5624,"library":"faststream","title":"FastStream","description":"FastStream is a modern, asynchronous framework designed to simplify interactions with various messaging queues (Kafka, RabbitMQ, Redis, NATS, MQTT). It provides an intuitive, FastAPI-like API for building message-driven applications, handling message serialization, dependency injection, and health checks. The current stable version is 0.6.7, with frequent minor releases and a significant 0.7.0 release candidate bringing breaking changes.","status":"active","version":"0.6.7","language":"en","source_language":"en","source_url":"https://github.com/ag2ai/FastStream","tags":["messaging","async","broker","kafka","redis","mqtt","nats","rabbitmq","data-streaming"],"install":[{"cmd":"pip install \"faststream[kafka]\"","lang":"bash","label":"Install with Kafka support"},{"cmd":"pip install faststream","lang":"bash","label":"Install core FastStream (no broker)"}],"dependencies":[{"reason":"Required for Kafka integration via `faststream[kafka]`","package":"aiokafka","optional":true},{"reason":"Used for data validation and serialization in messages","package":"pydantic","optional":false}],"imports":[{"symbol":"FastStream","correct":"from faststream import FastStream"},{"symbol":"Logger","correct":"from faststream import Logger"},{"note":"Broker imports are now directly from `faststream.<broker_name>` as of v0.7.0rc0 and likely stable 0.7.0. Older versions used `faststream.broker.<broker_name>`.","wrong":"from faststream.broker.kafka import KafkaBroker","symbol":"KafkaBroker","correct":"from faststream.kafka import KafkaBroker"},{"note":"Broker imports are now directly from `faststream.<broker_name>` as of v0.7.0rc0 and likely stable 0.7.0. Older versions used `faststream.broker.<broker_name>`.","wrong":"from faststream.broker.mqtt import MQTTBroker","symbol":"MQTTBroker","correct":"from faststream.mqtt import MQTTBroker"},{"symbol":"ContextRef","correct":"from faststream.types import ContextRef"}],"quickstart":{"code":"import os\nfrom faststream import FastStream, Logger\nfrom faststream.kafka import KafkaBroker\n\n# Configure Kafka broker connection\n# Use 'localhost:9092' for local Kafka, or environment variable for production\nKAFKA_BROKER_URL = os.environ.get('KAFKA_BROKER_URL', 'localhost:9092')\n\nbroker = KafkaBroker(KAFKA_BROKER_URL)\napp = FastStream(broker)\n\n@broker.subscriber('test-topic')\nasync def handle_message(msg: str, logger: Logger):\n    logger.info(f\"Received message: {msg}\")\n\n@app.on_startup\nasync def app_startup():\n    logger = Logger().bind(service=\"startup\")\n    logger.info(\"FastStream application started\")\n    # Example: publish a message on startup\n    await broker.publish(\"Hello, FastStream!\", topic='test-topic')\n\n@app.on_shutdown\nasync def app_shutdown():\n    logger = Logger().bind(service=\"shutdown\")\n    logger.info(\"FastStream application stopped\")\n\n# To run this application:\n# 1. Ensure Kafka is running.\n# 2. Save as `app.py`.\n# 3. `pip install \"faststream[kafka]\"`\n# 4. `faststream run app:app`","lang":"python","description":"This quickstart demonstrates a basic FastStream application with Kafka. It defines a Kafka broker, an application instance, and a subscriber that listens to 'test-topic'. A message is published on application startup for immediate testing. Ensure Kafka is running and FastStream is installed with Kafka extras to run."},"warnings":[{"fix":"Review your application for usage of deprecated features. For Redis, ensure your message formats are binary. Replace `broker.close()` with `broker.stop()`.","message":"Version 0.7.0 (release candidate available) removes several deprecated features. Specifically: publisher/subscriber-level middlewares, `ack_policy` now replaces several deprecated options, `RedisJSONMessageParser` is removed (Redis services must now use binary message format), and `broker.close` is replaced by `broker.stop`.","severity":"breaking","affected_versions":"<0.7.0 to 0.7.0+"},{"fix":"Update all broker import statements to the new direct path, e.g., `from faststream.kafka import KafkaBroker`.","message":"As of 0.7.0rc0 (and likely stable 0.7.0), import paths for specific brokers have changed. They are now directly under `faststream.<broker_name>` (e.g., `from faststream.kafka import KafkaBroker`) instead of `faststream.broker.<broker_name>`.","severity":"breaking","affected_versions":"<0.7.0 to 0.7.0+"},{"fix":"Always install FastStream with the necessary broker extras for your chosen messaging queue (e.g., `pip install \"faststream[kafka,redis]\"` for both).","message":"FastStream's core installation (`pip install faststream`) does not include broker-specific client libraries. You must install FastStream with the appropriate extras, e.g., `pip install \"faststream[kafka]\"`, `\"faststream[redis]\"`, `\"faststream[mqtt]\"`, etc. Failing to do so will result in `ModuleNotFoundError` when trying to import or use a broker.","severity":"gotcha","affected_versions":"all"},{"fix":"Consult the official FastStream 0.6.0 release notes and documentation regarding the new Middleware and Router APIs. Adjust your code to conform to the finalized API designs.","message":"Version 0.6.0 introduced significant changes to the Middleware API and Router API. Applications upgrading from versions prior to 0.6.0 may experience breaking changes related to how middlewares are defined and applied, and how routers are configured.","severity":"breaking","affected_versions":"<0.6.0 to 0.6.0+"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}