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

feat(bindings/python)!: Implement File and AsyncFile to replace Reader #3474

Merged
merged 2 commits into from
Nov 4, 2023

Conversation

Xuanwo
Copy link
Member

@Xuanwo Xuanwo commented Nov 3, 2023

Python users don't know about reader and writer, they are using File-like objects and context manager.

This PR add Operator::open and AsnycFile to make our API more native to python users.

Async version:

async with await op.open(filename, "rb") as r:
    content = await r.read()

Blocking version:

with op.open(filename, "rb") as r:
    content = r.read()

Writer is also supported in the same way:

async with await op.open(filename, "wb") as w:
    await w.write("Hello, World!")

Close #2570


Only wb and rb supported so far.

@Xuanwo Xuanwo requested a review from messense as a code owner November 3, 2023 10:27
@Xuanwo Xuanwo requested a review from Zheaoli November 3, 2023 10:27
@Xuanwo Xuanwo changed the title feat(bindings/python): Implement File and AsyncFile to replace Reader feat(bindings/python)!: Implement File and AsyncFile to replace Reader Nov 3, 2023
Signed-off-by: Xuanwo <github@xuanwo.io>
Copy link
Member

@Zheaoli Zheaoli left a comment

Choose a reason for hiding this comment

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

Mostly LGTM

Here may be something to follow up

  1. In Python, People may use r+b to use read and write API in the same object
  2. We may need test for context manager

@Xuanwo
Copy link
Member Author

Xuanwo commented Nov 3, 2023

In Python, People may use r+b to use read and write API in the same object

This is not allowed in opendal. We can't and don't want to support this use case.

@Xuanwo Xuanwo merged commit fd6cb67 into main Nov 4, 2023
60 checks passed
@Xuanwo Xuanwo deleted the python-api branch November 4, 2023 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python: Expose AsyncWriter in python binding
3 participants