65
65
S3ConfigInput ,
66
66
)
67
67
68
- SUPPORTED_PROTOCOLS = {
68
+ SUPPORTED_PROTOCOLS : set [ str ] = {
69
69
"abfs" ,
70
70
"abfss" ,
71
71
"adl" ,
80
80
"s3" ,
81
81
"s3a" ,
82
82
}
83
+ """All supported protocols."""
84
+
85
+ SUPPORTED_PROTOCOLS_T = Literal [
86
+ "abfs" ,
87
+ "abfss" ,
88
+ "adl" ,
89
+ "az" ,
90
+ "azure" ,
91
+ "file" ,
92
+ "gcs" ,
93
+ "gs" ,
94
+ "http" ,
95
+ "https" ,
96
+ "memory" ,
97
+ "s3" ,
98
+ "s3a" ,
99
+ ]
100
+ """A type hint for all supported protocols."""
83
101
84
102
85
103
class FsspecStore (fsspec .asyn .AsyncFileSystem ):
@@ -747,24 +765,44 @@ def loc(self, value: int) -> None:
747
765
raise ValueError ("Cannot set `.loc`. Use `seek` instead." )
748
766
749
767
750
- def register (protocol : str | Iterable [str ], * , asynchronous : bool = False ) -> None :
768
+ def register (
769
+ protocol : SUPPORTED_PROTOCOLS_T
770
+ | str
771
+ | Iterable [SUPPORTED_PROTOCOLS_T ]
772
+ | Iterable [str ]
773
+ | None = None ,
774
+ * ,
775
+ asynchronous : bool = False ,
776
+ ) -> None :
751
777
"""Dynamically register a subclass of FsspecStore for the given protocol(s).
752
778
753
779
This function creates a new subclass of FsspecStore with the specified
754
780
protocol and registers it with fsspec. If multiple protocols are provided,
755
781
the function registers each one individually.
756
782
757
783
Args:
758
- protocol (str | list[str]): A single protocol (e.g., "s3", "gcs", "abfs") or
759
- a list of protocols to register FsspecStore for.
760
- asynchronous (bool, optional): If True, the registered store will support
761
- asynchronous operations. Defaults to False.
784
+ protocol: A single protocol (e.g., "s3", "gcs", "abfs") or
785
+ a list of protocols to register FsspecStore for. Defaults to `None`, which
786
+ will register `obstore` as the provider for all [supported
787
+ protocols][obstore.fsspec.SUPPORTED_PROTOCOLS] **except** for `file://` and
788
+ `memory://`. If you wish to use `obstore` via fsspec for `file://` or
789
+ `memory://` URLs, list them explicitly.
790
+ asynchronous: If `True`, the registered store will support
791
+ asynchronous operations. Defaults to `False`.
762
792
763
793
Example:
764
794
```py
795
+ # Register obstore as the default handler for all supported protocols except for
796
+ # `memory://` and `file://`
797
+ register()
798
+
765
799
register("s3")
766
- register("s3", asynchronous=True) # Registers an async store for "s3"
767
- register(["gcs", "abfs"]) # Registers both "gcs" and "abfs"
800
+
801
+ # Registers an async store for "s3"
802
+ register("s3", asynchronous=True)
803
+
804
+ # Registers both "gcs" and "abfs"
805
+ register(["gcs", "abfs"])
768
806
```
769
807
770
808
Notes:
@@ -773,6 +811,9 @@ def register(protocol: str | Iterable[str], *, asynchronous: bool = False) -> No
773
811
FsspecStore class.
774
812
775
813
"""
814
+ if protocol is None :
815
+ protocol = SUPPORTED_PROTOCOLS - {"file" , "memory" }
816
+
776
817
if isinstance (protocol , str ):
777
818
_register (protocol , asynchronous = asynchronous )
778
819
return
0 commit comments