Skip to content

Commit 7607dc6

Browse files
authored
New upload URL (#188)
* update spec * linting * new upload channel * new release version * update deps
1 parent f9af0df commit 7607dc6

File tree

7 files changed

+104
-71
lines changed

7 files changed

+104
-71
lines changed

examples/datasets/access_logs.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,4 +1029,4 @@ ip,timestamp,method,url_path,version,status_code,bytes,referrer,user_agent,respo
10291029
65.209.139.92,27/Dec/2037:12:00:00 +0530,PUT,usr/admin/developer,HTTP/1.0,403,5142,http://www.parker-miller.org/tag/list/list/privacy/,Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML; like Gecko) Chrome/89.0.4380.0 Safari/537.36 Edg/89.0.759.0,2603
10301030
14.9.21.127,27/Dec/2037:12:00:00 +0530,PUT,usr/login,HTTP/1.0,303,4984,-,Mozilla/5.0 (Linux; Android 10; ONEPLUS A6000) AppleWebKit/537.36 (KHTML; like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36,1137
10311031
55.170.37.108,27/Dec/2037:12:00:00 +0530,PUT,usr/register,HTTP/1.0,303,5028,http://www.parker-miller.org/tag/list/list/privacy/,Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0,2391
1032-
252.222.142.134,27/Dec/2037:12:00:00 +0530,DELETE,usr/admin/developer,HTTP/1.0,404,5026,-,Mozilla/5.0 (Linux; Android 10; ONEPLUS A6000) AppleWebKit/537.36 (KHTML; like Gecko) Chrome/77.0.3865.116 Mobile Safari/537.36 EdgA/45.12.4.5121,2551
1032+
252.222.142.134,27/Dec/2037:12:00:00 +0530,DELETE,usr/admin/developer,HTTP/1.0,404,5026,-,Mozilla/5.0 (Linux; Android 10; ONEPLUS A6000) AppleWebKit/537.36 (KHTML; like Gecko) Chrome/77.0.3865.116 Mobile Safari/537.36 EdgA/45.12.4.5121,2551

poetry.lock

Lines changed: 59 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "xata"
3-
version = "1.2.2"
3+
version = "1.2.3"
44
description = "Python SDK for Xata.io"
55
authors = ["Xata <support@xata.io>"]
66
license = "Apache-2.0"

tests/unit-tests/api_request_domains_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ def test_workspace_domain(self):
3737

3838
expected = "https://%s.%s.%s" % (ws_id, DEFAULT_REGION, domain)
3939
assert expected == client.table().get_base_url()
40+
41+
def test_upload_base_url(self):
42+
client = XataClient(api_key="123", db_url="https://12345.region-42.staging-xata.dev/db/testopia-042")
43+
assert "https://12345.region-42.upload.staging-xata.dev" == client.databases().get_upload_base_url()

xata/api/files.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
# ------------------------------------------------------- #
2121
# Files
22-
# Files
23-
# Specification: core:v1.0
22+
# CRUD API for operating on binary content in file and file[] columns.
23+
# Specification: workspace:v1.0
2424
# ------------------------------------------------------- #
2525

2626
from requests import request
@@ -46,6 +46,7 @@ def get_item(
4646
"""
4747
Retrieves file content from an array by file ID
4848
49+
Reference: https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id/column/column_name/file/file_id#download-content-from-a-file-item-in-a-file-array-column
4950
Path: /db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file/{file_id}
5051
Method: GET
5152
Response status codes:
@@ -54,6 +55,7 @@ def get_item(
5455
- 401: Authentication Error
5556
- 404: Example response
5657
- 5XX: Unexpected Error
58+
- default: Unexpected Error
5759
Response: */*
5860
5961
:param table_name: str The Table name
@@ -63,7 +65,7 @@ def get_item(
6365
:param db_name: str = None The name of the database to query. Default: database name from the client.
6466
:param branch_name: str = None The name of the branch to query. Default: branch name from the client.
6567
66-
:return ApiResponse
68+
:returns ApiResponse
6769
"""
6870
db_branch_name = self.client.get_db_branch_name(db_name, branch_name)
6971
url_path = f"/db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file/{file_id}"
@@ -83,6 +85,7 @@ def put_item(
8385
"""
8486
Uploads the file content to an array given the file ID
8587
88+
Reference: https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id/column/column_name/file/file_id#upload-or-update-the-content-of-a-file-item-in-a-file-array-column
8689
Path: /db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file/{file_id}
8790
Method: PUT
8891
Response status codes:
@@ -93,6 +96,7 @@ def put_item(
9396
- 404: Example response
9497
- 422: Example response
9598
- 5XX: Unexpected Error
99+
- default: Unexpected Error
96100
97101
:param table_name: str The Table name
98102
:param record_id: str The Record name
@@ -103,12 +107,13 @@ def put_item(
103107
:param db_name: str = None The name of the database to query. Default: database name from the client.
104108
:param branch_name: str = None The name of the branch to query. Default: branch name from the client.
105109
106-
:return ApiResponse
110+
:returns ApiResponse
107111
"""
112+
108113
db_branch_name = self.client.get_db_branch_name(db_name, branch_name)
109114
url_path = f"/db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file/{file_id}"
110115
headers = {"content-type": content_type}
111-
return self.request("PUT", url_path, headers, data=data)
116+
return self.request("PUT", url_path, headers, data=data, override_base_url=self.get_upload_base_url())
112117

113118
def delete_item(
114119
self,
@@ -122,6 +127,7 @@ def delete_item(
122127
"""
123128
Deletes an item from an file array column given the file ID
124129
130+
Reference: https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id/column/column_name/file/file_id#delete-an-item-from-a-file-array
125131
Path: /db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file/{file_id}
126132
Method: DELETE
127133
Response status codes:
@@ -130,6 +136,7 @@ def delete_item(
130136
- 401: Authentication Error
131137
- 404: Example response
132138
- 5XX: Unexpected Error
139+
- default: Unexpected Error
133140
134141
:param table_name: str The Table name
135142
:param record_id: str The Record name
@@ -138,7 +145,7 @@ def delete_item(
138145
:param db_name: str = None The name of the database to query. Default: database name from the client.
139146
:param branch_name: str = None The name of the branch to query. Default: branch name from the client.
140147
141-
:return ApiResponse
148+
:returns ApiResponse
142149
"""
143150
db_branch_name = self.client.get_db_branch_name(db_name, branch_name)
144151
url_path = f"/db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file/{file_id}"
@@ -150,6 +157,7 @@ def get(
150157
"""
151158
Retrieves the file content from a file column
152159
160+
Reference: https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id/column/column_name/file#download-content-from-a-file-column
153161
Path: /db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file
154162
Method: GET
155163
Response status codes:
@@ -159,6 +167,7 @@ def get(
159167
- 401: Authentication Error
160168
- 404: Example response
161169
- 5XX: Unexpected Error
170+
- default: Unexpected Error
162171
Response: */*
163172
164173
:param table_name: str The Table name
@@ -167,7 +176,7 @@ def get(
167176
:param db_name: str = None The name of the database to query. Default: database name from the client.
168177
:param branch_name: str = None The name of the branch to query. Default: branch name from the client.
169178
170-
:return ApiResponse
179+
:returns ApiResponse
171180
"""
172181
db_branch_name = self.client.get_db_branch_name(db_name, branch_name)
173182
url_path = f"/db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file"
@@ -186,6 +195,7 @@ def put(
186195
"""
187196
Uploads the file content to the given file column
188197
198+
Reference: https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id/column/column_name/file#upload-content-to-a-file-column
189199
Path: /db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file
190200
Method: PUT
191201
Response status codes:
@@ -196,27 +206,30 @@ def put(
196206
- 404: Example response
197207
- 422: Example response
198208
- 5XX: Unexpected Error
209+
- default: Unexpected Error
199210
200211
:param table_name: str The Table name
201212
:param record_id: str The Record name
202213
:param column_name: str The Column name
203-
:param data: bytes
214+
:param data: bytes content
215+
:param content_type: str Default: "application/octet-stream"
204216
:param db_name: str = None The name of the database to query. Default: database name from the client.
205217
:param branch_name: str = None The name of the branch to query. Default: branch name from the client.
206218
207-
:return ApiResponse
219+
:returns ApiResponse
208220
"""
209221
db_branch_name = self.client.get_db_branch_name(db_name, branch_name)
210222
url_path = f"/db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file"
211223
headers = {"content-type": content_type}
212-
return self.request("PUT", url_path, headers, data=data)
224+
return self.request("PUT", url_path, headers, data=data, override_base_url=self.get_upload_base_url())
213225

214226
def delete(
215227
self, table_name: str, record_id: str, column_name: str, db_name: str = None, branch_name: str = None
216228
) -> ApiResponse:
217229
"""
218230
Deletes a file referred in a file column
219231
232+
Reference: https://xata.io/docs/api-reference/db/db_branch_name/tables/table_name/data/record_id/column/column_name/file#remove-the-content-from-a-file-column
220233
Path: /db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file
221234
Method: DELETE
222235
Response status codes:
@@ -225,14 +238,15 @@ def delete(
225238
- 401: Authentication Error
226239
- 404: Example response
227240
- 5XX: Unexpected Error
241+
- default: Unexpected Error
228242
229243
:param table_name: str The Table name
230244
:param record_id: str The Record name
231245
:param column_name: str The Column name
232246
:param db_name: str = None The name of the database to query. Default: database name from the client.
233247
:param branch_name: str = None The name of the branch to query. Default: branch name from the client.
234248
235-
:return ApiResponse
249+
:returns ApiResponse
236250
"""
237251
db_branch_name = self.client.get_db_branch_name(db_name, branch_name)
238252
url_path = f"/db/{db_branch_name}/tables/{table_name}/data/{record_id}/column/{column_name}/file"

xata/api_request.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ def get_base_url(self) -> str:
4545
cfg = self.client.get_config()
4646
return "https://%s.%s.%s" % (cfg["workspaceId"], cfg["region"], cfg["domain_workspace"])
4747

48+
def get_upload_base_url(self) -> str:
49+
"""
50+
Upload of files has dedidcated URL that is not represented in the OAS
51+
52+
:returns str
53+
"""
54+
cfg = self.client.get_config()
55+
return "https://%s.%s.upload.%s" % (cfg["workspaceId"], cfg["region"], cfg["domain_workspace"])
56+
4857
def request(
4958
self,
5059
http_method: str,
@@ -53,6 +62,7 @@ def request(
5362
payload: dict = None,
5463
data: bytes = None,
5564
is_streaming: bool = False,
65+
override_base_url=None,
5666
) -> ApiResponse:
5767
"""
5868
:param http_method: str
@@ -61,6 +71,7 @@ def request(
6171
:param payload: dict = None
6272
:param data: bytes = None
6373
:param is_streaming: bool = False
74+
:param override_base_url = None Set alternative base URL
6475
6576
:returns ApiResponse
6677
@@ -69,7 +80,8 @@ def request(
6980
:raises ServerError
7081
"""
7182
headers = {**headers, **self.client.get_headers()}
72-
url = "%s/%s" % (self.get_base_url(), url_path.lstrip("/"))
83+
base_url = self.get_base_url() if override_base_url is None else override_base_url
84+
url = "%s/%s" % (base_url, url_path.lstrip("/"))
7385

7486
# In order not exhaust the connection pool with open connections from unread streams
7587
# we opt for Session usage on all non-stream requests

xata/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
# TODO this is a manual task, to keep in sync with pyproject.toml
4141
# could/should be automated to keep in sync
42-
__version__ = "1.2.2"
42+
__version__ = "1.2.3"
4343

4444
PERSONAL_API_KEY_LOCATION = "~/.config/xata/key"
4545
DEFAULT_DATA_PLANE_DOMAIN = "xata.sh"

0 commit comments

Comments
 (0)