Skip to content

Conversation

@tiangolo
Copy link
Contributor

This PR removes aiofiles as a dependency, handling files directly.

It also adds support for file-like objects in FileResponse apart from file paths.

This is related to #461 and @tomchristie's comment at #457 (comment)

@florimondmanca
Copy link
Contributor

Good stuff!

Any reason why changing path to file_or_path instead of adding a new file parameter, and making sure only one of them is given? Would preserve the current API on FileResponse.

@tiangolo
Copy link
Contributor Author

Good point. Many libraries receive a file or path single parameter, this would be equivalent to that. E.g. Pillow: https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#PIL.Image.open

But having just an additional parameter would work the same.

@tomchristie what do you prefer?

@dhirschfeld
Copy link

An argument which can take either a file-like object or a path is quite a common idiom in Python and is, IMHO quite a user-friendly api.

Exposing two different arguments to a user and forcing them to choose depending on the type of object they have doesn't strike me as very pythonic - Python is duck-typed so the user shouldn't have to care about the type of argument they pass - the class should handle those details internally (as is done in this PR)

@Kludex
Copy link
Owner

Kludex commented Jun 26, 2021

Hola @tiangolo 👋

Closing this due to recent anyio integration and aiofiles removal on #1157.

@Kludex Kludex closed this Jun 26, 2021
@tiangolo
Copy link
Contributor Author

Nice! Thanks @Kludex for the cleanup. 🙇

@tiangolo tiangolo deleted the independent-request-files branch July 12, 2021 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

staticfiles Static file serving

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants