{"id":23709,"library":"fastapi-cloudevents","title":"FastAPI CloudEvents","description":"A FastAPI plugin for integrating CloudEvents. Current version 2.0.2, release cadence: sporadic.","status":"active","version":"2.0.2","language":"python","source_language":"en","source_url":"https://github.com/sasha-tkachev/fastapi-cloudevents","tags":["fastapi","cloudevents","events","middleware"],"install":[{"cmd":"pip install fastapi-cloudevents","lang":"bash","label":"install from PyPI"}],"dependencies":[],"imports":[{"note":"CloudEvent data model is from cloudevents SDK, not from fastapi-cloudevents.","wrong":"from fastapi_cloudevents import CloudEvent","symbol":"CloudEvent","correct":"from cloudevents.http import CloudEvent"},{"note":"","wrong":null,"symbol":"from_event","correct":"from fastapi_cloudevents import from_event"},{"note":"","wrong":null,"symbol":"to_event","correct":"from fastapi_cloudevents import to_event"}],"quickstart":{"code":"from fastapi import FastAPI, Request\nfrom fastapi_cloudevents import from_event, to_event\nfrom cloudevents.http import CloudEvent\n\napp = FastAPI()\n\n@app.post(\"/\")\nasync def receive(request: Request):\n    event = from_event(request)\n    print(event)\n    return to_event(CloudEvent({\"type\": \"example\", \"source\": \"test\"}, {\"message\": \"Hello\"}))","lang":"python","description":"Basic example of receiving and sending CloudEvents with FastAPI."},"warnings":[{"fix":"Use Pydantic V2 or pin fastapi-cloudevents<2.0.0.","message":"Version 2.0.0 introduced Pydantic V2 support, dropping V1. If your project uses Pydantic V1, stay on v1.x or migrate models.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Pass the `Request` object from FastAPI endpoint, not a dict.","message":"Use of `from_event` on raw dicts is deprecated; always pass a FastAPI Request object.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Return the response directly from your endpoint, or inspect the body via `response.body`.","message":"The `to_event` function returns a Starlette Response, not a CloudEvent object. Do not try to call `.data` on it.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install `cloudevents` and import `CloudEvent` from `cloudevents.http`.","cause":"CloudEvent class is not part of fastapi-cloudevents; it comes from the cloudevents SDK.","error":"ImportError: cannot import name 'CloudEvent' from 'fastapi_cloudevents'"},{"fix":"Use `await request.body()` instead of `request.body`.","cause":"Trying to access `.body` on a Request that hasn't been read yet (async context).","error":"AttributeError: 'Request' object has no attribute 'body'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}