Skip to content

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

Merged
Xuanwo merged 2 commits intomainfrom
python-api
Nov 4, 2023
Merged

feat(bindings/python)!: Implement File and AsyncFile to replace Reader#3474
Xuanwo merged 2 commits intomainfrom
python-api

Conversation

@Xuanwo
Copy link
Copy Markdown
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
@github-actions github-actions Bot added the releases-note/feat The PR implements a new feature or has a title that begins with "feat" label Nov 3, 2023
Signed-off-by: Xuanwo <github@xuanwo.io>
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread bindings/python/src/file.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/feat The PR implements a new feature or has a title that begins with "feat"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python: Expose AsyncWriter in python binding

3 participants