corebase 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- corebase/__init__.py +108 -0
- corebase/_async/__init__.py +1 -0
- corebase/_async/auth_client.py +55 -0
- corebase/_async/client.py +398 -0
- corebase/_sync/__init__.py +1 -0
- corebase/_sync/auth_client.py +55 -0
- corebase/_sync/client.py +393 -0
- corebase/auth/__init__.py +20 -0
- corebase/auth/_async/__init__.py +1 -0
- corebase/auth/_async/gotrue_admin_api.py +356 -0
- corebase/auth/_async/gotrue_admin_mfa_api.py +32 -0
- corebase/auth/_async/gotrue_admin_oauth_api.py +93 -0
- corebase/auth/_async/gotrue_base_api.py +78 -0
- corebase/auth/_async/gotrue_client.py +1404 -0
- corebase/auth/_async/gotrue_mfa_api.py +94 -0
- corebase/auth/_async/storage.py +31 -0
- corebase/auth/_sync/__init__.py +1 -0
- corebase/auth/_sync/gotrue_admin_api.py +356 -0
- corebase/auth/_sync/gotrue_admin_mfa_api.py +32 -0
- corebase/auth/_sync/gotrue_admin_oauth_api.py +93 -0
- corebase/auth/_sync/gotrue_base_api.py +78 -0
- corebase/auth/_sync/gotrue_client.py +1394 -0
- corebase/auth/_sync/gotrue_mfa_api.py +94 -0
- corebase/auth/_sync/storage.py +31 -0
- corebase/auth/constants.py +15 -0
- corebase/auth/errors.py +259 -0
- corebase/auth/helpers.py +288 -0
- corebase/auth/py.typed +0 -0
- corebase/auth/timer.py +53 -0
- corebase/auth/types.py +1021 -0
- corebase/auth/version.py +1 -0
- corebase/client.py +12 -0
- corebase/functions/__init__.py +47 -0
- corebase/functions/_async/__init__.py +1 -0
- corebase/functions/_async/functions_client.py +218 -0
- corebase/functions/_sync/__init__.py +1 -0
- corebase/functions/_sync/functions_client.py +218 -0
- corebase/functions/errors.py +62 -0
- corebase/functions/py.typed +0 -0
- corebase/functions/utils.py +33 -0
- corebase/functions/version.py +1 -0
- corebase/lib/__init__.py +3 -0
- corebase/lib/client_options.py +189 -0
- corebase/migrate/__init__.py +374 -0
- corebase/migrate/__main__.py +7 -0
- corebase/postgrest/__init__.py +62 -0
- corebase/postgrest/_async/__init__.py +1 -0
- corebase/postgrest/_async/client.py +206 -0
- corebase/postgrest/_async/request_builder.py +503 -0
- corebase/postgrest/_sync/__init__.py +1 -0
- corebase/postgrest/_sync/client.py +206 -0
- corebase/postgrest/_sync/request_builder.py +503 -0
- corebase/postgrest/base_client.py +61 -0
- corebase/postgrest/base_request_builder.py +787 -0
- corebase/postgrest/constants.py +6 -0
- corebase/postgrest/exceptions.py +115 -0
- corebase/postgrest/py.typed +0 -0
- corebase/postgrest/types.py +72 -0
- corebase/postgrest/utils.py +91 -0
- corebase/postgrest/version.py +1 -0
- corebase/py.typed +0 -0
- corebase/realtime/__init__.py +17 -0
- corebase/realtime/_async/__init__.py +0 -0
- corebase/realtime/_async/channel.py +766 -0
- corebase/realtime/_async/client.py +498 -0
- corebase/realtime/_async/presence.py +185 -0
- corebase/realtime/_async/push.py +162 -0
- corebase/realtime/_async/timer.py +41 -0
- corebase/realtime/_sync/__init__.py +0 -0
- corebase/realtime/_sync/channel.py +30 -0
- corebase/realtime/_sync/client.py +71 -0
- corebase/realtime/_sync/presence.py +10 -0
- corebase/realtime/exceptions.py +38 -0
- corebase/realtime/message.py +176 -0
- corebase/realtime/py.typed +0 -0
- corebase/realtime/transformers.py +9 -0
- corebase/realtime/types.py +246 -0
- corebase/realtime/utils.py +5 -0
- corebase/realtime/version.py +1 -0
- corebase/storage/__init__.py +56 -0
- corebase/storage/_async/__init__.py +1 -0
- corebase/storage/_async/analytics.py +82 -0
- corebase/storage/_async/bucket.py +142 -0
- corebase/storage/_async/client.py +106 -0
- corebase/storage/_async/file_api.py +630 -0
- corebase/storage/_async/request.py +32 -0
- corebase/storage/_async/vectors.py +213 -0
- corebase/storage/_sync/__init__.py +1 -0
- corebase/storage/_sync/analytics.py +80 -0
- corebase/storage/_sync/bucket.py +142 -0
- corebase/storage/_sync/client.py +106 -0
- corebase/storage/_sync/file_api.py +630 -0
- corebase/storage/_sync/request.py +32 -0
- corebase/storage/_sync/vectors.py +199 -0
- corebase/storage/constants.py +16 -0
- corebase/storage/exceptions.py +84 -0
- corebase/storage/py.typed +0 -0
- corebase/storage/types.py +313 -0
- corebase/storage/utils.py +26 -0
- corebase/storage/version.py +1 -0
- corebase/types.py +8 -0
- corebase/version.py +1 -0
- corebase-1.0.0.dist-info/METADATA +78 -0
- corebase-1.0.0.dist-info/RECORD +106 -0
- corebase-1.0.0.dist-info/WHEEL +4 -0
- corebase-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import builtins
|
|
4
|
+
|
|
5
|
+
from httpx import AsyncClient, Headers
|
|
6
|
+
from yarl import URL
|
|
7
|
+
|
|
8
|
+
from ..exceptions import StorageApiError, VectorBucketException
|
|
9
|
+
from ..types import (
|
|
10
|
+
JSON,
|
|
11
|
+
DistanceMetric,
|
|
12
|
+
GetVectorBucketResponse,
|
|
13
|
+
GetVectorIndexResponse,
|
|
14
|
+
GetVectorsResponse,
|
|
15
|
+
ListVectorBucketsResponse,
|
|
16
|
+
ListVectorIndexesResponse,
|
|
17
|
+
ListVectorsResponse,
|
|
18
|
+
MetadataConfiguration,
|
|
19
|
+
QueryVectorsResponse,
|
|
20
|
+
VectorData,
|
|
21
|
+
VectorFilter,
|
|
22
|
+
VectorObject,
|
|
23
|
+
)
|
|
24
|
+
from .request import AsyncRequestBuilder
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# used to not send non-required values as `null`
|
|
28
|
+
# for they cannot be null
|
|
29
|
+
def remove_none(**kwargs: JSON) -> JSON:
|
|
30
|
+
return {key: val for key, val in kwargs.items() if val is not None}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AsyncVectorBucketScope:
|
|
34
|
+
def __init__(self, request: AsyncRequestBuilder, bucket_name: str) -> None:
|
|
35
|
+
self._request = request
|
|
36
|
+
self._bucket_name = bucket_name
|
|
37
|
+
|
|
38
|
+
def with_metadata(self, **data: JSON) -> JSON:
|
|
39
|
+
return remove_none(vectorBucketName=self._bucket_name, **data)
|
|
40
|
+
|
|
41
|
+
async def create_index(
|
|
42
|
+
self,
|
|
43
|
+
index_name: str,
|
|
44
|
+
dimension: int,
|
|
45
|
+
distance_metric: DistanceMetric,
|
|
46
|
+
data_type: str,
|
|
47
|
+
metadata: MetadataConfiguration | None = None,
|
|
48
|
+
) -> None:
|
|
49
|
+
metadata_configuration = (
|
|
50
|
+
metadata.model_dump(by_alias=True, exclude_none=True) if metadata else None
|
|
51
|
+
)
|
|
52
|
+
body = self.with_metadata(
|
|
53
|
+
indexName=index_name,
|
|
54
|
+
dimension=dimension,
|
|
55
|
+
distanceMetric=distance_metric,
|
|
56
|
+
dataType=data_type,
|
|
57
|
+
metadataConfiguration=metadata_configuration or None,
|
|
58
|
+
)
|
|
59
|
+
await self._request.send(http_method="POST", path=["CreateIndex"], body=body)
|
|
60
|
+
|
|
61
|
+
async def get_index(self, index_name: str) -> GetVectorIndexResponse | None:
|
|
62
|
+
body = self.with_metadata(indexName=index_name)
|
|
63
|
+
try:
|
|
64
|
+
data = await self._request.send(
|
|
65
|
+
http_method="POST", path=["GetIndex"], body=body
|
|
66
|
+
)
|
|
67
|
+
return GetVectorIndexResponse.model_validate_json(data.content)
|
|
68
|
+
except StorageApiError:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
async def list_indexes(
|
|
72
|
+
self,
|
|
73
|
+
next_token: str | None = None,
|
|
74
|
+
max_results: int | None = None,
|
|
75
|
+
prefix: str | None = None,
|
|
76
|
+
) -> ListVectorIndexesResponse:
|
|
77
|
+
body = self.with_metadata(
|
|
78
|
+
nextToken=next_token, maxResults=max_results, prefix=prefix
|
|
79
|
+
)
|
|
80
|
+
data = await self._request.send(
|
|
81
|
+
http_method="POST", path=["ListIndexes"], body=body
|
|
82
|
+
)
|
|
83
|
+
return ListVectorIndexesResponse.model_validate_json(data.content)
|
|
84
|
+
|
|
85
|
+
async def delete_index(self, index_name: str) -> None:
|
|
86
|
+
body = self.with_metadata(indexName=index_name)
|
|
87
|
+
await self._request.send(http_method="POST", path=["DeleteIndex"], body=body)
|
|
88
|
+
|
|
89
|
+
def index(self, index_name: str) -> AsyncVectorIndexScope:
|
|
90
|
+
return AsyncVectorIndexScope(self._request, self._bucket_name, index_name)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class AsyncVectorIndexScope:
|
|
94
|
+
def __init__(
|
|
95
|
+
self, request: AsyncRequestBuilder, bucket_name: str, index_name: str
|
|
96
|
+
) -> None:
|
|
97
|
+
self._request = request
|
|
98
|
+
self._bucket_name = bucket_name
|
|
99
|
+
self._index_name = index_name
|
|
100
|
+
|
|
101
|
+
def with_metadata(self, **data: JSON) -> JSON:
|
|
102
|
+
return remove_none(
|
|
103
|
+
vectorBucketName=self._bucket_name,
|
|
104
|
+
indexName=self._index_name,
|
|
105
|
+
**data,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
async def put(self, vectors: builtins.list[VectorObject]) -> None:
|
|
109
|
+
body = self.with_metadata(
|
|
110
|
+
vectors=[v.model_dump(exclude_none=True) for v in vectors]
|
|
111
|
+
)
|
|
112
|
+
await self._request.send(http_method="POST", path=["PutVectors"], body=body)
|
|
113
|
+
|
|
114
|
+
async def get(
|
|
115
|
+
self, *keys: str, return_data: bool = True, return_metadata: bool = True
|
|
116
|
+
) -> GetVectorsResponse:
|
|
117
|
+
body = self.with_metadata(
|
|
118
|
+
keys=keys, returnData=return_data, returnMetadata=return_metadata
|
|
119
|
+
)
|
|
120
|
+
data = await self._request.send(
|
|
121
|
+
http_method="POST", path=["GetVectors"], body=body
|
|
122
|
+
)
|
|
123
|
+
return GetVectorsResponse.model_validate_json(data.content)
|
|
124
|
+
|
|
125
|
+
async def list(
|
|
126
|
+
self,
|
|
127
|
+
max_results: int | None = None,
|
|
128
|
+
next_token: str | None = None,
|
|
129
|
+
return_data: bool = True,
|
|
130
|
+
return_metadata: bool = True,
|
|
131
|
+
segment_count: int | None = None,
|
|
132
|
+
segment_index: int | None = None,
|
|
133
|
+
) -> ListVectorsResponse:
|
|
134
|
+
body = self.with_metadata(
|
|
135
|
+
maxResults=max_results,
|
|
136
|
+
nextToken=next_token,
|
|
137
|
+
returnData=return_data,
|
|
138
|
+
returnMetadata=return_metadata,
|
|
139
|
+
segmentCount=segment_count,
|
|
140
|
+
segmentIndex=segment_index,
|
|
141
|
+
)
|
|
142
|
+
data = await self._request.send(
|
|
143
|
+
http_method="POST", path=["ListVectors"], body=body
|
|
144
|
+
)
|
|
145
|
+
return ListVectorsResponse.model_validate_json(data.content)
|
|
146
|
+
|
|
147
|
+
async def query(
|
|
148
|
+
self,
|
|
149
|
+
query_vector: VectorData,
|
|
150
|
+
topK: int,
|
|
151
|
+
filter: VectorFilter | None = None,
|
|
152
|
+
return_distance: bool = True,
|
|
153
|
+
return_metadata: bool = True,
|
|
154
|
+
) -> QueryVectorsResponse:
|
|
155
|
+
body = self.with_metadata(
|
|
156
|
+
queryVector=dict(query_vector),
|
|
157
|
+
topK=topK,
|
|
158
|
+
filter=filter,
|
|
159
|
+
returnDistance=return_distance,
|
|
160
|
+
returnMetadata=return_metadata,
|
|
161
|
+
)
|
|
162
|
+
data = await self._request.send(
|
|
163
|
+
http_method="POST", path=["QueryVectors"], body=body
|
|
164
|
+
)
|
|
165
|
+
return QueryVectorsResponse.model_validate_json(data.content)
|
|
166
|
+
|
|
167
|
+
async def delete(self, keys: builtins.list[str]) -> None:
|
|
168
|
+
if len(keys) < 1 or len(keys) > 500:
|
|
169
|
+
raise VectorBucketException("Keys batch size must be between 1 and 500.")
|
|
170
|
+
body = self.with_metadata(keys=keys)
|
|
171
|
+
await self._request.send(http_method="POST", path=["DeleteVectors"], body=body)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class AsyncStorageVectorsClient:
|
|
175
|
+
def __init__(self, url: URL, headers: Headers, session: AsyncClient) -> None:
|
|
176
|
+
self._request = AsyncRequestBuilder(session, base_url=URL(url), headers=headers)
|
|
177
|
+
|
|
178
|
+
def from_(self, bucket_name: str) -> AsyncVectorBucketScope:
|
|
179
|
+
return AsyncVectorBucketScope(self._request, bucket_name)
|
|
180
|
+
|
|
181
|
+
async def create_bucket(self, bucket_name: str) -> None:
|
|
182
|
+
body = {"vectorBucketName": bucket_name}
|
|
183
|
+
await self._request.send(
|
|
184
|
+
http_method="POST", path=["CreateVectorBucket"], body=body
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
async def get_bucket(self, bucket_name: str) -> GetVectorBucketResponse | None:
|
|
188
|
+
body = {"vectorBucketName": bucket_name}
|
|
189
|
+
try:
|
|
190
|
+
data = await self._request.send(
|
|
191
|
+
http_method="POST", path=["GetVectorBucket"], body=body
|
|
192
|
+
)
|
|
193
|
+
return GetVectorBucketResponse.model_validate_json(data.content)
|
|
194
|
+
except StorageApiError:
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
async def list_buckets(
|
|
198
|
+
self,
|
|
199
|
+
prefix: str | None = None,
|
|
200
|
+
max_results: int | None = None,
|
|
201
|
+
next_token: str | None = None,
|
|
202
|
+
) -> ListVectorBucketsResponse:
|
|
203
|
+
body = remove_none(prefix=prefix, maxResults=max_results, nextToken=next_token)
|
|
204
|
+
data = await self._request.send(
|
|
205
|
+
http_method="POST", path=["ListVectorBuckets"], body=body
|
|
206
|
+
)
|
|
207
|
+
return ListVectorBucketsResponse.model_validate_json(data.content)
|
|
208
|
+
|
|
209
|
+
async def delete_bucket(self, bucket_name: str) -> None:
|
|
210
|
+
body = {"vectorBucketName": bucket_name}
|
|
211
|
+
await self._request.send(
|
|
212
|
+
http_method="POST", path=["DeleteVectorBucket"], body=body
|
|
213
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .client import SyncStorageClient as SyncStorageClient
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from httpx import QueryParams
|
|
4
|
+
|
|
5
|
+
from ..types import (
|
|
6
|
+
AnalyticsBucket,
|
|
7
|
+
AnalyticsBucketDeleteResponse,
|
|
8
|
+
AnalyticsBucketsParser,
|
|
9
|
+
SortColumn,
|
|
10
|
+
SortOrder,
|
|
11
|
+
)
|
|
12
|
+
from .request import SyncRequestBuilder
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from pyiceberg.catalog.rest import RestCatalog
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SyncStorageAnalyticsClient:
|
|
19
|
+
def __init__(self, request: SyncRequestBuilder) -> None:
|
|
20
|
+
self._request = request
|
|
21
|
+
|
|
22
|
+
def create(self, bucket_name: str) -> AnalyticsBucket:
|
|
23
|
+
body = {"name": bucket_name}
|
|
24
|
+
data = self._request.send(http_method="POST", path=["bucket"], body=body)
|
|
25
|
+
return AnalyticsBucket.model_validate_json(data.content)
|
|
26
|
+
|
|
27
|
+
def list(
|
|
28
|
+
self,
|
|
29
|
+
limit: int | None = None,
|
|
30
|
+
offset: int | None = None,
|
|
31
|
+
sort_column: SortColumn | None = None,
|
|
32
|
+
sort_order: SortOrder | None = None,
|
|
33
|
+
search: str | None = None,
|
|
34
|
+
) -> list[AnalyticsBucket]:
|
|
35
|
+
params = dict(
|
|
36
|
+
limit=limit,
|
|
37
|
+
offset=offset,
|
|
38
|
+
sortColumn=sort_column,
|
|
39
|
+
sortOrder=sort_order,
|
|
40
|
+
search=search,
|
|
41
|
+
)
|
|
42
|
+
filtered_params = QueryParams(
|
|
43
|
+
**{k: v for k, v in params.items() if v is not None}
|
|
44
|
+
)
|
|
45
|
+
data = self._request.send(
|
|
46
|
+
http_method="GET", path=["bucket"], query_params=filtered_params
|
|
47
|
+
)
|
|
48
|
+
return AnalyticsBucketsParser.validate_json(data.content)
|
|
49
|
+
|
|
50
|
+
def delete(self, bucket_name: str) -> AnalyticsBucketDeleteResponse:
|
|
51
|
+
data = self._request.send(http_method="DELETE", path=["bucket", bucket_name])
|
|
52
|
+
return AnalyticsBucketDeleteResponse.model_validate_json(data.content)
|
|
53
|
+
|
|
54
|
+
def catalog(
|
|
55
|
+
self, catalog_name: str, access_key_id: str, secret_access_key: str
|
|
56
|
+
) -> "RestCatalog":
|
|
57
|
+
try:
|
|
58
|
+
from pyiceberg.catalog.rest import RestCatalog
|
|
59
|
+
except ImportError as err:
|
|
60
|
+
raise Exception(
|
|
61
|
+
"pyiceberg is required for storage analytics catalog support"
|
|
62
|
+
) from err
|
|
63
|
+
|
|
64
|
+
catalog_uri = self._request._base_url
|
|
65
|
+
s3_endpoint = self._request._base_url.parent.joinpath("s3")
|
|
66
|
+
service_key = self._request.headers.get("apiKey")
|
|
67
|
+
assert service_key, "apiKey must be passed in the headers."
|
|
68
|
+
return RestCatalog(
|
|
69
|
+
catalog_name,
|
|
70
|
+
warehouse=catalog_name,
|
|
71
|
+
uri=str(catalog_uri),
|
|
72
|
+
token=service_key,
|
|
73
|
+
**{
|
|
74
|
+
"py-io-impl": "pyiceberg.io.pyarrow.PyArrowFileIO",
|
|
75
|
+
"s3.endpoint": str(s3_endpoint),
|
|
76
|
+
"s3.access-key-id": access_key_id,
|
|
77
|
+
"s3.secret-access-key": secret_access_key,
|
|
78
|
+
"s3.force-virtual-addressing": "False",
|
|
79
|
+
},
|
|
80
|
+
)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from httpx import Client, Headers, HTTPStatusError, Response
|
|
7
|
+
from yarl import URL
|
|
8
|
+
|
|
9
|
+
from ..exceptions import StorageApiError
|
|
10
|
+
from ..types import CreateOrUpdateBucketOptions, RequestMethod
|
|
11
|
+
from .file_api import SyncBucket
|
|
12
|
+
|
|
13
|
+
__all__ = ["SyncStorageBucketAPI"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SyncStorageBucketAPI:
|
|
17
|
+
"""This class abstracts access to the endpoint to the Get, List, Empty, and Delete operations on a bucket"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, session: Client, url: str, headers: Headers) -> None:
|
|
20
|
+
if url and url[-1] != "/":
|
|
21
|
+
warnings.warn(
|
|
22
|
+
"Storage endpoint URL should have a trailing slash. "
|
|
23
|
+
"The URL has been automatically corrected.",
|
|
24
|
+
UserWarning,
|
|
25
|
+
stacklevel=2,
|
|
26
|
+
)
|
|
27
|
+
url += "/"
|
|
28
|
+
self._base_url = URL(url)
|
|
29
|
+
self._client = session
|
|
30
|
+
self._headers = headers
|
|
31
|
+
|
|
32
|
+
def _request(
|
|
33
|
+
self,
|
|
34
|
+
method: RequestMethod,
|
|
35
|
+
path: list[str],
|
|
36
|
+
json: dict[Any, Any] | None = None,
|
|
37
|
+
) -> Response:
|
|
38
|
+
try:
|
|
39
|
+
url_path = self._base_url.joinpath(*path)
|
|
40
|
+
response = self._client.request(
|
|
41
|
+
method, str(url_path), json=json, headers=self._headers
|
|
42
|
+
)
|
|
43
|
+
response.raise_for_status()
|
|
44
|
+
except HTTPStatusError as exc:
|
|
45
|
+
try:
|
|
46
|
+
resp = exc.response.json()
|
|
47
|
+
raise StorageApiError(
|
|
48
|
+
resp["message"], resp["error"], resp["statusCode"]
|
|
49
|
+
) from exc
|
|
50
|
+
except (KeyError, TypeError, ValueError) as err:
|
|
51
|
+
message = f"Unable to parse error message: {exc.response.text}"
|
|
52
|
+
raise StorageApiError(
|
|
53
|
+
message, "InternalError", exc.response.status_code
|
|
54
|
+
) from err
|
|
55
|
+
|
|
56
|
+
return response
|
|
57
|
+
|
|
58
|
+
def list_buckets(self) -> list[SyncBucket]:
|
|
59
|
+
"""Retrieves the details of all storage buckets within an existing product."""
|
|
60
|
+
# if the request doesn't error, it is assured to return a list
|
|
61
|
+
res = self._request("GET", ["bucket"])
|
|
62
|
+
return [SyncBucket(**bucket) for bucket in res.json()]
|
|
63
|
+
|
|
64
|
+
def get_bucket(self, id: str) -> SyncBucket:
|
|
65
|
+
"""Retrieves the details of an existing storage bucket.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
id
|
|
70
|
+
The unique identifier of the bucket you would like to retrieve.
|
|
71
|
+
"""
|
|
72
|
+
res = self._request("GET", ["bucket", id])
|
|
73
|
+
json = res.json()
|
|
74
|
+
return SyncBucket(**json)
|
|
75
|
+
|
|
76
|
+
def create_bucket(
|
|
77
|
+
self,
|
|
78
|
+
id: str,
|
|
79
|
+
name: str | None = None,
|
|
80
|
+
options: CreateOrUpdateBucketOptions | None = None,
|
|
81
|
+
) -> dict[str, str]:
|
|
82
|
+
"""Creates a new storage bucket.
|
|
83
|
+
|
|
84
|
+
Parameters
|
|
85
|
+
----------
|
|
86
|
+
id
|
|
87
|
+
A unique identifier for the bucket you are creating.
|
|
88
|
+
name
|
|
89
|
+
A name for the bucket you are creating. If not passed, the id is used as the name as well.
|
|
90
|
+
options
|
|
91
|
+
Extra options to send while creating the bucket. Valid options are `public`, `file_size_limit` and
|
|
92
|
+
`allowed_mime_types`.
|
|
93
|
+
"""
|
|
94
|
+
json: dict[str, Any] = {"id": id, "name": name or id}
|
|
95
|
+
if options:
|
|
96
|
+
json.update(**options)
|
|
97
|
+
res = self._request(
|
|
98
|
+
"POST",
|
|
99
|
+
["bucket"],
|
|
100
|
+
json=json,
|
|
101
|
+
)
|
|
102
|
+
return res.json()
|
|
103
|
+
|
|
104
|
+
def update_bucket(
|
|
105
|
+
self, id: str, options: CreateOrUpdateBucketOptions
|
|
106
|
+
) -> dict[str, str]:
|
|
107
|
+
"""Update a storage bucket.
|
|
108
|
+
|
|
109
|
+
Parameters
|
|
110
|
+
----------
|
|
111
|
+
id
|
|
112
|
+
The unique identifier of the bucket you would like to update.
|
|
113
|
+
options
|
|
114
|
+
The properties you want to update. Valid options are `public`, `file_size_limit` and
|
|
115
|
+
`allowed_mime_types`.
|
|
116
|
+
"""
|
|
117
|
+
json = {"id": id, "name": id, **options}
|
|
118
|
+
res = self._request("PUT", ["bucket", id], json=json)
|
|
119
|
+
return res.json()
|
|
120
|
+
|
|
121
|
+
def empty_bucket(self, id: str) -> dict[str, str]:
|
|
122
|
+
"""Removes all objects inside a single bucket.
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
id
|
|
127
|
+
The unique identifier of the bucket you would like to empty.
|
|
128
|
+
"""
|
|
129
|
+
res = self._request("POST", ["bucket", id, "empty"], json={})
|
|
130
|
+
return res.json()
|
|
131
|
+
|
|
132
|
+
def delete_bucket(self, id: str) -> dict[str, str]:
|
|
133
|
+
"""Deletes an existing bucket. Note that you cannot delete buckets with existing objects inside. You must first
|
|
134
|
+
`empty()` the bucket.
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
id
|
|
139
|
+
The unique identifier of the bucket you would like to delete.
|
|
140
|
+
"""
|
|
141
|
+
res = self._request("DELETE", ["bucket", id], json={})
|
|
142
|
+
return res.json()
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import platform
|
|
4
|
+
from warnings import warn
|
|
5
|
+
|
|
6
|
+
from httpx import Client, Headers
|
|
7
|
+
|
|
8
|
+
from corebase.storage.constants import DEFAULT_TIMEOUT
|
|
9
|
+
|
|
10
|
+
from ..version import __version__
|
|
11
|
+
from .analytics import SyncStorageAnalyticsClient
|
|
12
|
+
from .bucket import SyncStorageBucketAPI
|
|
13
|
+
from .file_api import SyncBucketProxy
|
|
14
|
+
from .request import SyncRequestBuilder
|
|
15
|
+
from .vectors import SyncStorageVectorsClient
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"SyncStorageClient",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SyncStorageClient(SyncStorageBucketAPI):
|
|
23
|
+
"""Manage storage buckets and files."""
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
url: str,
|
|
28
|
+
headers: dict[str, str],
|
|
29
|
+
timeout: int | None = None,
|
|
30
|
+
verify: bool | None = None,
|
|
31
|
+
proxy: str | None = None,
|
|
32
|
+
http_client: Client | None = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
headers = {
|
|
35
|
+
"X-Client-Info": (
|
|
36
|
+
f"corebase-py/storage3 v{__version__}"
|
|
37
|
+
f"; platform={platform.system()}"
|
|
38
|
+
f"; platform-version={platform.release()}"
|
|
39
|
+
f"; runtime=python"
|
|
40
|
+
f"; runtime-version={platform.python_version()}"
|
|
41
|
+
),
|
|
42
|
+
**headers,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if timeout is not None:
|
|
46
|
+
warn(
|
|
47
|
+
"The 'timeout' parameter is deprecated. Please configure it in the http client instead.",
|
|
48
|
+
DeprecationWarning,
|
|
49
|
+
stacklevel=2,
|
|
50
|
+
)
|
|
51
|
+
if verify is not None:
|
|
52
|
+
warn(
|
|
53
|
+
"The 'verify' parameter is deprecated. Please configure it in the http client instead.",
|
|
54
|
+
DeprecationWarning,
|
|
55
|
+
stacklevel=2,
|
|
56
|
+
)
|
|
57
|
+
if proxy is not None:
|
|
58
|
+
warn(
|
|
59
|
+
"The 'proxy' parameter is deprecated. Please configure it in the http client instead.",
|
|
60
|
+
DeprecationWarning,
|
|
61
|
+
stacklevel=2,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
self.verify = bool(verify) if verify is not None else True
|
|
65
|
+
self.timeout = int(abs(timeout)) if timeout is not None else DEFAULT_TIMEOUT
|
|
66
|
+
|
|
67
|
+
self.session = http_client or Client(
|
|
68
|
+
headers=headers,
|
|
69
|
+
timeout=self.timeout,
|
|
70
|
+
proxy=proxy,
|
|
71
|
+
verify=self.verify,
|
|
72
|
+
follow_redirects=True,
|
|
73
|
+
http2=True,
|
|
74
|
+
)
|
|
75
|
+
super().__init__(self.session, url, Headers(headers))
|
|
76
|
+
|
|
77
|
+
def __enter__(self) -> SyncStorageClient:
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def __exit__(self, exc_type, exc, tb) -> None:
|
|
81
|
+
self.session.close()
|
|
82
|
+
|
|
83
|
+
def from_(self, id: str) -> SyncBucketProxy:
|
|
84
|
+
"""Run a storage file operation.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
id
|
|
89
|
+
The unique identifier of the bucket
|
|
90
|
+
"""
|
|
91
|
+
return SyncBucketProxy(id, self._base_url, self._headers, self._client)
|
|
92
|
+
|
|
93
|
+
def vectors(self) -> SyncStorageVectorsClient:
|
|
94
|
+
return SyncStorageVectorsClient(
|
|
95
|
+
url=self._base_url.joinpath("vector"),
|
|
96
|
+
headers=self._headers,
|
|
97
|
+
session=self.session,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def analytics(self) -> SyncStorageAnalyticsClient:
|
|
101
|
+
request = SyncRequestBuilder(
|
|
102
|
+
session=self.session,
|
|
103
|
+
headers=self._headers,
|
|
104
|
+
base_url=self._base_url.joinpath("iceberg"),
|
|
105
|
+
)
|
|
106
|
+
return SyncStorageAnalyticsClient(request=request)
|