Comments (2)
Hi @DayalStrub
You should be able to achieve what you want, in a few different ways:
- aws profiles can be provided via storage options directly, see: https://s3fs.readthedocs.io/en/latest/#credentials
p1 = UPath("s3://bucket/file", profile="shared1") p2 = UPath("s3://bucket/file", profile="shared2")
- filesystem instances are cached depending on your provided storage_options (the keyword arguments in
UPath
) see: https://github.com/fsspec/filesystem_spec/blob/d969b9601e4aaf5922cb00d82b869bf4b4affd95/fsspec/spec.py#L69-L78
This means that the filesystem instances are identical if (simplifying a bit) their storage_options are identicalUPath("s3://bucket/something").fs is UPath("s3://bucket/bla").fs
. You can prevent that caching from occuring by using a special keyword argument:UPath("s3://bucket/file", skip_instance_cache=True)
- You can clear clear the instance cache of a specific filesystem class manually by running:
import fsspec os.environ["AWS_PROFILE"] = "shared1" p1 = UPath("s3://bucket/foo") # clear the instance cache for the fsspec class associated to the "s3" protocol fsspec.get_filesystem_class(p1.protocol).clear_instance_cache() os.environ["AWS_PROFILE"] = "shared2" p2 = UPath("s3://bucket/bar")
Let me know if that helps,
Andreas
from universal_pathlib.
super helpful! thanks!
for what i had in mind, where i might use one profile for a while/some paths then switch, i think option 3 works great, and i would maybe make a helper function and pass the protocol directly, eg something like
def set_profile(profile):
fsspec.get_filesystem_class("s3").clear_instance_cache()
os.environ["AWS_PROFILE"] = profile
set_profile("shared1")
p1 = UPath("s3://bucket/foo")
p2 = UPath("s3://bucket/bar")
set_profile("shared2")
p3 = UPath("s3://bucket/baz")
i'll close the issue - but do think it would make a great Discussion, given the great answer. guess people can search old tickets too.
from universal_pathlib.
Related Issues (20)
- Passing abfs as fs parameter to UPath fails. HOT 3
- SSH / SFTP Implementations HOT 5
- s3fs kwarg unexpected keyword argument in `AioSession` HOT 2
- Static analysis of types broken in `>=0.2.0` HOT 1
- Relative paths don't work when `_protocol_dispatch = False`. HOT 4
- Behaviour of joinpath when the second path has protocol HOT 6
- `relative_to` doesn't work for FilePath HOT 2
- `S3Path.touch` with `exist_ok=True` on existing file raises an error HOT 3
- v0.2.2 breaks SMBFilesystem HOT 4
- `pip install -e .` under Python 3.12.3, pip 24.0 fails because `description` is not dynamic HOT 8
- Support for huggingface filesystem `hf` protocol
- Test against 3.13
- Prepare for release v0.3.0
- `path.iterdir()` yields `path` itself as the first item (with S3) HOT 6
- Efficient copying via shutil HOT 5
- Investigate python3.12 http fs path parsing errors HOT 3
- rename (move) file over different file system HOT 3
- Cannot use UPath on S3 with pandas: PermissionError/Access Denied HOT 3
- Test regressions with Python 3.13 HOT 1
- samefile() is not implemented HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from universal_pathlib.