Skip to content

Allow returning memoryview in StreamingResponse#2576

Merged
adriangb merged 1 commit intoKludex:masterfrom
bschoenmaeckers:master
Apr 22, 2024
Merged

Allow returning memoryview in StreamingResponse#2576
adriangb merged 1 commit intoKludex:masterfrom
bschoenmaeckers:master

Conversation

@bschoenmaeckers
Copy link
Contributor

@bschoenmaeckers bschoenmaeckers commented Apr 22, 2024

Summary

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Copy link
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@adriangb adriangb merged commit 9fd3ecc into Kludex:master Apr 22, 2024
@Kludex
Copy link
Owner

Kludex commented Apr 23, 2024

What's the use case? To create the memoryview you need bytes or bytearray anyway...

@bschoenmaeckers
Copy link
Contributor Author

Memoryview allows you to efficiently return a slice of the original bytes value without copying. This is especially convenient when you want to strip some prefix or header of some value in memory you don’t control.

@adriangb
Copy link
Contributor

Yup I'd say the use cases are varied, it allows moving around bytes with zero copying.

@Kludex
Copy link
Owner

Kludex commented Apr 28, 2024

This is a PR without description, and there's a single discussion that mentioned this feature request (that is 4 years old) without reactions.

Also, this can be easily done by overriding the stream_response method. And that's what we've always recommended.

@adriangb
Copy link
Contributor

Feel free to revert it if you don’t agree. To me it made sense and was simple.

@danielballan
Copy link

Thanks for this! Useful when transmitting buffers from numpy array without copying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants