question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to cache `StreamingResponse`?

See original GitHub issue

Hi, is there a way to cache StreamingResponse?

Currently i get:

ValueError: [TypeError("'async_generator' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jegorkcommented, Nov 5, 2022

I can draft a solution via subclassing StreamingResponse (I think it will be less error-prone). Regarding the finiteness of the iterator, I can try adding both time and size constraints.

0reactions
mglowinski93commented, Nov 5, 2022

I also think, that overwritting ‘stream_response’ would be better solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to cache StreamReponse or make a cache middleware
I'd like to make a general cache middleware and wrote code above. ... So it's basically fine to read data from StreamingResponse.
Read more >
How to cache StreamingResponse? - python - Stack Overflow
I tried aiocache package and fastapi-cache package, but all this kind of packages try to convert value being cached to JSON or even...
Read more >
Custom Response - HTML, Stream, File, others - FastAPI
Using StreamingResponse with file-like objects¶. If you have a file-like object (e.g. the object returned by open() ), you can create a generator...
Read more >
Received & return a file from in-memory buffer using FastAPI
The right way of sending a file from memory is by using StreamingResponse , but StreamingResponse requires an iterator object, e.g.. from ...
Read more >
Responses - Starlette
Takes an async generator or a normal generator/iterator and streams the response body. from starlette.responses import StreamingResponse import asyncio async ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found