You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See {doc}`../user-guide/connecting-to-storage` for path and authority handling
33
33
with bucket-scoped services.
34
34
35
+
## Read and write CSV with S3 URLs
36
+
37
+
Register `S3FileSystem` before using pandas with `s3://` URLs. This selects OpenDAL for subsequent fsspec S3 lookups in the current process; it is not required for `opendal+s3://` URLs.
38
+
39
+
This example uses the local MinIO service and existing bucket described in {doc}`../user-guide/connecting-to-storage`. Set the environment variables below to connect to your own storage. The default credentials are only for local development.
Each OpenDAL S3 filesystem is scoped to one bucket. See {doc}`../reference/configuration` for the supported s3fs configuration options; not every s3fs feature is available.
71
+
35
72
## Test coverage
36
73
37
74
The repository tests:
38
75
39
76
- CSV and Parquet URL operations through `opendal+s3`
40
77
- Parquet round trips with an explicit filesystem
41
78
79
+
The documentation example checker also executes the `s3://` CSV round trip above.
80
+
42
81
The test runs against memory, local filesystem, and MinIO-backed S3 fixtures.
Copy file name to clipboardExpand all lines: docs/reference/configuration.md
+8-1Lines changed: 8 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,9 @@ fs = OpendalFileSystem(
48
48
Use the [OpenDAL service directory](https://opendal.apache.org/services/) as the
49
49
configuration reference. Option names pass through unchanged.
50
50
51
-
The `S3FileSystem` adapter accepts these common `s3fs` aliases:
51
+
## S3 compatibility options
52
+
53
+
The `S3FileSystem` adapter for `s3://` accepts the following `s3fs` aliases. These aliases do not apply to `OpendalFileSystem` or the `opendal+...` protocols, which use OpenDAL option names.
52
54
53
55
| s3fs option | OpenDAL S3 option |
54
56
| --- | --- |
@@ -66,11 +68,16 @@ The `S3FileSystem` adapter accepts these common `s3fs` aliases:
66
68
67
69
OpenDAL option names take precedence when both forms are provided.
`client_kwargs` must be a mapping. Top-level aliases take precedence over aliases inside `client_kwargs`.
72
+
73
+
`default_block_size` sets the filesystem's default block size in bytes. It is an adapter setting, not an OpenDAL service option. Other s3fs-specific options and features are not guaranteed to be compatible.
69
74
70
75
## URL-derived settings
71
76
72
77
Registered service adapters can derive one setting from the URL authority. For
73
78
example, `opendal+s3://my-bucket/path` supplies `bucket="my-bucket"`.
74
79
Explicit filesystem construction requires the bucket keyword instead.
75
80
81
+
For `s3://my-bucket/path`, `S3FileSystem` uses `my-bucket` even when a different `bucket` is present in the storage options. Paths passed to this filesystem include the bucket, such as `my-bucket/path`; the underlying OpenDAL operator receives the bucket-relative key.
82
+
76
83
Do not provide conflicting values through the URL and keyword arguments.
This explicit process-wide operation is the only way opendalfs changes the meaning of a standard protocol.
32
+
Installing or importing opendalfs does not replace fsspec's S3 implementation. The explicit registration above replaces it for subsequent lookups in the current process.
33
33
The adapter accepts the common s3fs constructor options listed in {doc}`configuration`.
34
-
Each adapter instance is scoped to one bucket; a multi-path operation spanning buckets raises`ValueError`.
34
+
Each adapter instance is scoped to one bucket; paths belonging to another bucket raise`ValueError`. This is not a complete replacement for every s3fs feature.
35
35
36
36
See {doc}`../user-guide/connecting-to-storage` for complete examples.
Copy file name to clipboardExpand all lines: docs/user-guide/connecting-to-storage.md
+88-13Lines changed: 88 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,12 @@ An `opendalfs` filesystem needs an OpenDAL service name and that service's
4
4
configuration. Choose the construction style that matches the library you are
5
5
using.
6
6
7
+
| Your application accepts | Use |
8
+
| --- | --- |
9
+
| A filesystem, mapping, or file-like object |`OpendalFileSystem("service", ...)`|
10
+
| An explicit OpenDAL URL |`opendal+s3://`, `opendal+gcs://`, or `opendal+azblob://`|
11
+
| An `s3://` URL | Register `S3FileSystem` with fsspec before using it |
12
+
7
13
## Construct the filesystem directly
8
14
9
15
Use {class}`opendalfs.OpendalFileSystem` when your code controls the filesystem
@@ -23,6 +29,19 @@ fs = OpendalFileSystem(
23
29
The first argument selects the OpenDAL service. Remaining service-specific
24
30
keyword arguments are passed to the OpenDAL Python binding.
25
31
32
+
This also works for services without a URL adapter. For example, the local filesystem service needs no credentials:
33
+
34
+
```python
35
+
from tempfile import TemporaryDirectory
36
+
37
+
with TemporaryDirectory() as directory:
38
+
fs = OpendalFileSystem("fs", root=directory)
39
+
fs.pipe_file("hello.txt", b"Hello from OpenDAL!")
40
+
assert fs.cat_file("hello.txt") ==b"Hello from OpenDAL!"
41
+
```
42
+
43
+
Available services depend on the installed OpenDAL Python binding. Pass the filesystem, its mapping, or an opened file to libraries that accept these objects; no protocol registration is needed.
44
+
26
45
## Ask fsspec for a registered filesystem
27
46
28
47
The package installs fsspec entry points for S3, Google Cloud Storage, and Azure
@@ -38,31 +57,70 @@ fs = fsspec.filesystem(
38
57
)
39
58
```
40
59
41
-
## Keep an existing S3 URL
60
+
## Use S3 URLs
42
61
43
-
Applications that cannot rewrite existing `s3://` URLs can explicitly replace fsspec's S3 implementation:
62
+
Register `S3FileSystem` to use OpenDAL with `s3://` URLs and the supported s3fs configuration options:
The registration replaces the S3 implementation for subsequent fsspec lookups in the current process. Run it during application startup, before constructing an S3 filesystem. Installing or importing `opendalfs` does not change `s3://`. Use `opendal+s3://` if you do not want to change the process-wide registration.
72
+
73
+
### Write and read a file
74
+
75
+
The following example uses a local MinIO service at `http://127.0.0.1:9000` with an existing `test-bucket` bucket. The default credentials are for local development only. Set the `OPENDAL_S3_*` environment variables to use your own endpoint, credentials, and bucket.
76
+
77
+
When working from this repository, `podman compose up -d --wait` starts the MinIO service. Create the bucket in the MinIO console at `http://localhost:9001` before running the example; the repository's documentation checks create their test bucket automatically.
with fsspec.open(url, "wt", **storage_options) as stream:
94
+
stream.write("Hello from OpenDAL!")
95
+
96
+
with fsspec.open(url, "rt", **storage_options) as stream:
97
+
assert stream.read() =="Hello from OpenDAL!"
57
98
```
58
99
59
-
The registration call is process-wide and should run during application startup, before constructing an S3 filesystem.
60
-
`S3FileSystem` translates common s3fs names such as `key`, `secret`, `token`, `anon`, and supported `client_kwargs`.
61
-
Installing `opendalfs` alone never changes `s3://`.
100
+
The same `storage_options` can be passed to downstream libraries; see the {doc}`../integrations/pandas` example. The complete list of supported s3fs aliases is in {doc}`../reference/configuration`.
101
+
102
+
### Bucket scope and compatibility
62
103
63
104
An OpenDAL S3 operator is scoped to one bucket, so each `S3FileSystem` instance is also scoped to one bucket.
64
-
Independent fsspec calls can use different buckets.
65
-
A single multi-path operation spanning buckets raises `ValueError` instead of sending a path to the wrong bucket.
105
+
`url_to_fs` takes the bucket from the URL and returns a bucket-prefixed path:
pass# This filesystem cannot access another bucket.
116
+
else:
117
+
raiseAssertionError("A path in another bucket must be rejected")
118
+
119
+
```
120
+
121
+
Independent fsspec calls can use different buckets; create a separate filesystem for each bucket. When constructing `S3FileSystem` directly, pass `bucket=...` explicitly.
122
+
123
+
The adapter does not implement every s3fs option or feature. Only the aliases listed in the configuration reference are supported as s3fs options; unsupported `client_kwargs` raise `TypeError`.
Other OpenDAL services intentionally have no URL adapter.
84
158
Construct `OpendalFileSystem` directly and pass the filesystem, mapping, or opened file to the consuming library.
159
+
For application-defined URL protocols, use fsspec's `register_implementation()` with a filesystem class that implements the protocol's URL and path rules. Registration alone does not add those rules to `OpendalFileSystem`.
0 commit comments