You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "lizzzcai (via GitHub)" <gi...@apache.org> on 2024/10/18 07:17:52 UTC

[D] how to download files into local from remote [opendal]

GitHub user lizzzcai created a discussion: how to download files into local from remote

Hi, thanks for the project. I am exploring the [python sdk](https://opendal.apache.org/docs/python/opendal.html), want to check any example on how to efficiently download files from s3 to local like [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-download-file.html).

currently I am trying is:
```python
# Read the file from the S3 bucket
file_content = op.read("test.txt")

# Print the file content to verify
print(file_content)

# write file to local
with open("test.txt", "wb") as f:
    f.write(file_content)
```

GitHub link: https://github.com/apache/opendal/discussions/5200

----
This is an automatically sent email for commits@opendal.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@opendal.apache.org


Re: [D] how to download files into local from remote [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
GitHub user Xuanwo added a comment to the discussion: how to download files into local from remote

Hi, please try read like a file:

```py
import opendal
import polars as pl

# Init an operator.
op = opendal.Operator("fs", root="/tmp")

# Create a DataFrame.
df = pl.DataFrame({"name": ["Alice", "Bob"], "age": [20, 30]})
print(f"df: {df}")

# Open and write the DataFrame to the file.
with op.open("test.csv", mode="wb") as file:
    df.write_csv(file)

# Open and read the DataFrame from the file.
with op.open("test.csv", mode="rb") as file:
    read_df = pl.read_csv(file)
    print(f"read_df: {read_df}")
```


GitHub link: https://github.com/apache/opendal/discussions/5200#discussioncomment-10980384

----
This is an automatically sent email for commits@opendal.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@opendal.apache.org