Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement file handling independent of aiofiles, add support for file-like objects #480

Closed
wants to merge 1 commit into from

Conversation

tiangolo
Copy link
Sponsor Member

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
Member

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
Sponsor Member 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
Sponsor Member

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
Sponsor Member 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.

None yet

5 participants