alfred-python 0.6.0__py3-none-any.whl → 0.6.1__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.
- alfred/base/__init__.py +3 -0
- alfred/http/__init__.py +2 -0
- alfred/http/http_client.py +6 -3
- alfred/rest/files/__init__.py +1 -0
- alfred/rest/files/v1.py +20 -13
- alfred/rest/jobs/__init__.py +1 -0
- {alfred_python-0.6.0.dist-info → alfred_python-0.6.1.dist-info}/METADATA +66 -34
- {alfred_python-0.6.0.dist-info → alfred_python-0.6.1.dist-info}/RECORD +11 -11
- {alfred_python-0.6.0.dist-info → alfred_python-0.6.1.dist-info}/LICENSE +0 -0
- {alfred_python-0.6.0.dist-info → alfred_python-0.6.1.dist-info}/WHEEL +0 -0
- {alfred_python-0.6.0.dist-info → alfred_python-0.6.1.dist-info}/top_level.txt +0 -0
alfred/base/__init__.py
CHANGED
alfred/http/__init__.py
CHANGED
alfred/http/http_client.py
CHANGED
|
@@ -255,7 +255,7 @@ class HttpClient:
|
|
|
255
255
|
hmac_key = f"amx {secret_key}:{signature_base64}:{nonce}:{request_timestamp}"
|
|
256
256
|
prepped_request.headers.update({"Authorization": hmac_key})
|
|
257
257
|
|
|
258
|
-
def __get_headers(self, headers: Optional[Dict[str, str]]) -> Dict[str, str]:
|
|
258
|
+
def __get_headers(self, headers: Optional[Dict[str, str]], has_files: bool = False) -> Dict[str, str]:
|
|
259
259
|
"""
|
|
260
260
|
Get the request headers.
|
|
261
261
|
|
|
@@ -265,10 +265,13 @@ class HttpClient:
|
|
|
265
265
|
headers = headers or {}
|
|
266
266
|
default_headers = {
|
|
267
267
|
"Accept-Charset": "utf-8",
|
|
268
|
-
"Content-Type": "application/json",
|
|
269
268
|
"Accept": RESPONSE_TYPE_HEADER_MAPPING.get(self.response_type),
|
|
270
269
|
}
|
|
271
270
|
|
|
271
|
+
# Set default Content-Type only if it's not a file upload
|
|
272
|
+
if "Content-Type" not in headers and not has_files:
|
|
273
|
+
default_headers["Content-Type"] = "application/json"
|
|
274
|
+
|
|
272
275
|
return {**default_headers, **headers}
|
|
273
276
|
|
|
274
277
|
@staticmethod
|
|
@@ -326,7 +329,7 @@ class HttpClient:
|
|
|
326
329
|
elif timeout <= 0:
|
|
327
330
|
raise ValueError(timeout)
|
|
328
331
|
|
|
329
|
-
headers = self.__get_headers(headers)
|
|
332
|
+
headers = self.__get_headers(headers, has_files=bool(files))
|
|
330
333
|
url = self.base_url + uri
|
|
331
334
|
|
|
332
335
|
kwargs = {
|
alfred/rest/files/__init__.py
CHANGED
alfred/rest/files/v1.py
CHANGED
|
@@ -10,7 +10,7 @@ from alfred.http.http_client import HttpClient
|
|
|
10
10
|
from alfred.base.exceptions import AlfredMissingArgument
|
|
11
11
|
from .base import FilesBase
|
|
12
12
|
from .typed import FileDetailsResponse
|
|
13
|
-
|
|
13
|
+
import magic
|
|
14
14
|
|
|
15
15
|
class Files(FilesBase):
|
|
16
16
|
def __init__(self, http_client: HttpClient):
|
|
@@ -41,6 +41,12 @@ class Files(FilesBase):
|
|
|
41
41
|
def upload_file(self, payload: UploadLocalFilePayload) -> UploadResponse:
|
|
42
42
|
file = payload.get("file")
|
|
43
43
|
filename = payload.get("filename")
|
|
44
|
+
session_id = payload.get("session_id")
|
|
45
|
+
metadata = payload.get("metadata", {})
|
|
46
|
+
|
|
47
|
+
# Detect MIME type
|
|
48
|
+
content_type = magic.from_buffer(file.read(1024), mime=True)
|
|
49
|
+
file.seek(0) # reset pointer
|
|
44
50
|
|
|
45
51
|
if isinstance(file, BufferedReader):
|
|
46
52
|
filename = os.path.basename(file.name)
|
|
@@ -48,21 +54,22 @@ class Files(FilesBase):
|
|
|
48
54
|
if not filename:
|
|
49
55
|
raise AlfredMissingArgument("filename must be provided.")
|
|
50
56
|
|
|
51
|
-
files =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
"metadata",
|
|
56
|
-
(None, json.dumps(payload.get("metadata")), "application/json"),
|
|
57
|
-
),
|
|
58
|
-
]
|
|
57
|
+
files = {
|
|
58
|
+
"file": (filename, file, content_type)
|
|
59
|
+
}
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
data = {
|
|
62
|
+
"session_id": session_id,
|
|
63
|
+
"metadata": json.dumps(metadata)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
parsed_response, _ = self.http_client.post(
|
|
61
67
|
"/api/file/uploadfile",
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
data=data,
|
|
69
|
+
files=files
|
|
64
70
|
)
|
|
65
|
-
|
|
71
|
+
|
|
72
|
+
return parsed_response
|
|
66
73
|
|
|
67
74
|
def __extract_filename(self, content_disposition: Text):
|
|
68
75
|
"""
|
alfred/rest/jobs/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: alfred-python
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.1
|
|
4
4
|
Summary: Python library designed to simplify and streamline interactions with the Alfred API
|
|
5
5
|
Author-email: Tagshelf LLC <support@tagshelf.com>
|
|
6
6
|
License: Copyright (c) 2018 The Python Packaging Authority
|
|
@@ -34,6 +34,8 @@ Requires-Dist: pydantic-settings >=2.0
|
|
|
34
34
|
Requires-Dist: requests >=2.30
|
|
35
35
|
Requires-Dist: python-socketio >=5.11
|
|
36
36
|
Requires-Dist: websocket-client >=1.8
|
|
37
|
+
Requires-Dist: python-magic ==0.4.27 ; platform_system != "Windows"
|
|
38
|
+
Requires-Dist: python-magic-bin ==0.4.14 ; platform_system == "Windows"
|
|
37
39
|
|
|
38
40
|
# Overview
|
|
39
41
|
|
|
@@ -50,13 +52,16 @@ Check out this simple example to get up and running:
|
|
|
50
52
|
```python
|
|
51
53
|
from alfred.rest import AlfredClient
|
|
52
54
|
from alfred.base import Configuration
|
|
55
|
+
from alfred.http import AuthConfiguration
|
|
53
56
|
|
|
54
57
|
config = Configuration.default()
|
|
55
|
-
auth_config =
|
|
58
|
+
auth_config = AuthConfiguration(
|
|
59
|
+
api_key = "<api-key>"
|
|
60
|
+
)
|
|
56
61
|
|
|
57
62
|
client = AlfredClient(config, auth_config)
|
|
58
63
|
|
|
59
|
-
values = client.data_points.get_values("
|
|
64
|
+
values = client.data_points.get_values("<file-id>")
|
|
60
65
|
print(values)
|
|
61
66
|
```
|
|
62
67
|
|
|
@@ -64,19 +69,18 @@ print(values)
|
|
|
64
69
|
|
|
65
70
|
A Session is a mechanism designed for asynchronous file uploads. It serves as a container or grouping for files that are uploaded at different times or from various sources, but are all part of a single Job. To see more information visit our [official documentation](https://docs.tagshelf.dev/enpoints/deferred-session).
|
|
66
71
|
|
|
67
|
-
####
|
|
72
|
+
#### Create session
|
|
68
73
|
|
|
69
74
|
```python
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
print(
|
|
75
|
+
result = client.sessions.create()
|
|
76
|
+
session_id = result.get("session_id")
|
|
77
|
+
print(session_id)
|
|
73
78
|
```
|
|
74
79
|
|
|
75
|
-
####
|
|
80
|
+
#### Get session by ID
|
|
76
81
|
|
|
77
82
|
```python
|
|
78
|
-
|
|
79
|
-
result = client.sessions.create()
|
|
83
|
+
result = client.sessions.get("<session-id>")
|
|
80
84
|
print(result)
|
|
81
85
|
```
|
|
82
86
|
|
|
@@ -87,15 +91,13 @@ A Job represents a single unit of work that group one or more Files within Alfre
|
|
|
87
91
|
#### Get job by ID
|
|
88
92
|
|
|
89
93
|
```python
|
|
90
|
-
|
|
91
|
-
result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
94
|
+
result = client.jobs.get("<job-id>")
|
|
92
95
|
print(result)
|
|
93
96
|
```
|
|
94
97
|
|
|
95
98
|
#### Get paginated jobs
|
|
96
99
|
|
|
97
100
|
```python
|
|
98
|
-
# Get paginated jobs
|
|
99
101
|
response = client.jobs.get_all(page_size=None, current_page=None)
|
|
100
102
|
print(response.is_empty)
|
|
101
103
|
print(response.result)
|
|
@@ -105,7 +107,9 @@ print(response.total)
|
|
|
105
107
|
#### Create job
|
|
106
108
|
|
|
107
109
|
```python
|
|
108
|
-
|
|
110
|
+
from alfred.rest.jobs import CreateJobDict
|
|
111
|
+
|
|
112
|
+
job: CreateJobDict = {
|
|
109
113
|
"session_id": "session-id",
|
|
110
114
|
"propagate_metadata": True,
|
|
111
115
|
"merge": True,
|
|
@@ -121,7 +125,6 @@ job = {
|
|
|
121
125
|
"file_names": ["file-name-1", "file-name-2"],
|
|
122
126
|
}
|
|
123
127
|
|
|
124
|
-
# Create a job
|
|
125
128
|
result = client.jobs.create(job)
|
|
126
129
|
print(result)
|
|
127
130
|
```
|
|
@@ -149,41 +152,71 @@ File is an individual document or data unit undergoing specialized operations ta
|
|
|
149
152
|
#### Get file by ID
|
|
150
153
|
|
|
151
154
|
```python
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
from alfred.rest.files import FileDetailsResponse
|
|
156
|
+
|
|
157
|
+
result: FileDetailsResponse = client.files.get("<file-id>")
|
|
154
158
|
print(result)
|
|
155
159
|
```
|
|
156
160
|
|
|
157
161
|
#### Download file by ID
|
|
158
162
|
|
|
159
163
|
```python
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
from alfred.rest.files import DownloadResponse
|
|
165
|
+
|
|
166
|
+
result: DownloadResponse = client.files.download("<file-id>")
|
|
162
167
|
|
|
163
168
|
with open(result.get("original_name"), "wb") as f:
|
|
164
169
|
f.write(result.get("file").getvalue())
|
|
165
170
|
```
|
|
166
171
|
|
|
167
|
-
#### Upload remote file
|
|
172
|
+
#### Upload a single remote file and create a Job
|
|
168
173
|
|
|
169
174
|
```python
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
"
|
|
174
|
-
|
|
175
|
+
from alfred.rest.files import UploadRemoteFilePayload, UploadResponse
|
|
176
|
+
|
|
177
|
+
payload: UploadRemoteFilePayload = {
|
|
178
|
+
"url": "<file-url>",
|
|
179
|
+
"filename" "file-name", # optional
|
|
180
|
+
"metadata": {
|
|
181
|
+
"key": "value",
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
result: UploadResponse = client.files.upload(payload)
|
|
186
|
+
print(result)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### Upload multiple remote files and create a Job
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from alfred.rest.files import UploadRemoteFilePayload, UploadResponse
|
|
193
|
+
|
|
194
|
+
payload: UploadRemoteFilePayload = {
|
|
195
|
+
"urls": ["<file-url>", "<file-url-2>"],
|
|
196
|
+
"filenames": ["file-name", "file-name-2"], # optional
|
|
197
|
+
"metadata": {
|
|
198
|
+
"key": "value",
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
result: UploadResponse = client.files.upload(payload)
|
|
175
203
|
print(result)
|
|
176
204
|
```
|
|
177
205
|
|
|
178
|
-
#### Upload a local file
|
|
206
|
+
#### Upload a local file by deferred session
|
|
179
207
|
|
|
180
208
|
```python
|
|
209
|
+
from alfred.rest.files import UploadLocalFilePayload, UploadResponse
|
|
210
|
+
|
|
181
211
|
with open("<Path to local file>", "rb") as upload_file:
|
|
182
|
-
|
|
212
|
+
|
|
213
|
+
payload: UploadLocalFilePayload = {
|
|
183
214
|
"file": upload_file,
|
|
184
|
-
"
|
|
215
|
+
"filename": "file-name.jpeg", # optional
|
|
216
|
+
"session_id": "<session-id>",
|
|
185
217
|
"metadata": {}
|
|
186
|
-
}
|
|
218
|
+
}
|
|
219
|
+
result: UploadResponse = client.files.upload_file(payload)
|
|
187
220
|
print(result)
|
|
188
221
|
```
|
|
189
222
|
|
|
@@ -197,8 +230,7 @@ Data Points are the core of Alfred's platform and represent data that you want t
|
|
|
197
230
|
#### Get Data Point by File ID
|
|
198
231
|
|
|
199
232
|
```python
|
|
200
|
-
|
|
201
|
-
result = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
233
|
+
result = client.data_points.get_values("<file-id>")
|
|
202
234
|
print(result)
|
|
203
235
|
```
|
|
204
236
|
|
|
@@ -227,14 +259,14 @@ The `alfred-python` library provides a way to listen to events emitted by Alfred
|
|
|
227
259
|
To get started, you need to create an instance of the `AlfredRealTimeClient` class.
|
|
228
260
|
|
|
229
261
|
```python
|
|
230
|
-
from alfred import AlfredRealTimeClient
|
|
262
|
+
from alfred.realtime import AlfredRealTimeClient
|
|
231
263
|
from alfred.base import Configuration
|
|
232
|
-
from alfred import AuthConfiguration
|
|
264
|
+
from alfred.http import AuthConfiguration
|
|
233
265
|
|
|
234
266
|
config = Configuration.default()
|
|
235
267
|
|
|
236
268
|
auth_config = AuthConfiguration({
|
|
237
|
-
"api_key": "
|
|
269
|
+
"api_key": "<api-key>"
|
|
238
270
|
})
|
|
239
271
|
|
|
240
272
|
client = AlfredRealTimeClient(
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
alfred/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
2
|
-
alfred/base/__init__.py,sha256=
|
|
2
|
+
alfred/base/__init__.py,sha256=ofqXadRCm14fndC43dox_TdUKgrtXn1MveCzj7t6qA0,73
|
|
3
3
|
alfred/base/config.py,sha256=Uqakwi-5Hb73JrWcyhwlrWbTm2pJF_EKA6GaVXm58EQ,866
|
|
4
4
|
alfred/base/constants.py,sha256=hxSL_lISCWuSfglTpkQOl82KFX_u5HOO6LQh-oiybAM,3125
|
|
5
5
|
alfred/base/exceptions.py,sha256=LeKJq4JDNCtsQdfo8xzqwbum99H_3fVhlpkyPO2ChhU,301
|
|
6
6
|
alfred/exceptions/__init__.py,sha256=Um5nvtfKZaD_4vbrv6R9kazOejs8UKS2o0GafAddDx8,226
|
|
7
|
-
alfred/http/__init__.py,sha256=
|
|
8
|
-
alfred/http/http_client.py,sha256=
|
|
7
|
+
alfred/http/__init__.py,sha256=Gk-UEx2h6ZBQayngVo9UNiDaPZka5MTQIbpq7Zf4_eQ,48
|
|
8
|
+
alfred/http/http_client.py,sha256=opN0QVyEmRvVkwemp63XNG5_ga1L6N1QOlF4oL174KA,18536
|
|
9
9
|
alfred/http/typed.py,sha256=0lqZT9F16f2IxqDCIf0oeNuGRWHkFHY4RQCIc4iXna0,939
|
|
10
10
|
alfred/realtime/__init__.py,sha256=0oG5LjzvrOU4U6__o1AuNdtARe8yYn2di-v-vu8SV4E,4280
|
|
11
11
|
alfred/rest/__init__.py,sha256=VprIGEGvsyTbhggoFcgUKC7FSoX6adjSGCcu2sehTMo,2554
|
|
12
12
|
alfred/rest/data_points/__init__.py,sha256=893MGIl_fcqM1f3WBb_SuXFwJI9mWGJT6b85410ah0M,350
|
|
13
13
|
alfred/rest/data_points/base.py,sha256=89t_JRuQbUcp8H1jjG_Gr_w7g5BbtB_hcoGzmJ-Szq0,331
|
|
14
14
|
alfred/rest/data_points/v1.py,sha256=E0o13V_uoxDJuKxnGQ8tHtgjA6FlwmsgWXuTJHY3T6c,587
|
|
15
|
-
alfred/rest/files/__init__.py,sha256=
|
|
15
|
+
alfred/rest/files/__init__.py,sha256=_pqs0XJ35xYUtgUCPE12_4d0t4qFbQqfCKr3_sq7VLA,387
|
|
16
16
|
alfred/rest/files/base.py,sha256=KgtnJqb0D7dZh7rm-4UtXbuSbPeG8ZhYBOcATpRr0gQ,1246
|
|
17
17
|
alfred/rest/files/typed.py,sha256=hE-E3yJmnDYwcyDmrrXblFyUgrbIVrFly6FRfoGykkU,1666
|
|
18
|
-
alfred/rest/files/v1.py,sha256=
|
|
19
|
-
alfred/rest/jobs/__init__.py,sha256=
|
|
18
|
+
alfred/rest/files/v1.py,sha256=QYx23G9SLLihJQ1J4cIeDK03i-pS0oaSabqgmdnAdOc,2926
|
|
19
|
+
alfred/rest/jobs/__init__.py,sha256=J4A3kCoeiVnhzso9rIEwYyhkmMXBmC7E6oJ_s-cQ_O8,383
|
|
20
20
|
alfred/rest/jobs/base.py,sha256=016SM_9_BFms5Of2nWKa1jX-cT5HlbBdq15r2mHFb6Y,789
|
|
21
21
|
alfred/rest/jobs/typed.py,sha256=w0t6LfZbyawad8Zz6bTywc-RrvuRIL7R2L4hRHTe3ew,429
|
|
22
22
|
alfred/rest/jobs/v1.py,sha256=X_dowgRW6jErtSnCC3gIbGp8RMJTFgFMS32NNKarmzQ,1334
|
|
@@ -27,8 +27,8 @@ alfred/typings/__init__.py,sha256=F7iVP8Wv4FPfqlwFRR8M381Q55IYChCiTANYr1vgDDw,34
|
|
|
27
27
|
alfred/typings/misc.py,sha256=m2i4ktYiX8U6Hx00os9b6hSP9k6t_Y7DdAppE8hFJCc,216
|
|
28
28
|
alfred/utils/__init__.py,sha256=oCoKgEKGX2kefjKNrv5GgDaTY2JQRHXqr-VPeIC9u2Q,35
|
|
29
29
|
alfred/utils/logging.py,sha256=7pcLpP-klfv1FhgMp1WIc8BKEHQlOhrj7qjGYYw31cc,2333
|
|
30
|
-
alfred_python-0.6.
|
|
31
|
-
alfred_python-0.6.
|
|
32
|
-
alfred_python-0.6.
|
|
33
|
-
alfred_python-0.6.
|
|
34
|
-
alfred_python-0.6.
|
|
30
|
+
alfred_python-0.6.1.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
|
31
|
+
alfred_python-0.6.1.dist-info/METADATA,sha256=tcBLtyxOyP7G4KlAkQy8pk9VEwiaNxOzrJgu6KCQ3Tc,17797
|
|
32
|
+
alfred_python-0.6.1.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
33
|
+
alfred_python-0.6.1.dist-info/top_level.txt,sha256=ciQlts3Jwu5HdzhiQYDhjDGMoxlI9_CcqBEgc6PBE5U,7
|
|
34
|
+
alfred_python-0.6.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|