-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy path__init__.py
More file actions
160 lines (143 loc) · 5.05 KB
/
__init__.py
File metadata and controls
160 lines (143 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright the Vortex contributors
from collections.abc import Callable
from typing import TypeAlias, Unpack, overload
from .._lib import store as _store # pyright: ignore[reportMissingModuleSource]
from ._aws import S3Config, S3Credential, S3CredentialProvider, S3Store
from ._azure import (
AzureAccessKey,
AzureBearerToken,
AzureConfig,
AzureCredential,
AzureCredentialProvider,
AzureSASToken,
AzureStore,
)
from ._client import ClientConfig
from ._gcs import GCSConfig, GCSCredential, GCSCredentialProvider, GCSStore
from ._http import HTTPStore
from ._local import LocalStore
from ._memory import MemoryStore
from ._retry import BackoffConfig, RetryConfig
ObjectStore: TypeAlias = AzureStore | GCSStore | HTTPStore | S3Store | LocalStore | MemoryStore
"""All supported ObjectStore implementations."""
@overload
def from_url(
url: str,
*,
config: S3Config | None = None,
client_options: ClientConfig | None = None,
retry_config: RetryConfig | None = None,
credential_provider: S3CredentialProvider | None = None,
**kwargs: Unpack[S3Config],
) -> ObjectStore: ...
@overload
def from_url(
url: str,
*,
config: GCSConfig | None = None,
client_options: ClientConfig | None = None,
retry_config: RetryConfig | None = None,
credential_provider: GCSCredentialProvider | None = None,
**kwargs: Unpack[GCSConfig],
) -> ObjectStore: ...
@overload
def from_url(
url: str,
*,
config: AzureConfig | None = None,
client_options: ClientConfig | None = None,
retry_config: RetryConfig | None = None,
credential_provider: AzureCredentialProvider | None = None,
**kwargs: Unpack[AzureConfig],
) -> ObjectStore: ...
@overload
def from_url(
url: str,
*,
config: None = None,
client_options: None = None,
retry_config: None = None,
automatic_cleanup: bool = False,
mkdir: bool = False,
) -> ObjectStore: ...
def from_url( # type: ignore[misc] # docstring in pyi file
url: str,
*,
config: S3Config | GCSConfig | AzureConfig | None = None,
client_options: ClientConfig | None = None,
retry_config: RetryConfig | None = None,
credential_provider: Callable[..., object] | None = None,
**kwargs: object,
) -> ObjectStore:
"""Easy construction of store by URL, identifying the relevant store.
This will defer to a store-specific ``from_url`` constructor based on the provided
``url``. E.g. passing ``"s3://bucket/path"`` will defer to
:meth:`S3Store.from_url <vortex.store.S3Store.from_url>`.
Supported formats:
- ``file:///path/to/my/file`` -> :class:`~vortex.store.LocalStore`
- ``memory:///`` -> :class:`~vortex.store.MemoryStore`
- ``s3://bucket/path`` -> :class:`~vortex.store.S3Store` (also supports ``s3a``)
- ``gs://bucket/path`` -> :class:`~vortex.store.GCSStore`
- ``az://account/container/path`` -> :class:`~vortex.store.AzureStore` (also
supports ``adl``, ``azure``, ``abfs``, ``abfss``)
- ``http://mydomain/path`` -> :class:`~vortex.store.HTTPStore`
- ``https://mydomain/path`` -> :class:`~vortex.store.HTTPStore`
There are also special cases for AWS and Azure for ``https://{host?}/path`` paths:
- ``dfs.core.windows.net``, ``blob.core.windows.net``, ``dfs.fabric.microsoft.com``,
``blob.fabric.microsoft.com`` -> :class:`~vortex.store.AzureStore`
- ``amazonaws.com`` -> :class:`~vortex.store.S3Store`
- ``r2.cloudflarestorage.com`` -> :class:`~vortex.store.S3Store`
.. note::
For best static typing, use the constructors on individual store classes
directly.
Args:
url: well-known storage URL.
Keyword Args:
config: per-store Configuration. Values in this config will override values
inferred from the url. Defaults to None.
client_options: HTTP Client options. Defaults to None.
retry_config: Retry configuration. Defaults to None.
credential_provider: A callback to provide custom credentials to the underlying store classes.
kwargs: per-store configuration passed down to store-specific builders.
"""
return _store.from_url( # pyright: ignore[reportCallIssue, reportUnknownVariableType]
url,
config=config, # pyright: ignore[reportArgumentType]
client_options=client_options,
retry_config=retry_config,
credential_provider=credential_provider, # pyright: ignore[reportArgumentType]
**kwargs, # pyright: ignore[reportArgumentType]
)
__all__ = [
# Azure
"AzureAccessKey",
"AzureBearerToken",
"AzureConfig",
"AzureCredential",
"AzureCredentialProvider",
"AzureSASToken",
"AzureStore",
# Client
"BackoffConfig",
"ClientConfig",
"RetryConfig",
# GCS
"GCSConfig",
"GCSCredential",
"GCSCredentialProvider",
"GCSStore",
# HTTP
"HTTPStore",
# Local
"LocalStore",
"MemoryStore",
# S3
"S3Config",
"S3Credential",
"S3CredentialProvider",
"S3Store",
# Utility
"from_url",
"ObjectStore",
]