fsspec / universal_pathlib

pathlib api extended to use fsspec backends
MIT License
240 stars 42 forks source link

Reuse s3 boto client? #168

Open theogaraj opened 9 months ago

theogaraj commented 9 months ago

I am starting to use upath a lot, it makes things so much easier! This is not an issue/bug, just a question (this github repo doesn't seem to have a "discussions" section).

I imagine that for S3 paths, somewhere under the hood upath is using boto3 and creating an S3 boto3 client.

If I create multiple UPaths, is each one creating a separate boto3 client? Or does it have a mechanism to reuse a client?

I am using both upath as well as smart_open, and the latter supports the ability to pass in your own boto3 client (described here). I couldn't find anything in the upath documentation, is this handled implicitly or just not supported?

ap-- commented 8 months ago

Hello @theogaraj,

universal_pathlib's s3 support depends on s3fs which in turn uses aiobotocore

You can pass keyword arguments down to aiobotocore via client_kwargs in s3fs: https://github.com/fsspec/s3fs/blob/34a32198188164fd48d4d1abcb267f033d1d1ce1/s3fs/core.py#L205

this would look like this:

aioboto_client_kwargs = {'somesetting': ...}

UPath("s3://mybucket/somefile.tar", client_kwargs=aioboto_client_kwargs)

Let me know if that helps, Andreas