alfred-python 0.6.0__tar.gz → 0.6.1__tar.gz
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_python-0.6.0 → alfred_python-0.6.1}/PKG-INFO +66 -34
- {alfred_python-0.6.0 → alfred_python-0.6.1}/README.md +63 -33
- alfred_python-0.6.1/alfred/base/__init__.py +3 -0
- alfred_python-0.6.1/alfred/http/__init__.py +2 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/http/http_client.py +6 -3
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/files/__init__.py +1 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/files/v1.py +20 -13
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/jobs/__init__.py +1 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred_python.egg-info/PKG-INFO +66 -34
- alfred_python-0.6.1/alfred_python.egg-info/requires.txt +11 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/pyproject.toml +4 -2
- alfred_python-0.6.0/alfred/base/__init__.py +0 -0
- alfred_python-0.6.0/alfred/http/__init__.py +0 -0
- alfred_python-0.6.0/alfred_python.egg-info/requires.txt +0 -5
- {alfred_python-0.6.0 → alfred_python-0.6.1}/LICENSE +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/base/config.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/base/constants.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/base/exceptions.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/exceptions/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/http/typed.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/realtime/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/data_points/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/data_points/base.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/data_points/v1.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/files/base.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/files/typed.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/jobs/base.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/jobs/typed.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/jobs/v1.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/sessions/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/sessions/base.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/rest/sessions/v1.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/typings/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/typings/misc.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/utils/__init__.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred/utils/logging.py +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred_python.egg-info/SOURCES.txt +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred_python.egg-info/dependency_links.txt +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/alfred_python.egg-info/top_level.txt +0 -0
- {alfred_python-0.6.0 → alfred_python-0.6.1}/setup.cfg +0 -0
|
@@ -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(
|
|
@@ -13,13 +13,16 @@ Check out this simple example to get up and running:
|
|
|
13
13
|
```python
|
|
14
14
|
from alfred.rest import AlfredClient
|
|
15
15
|
from alfred.base import Configuration
|
|
16
|
+
from alfred.http import AuthConfiguration
|
|
16
17
|
|
|
17
18
|
config = Configuration.default()
|
|
18
|
-
auth_config =
|
|
19
|
+
auth_config = AuthConfiguration(
|
|
20
|
+
api_key = "<api-key>"
|
|
21
|
+
)
|
|
19
22
|
|
|
20
23
|
client = AlfredClient(config, auth_config)
|
|
21
24
|
|
|
22
|
-
values = client.data_points.get_values("
|
|
25
|
+
values = client.data_points.get_values("<file-id>")
|
|
23
26
|
print(values)
|
|
24
27
|
```
|
|
25
28
|
|
|
@@ -27,19 +30,18 @@ print(values)
|
|
|
27
30
|
|
|
28
31
|
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).
|
|
29
32
|
|
|
30
|
-
####
|
|
33
|
+
#### Create session
|
|
31
34
|
|
|
32
35
|
```python
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
print(
|
|
36
|
+
result = client.sessions.create()
|
|
37
|
+
session_id = result.get("session_id")
|
|
38
|
+
print(session_id)
|
|
36
39
|
```
|
|
37
40
|
|
|
38
|
-
####
|
|
41
|
+
#### Get session by ID
|
|
39
42
|
|
|
40
43
|
```python
|
|
41
|
-
|
|
42
|
-
result = client.sessions.create()
|
|
44
|
+
result = client.sessions.get("<session-id>")
|
|
43
45
|
print(result)
|
|
44
46
|
```
|
|
45
47
|
|
|
@@ -50,15 +52,13 @@ A Job represents a single unit of work that group one or more Files within Alfre
|
|
|
50
52
|
#### Get job by ID
|
|
51
53
|
|
|
52
54
|
```python
|
|
53
|
-
|
|
54
|
-
result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
55
|
+
result = client.jobs.get("<job-id>")
|
|
55
56
|
print(result)
|
|
56
57
|
```
|
|
57
58
|
|
|
58
59
|
#### Get paginated jobs
|
|
59
60
|
|
|
60
61
|
```python
|
|
61
|
-
# Get paginated jobs
|
|
62
62
|
response = client.jobs.get_all(page_size=None, current_page=None)
|
|
63
63
|
print(response.is_empty)
|
|
64
64
|
print(response.result)
|
|
@@ -68,7 +68,9 @@ print(response.total)
|
|
|
68
68
|
#### Create job
|
|
69
69
|
|
|
70
70
|
```python
|
|
71
|
-
|
|
71
|
+
from alfred.rest.jobs import CreateJobDict
|
|
72
|
+
|
|
73
|
+
job: CreateJobDict = {
|
|
72
74
|
"session_id": "session-id",
|
|
73
75
|
"propagate_metadata": True,
|
|
74
76
|
"merge": True,
|
|
@@ -84,7 +86,6 @@ job = {
|
|
|
84
86
|
"file_names": ["file-name-1", "file-name-2"],
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
# Create a job
|
|
88
89
|
result = client.jobs.create(job)
|
|
89
90
|
print(result)
|
|
90
91
|
```
|
|
@@ -112,41 +113,71 @@ File is an individual document or data unit undergoing specialized operations ta
|
|
|
112
113
|
#### Get file by ID
|
|
113
114
|
|
|
114
115
|
```python
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
from alfred.rest.files import FileDetailsResponse
|
|
117
|
+
|
|
118
|
+
result: FileDetailsResponse = client.files.get("<file-id>")
|
|
117
119
|
print(result)
|
|
118
120
|
```
|
|
119
121
|
|
|
120
122
|
#### Download file by ID
|
|
121
123
|
|
|
122
124
|
```python
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
from alfred.rest.files import DownloadResponse
|
|
126
|
+
|
|
127
|
+
result: DownloadResponse = client.files.download("<file-id>")
|
|
125
128
|
|
|
126
129
|
with open(result.get("original_name"), "wb") as f:
|
|
127
130
|
f.write(result.get("file").getvalue())
|
|
128
131
|
```
|
|
129
132
|
|
|
130
|
-
#### Upload remote file
|
|
133
|
+
#### Upload a single remote file and create a Job
|
|
131
134
|
|
|
132
135
|
```python
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
"
|
|
137
|
-
|
|
136
|
+
from alfred.rest.files import UploadRemoteFilePayload, UploadResponse
|
|
137
|
+
|
|
138
|
+
payload: UploadRemoteFilePayload = {
|
|
139
|
+
"url": "<file-url>",
|
|
140
|
+
"filename" "file-name", # optional
|
|
141
|
+
"metadata": {
|
|
142
|
+
"key": "value",
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
result: UploadResponse = client.files.upload(payload)
|
|
147
|
+
print(result)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Upload multiple remote files and create a Job
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from alfred.rest.files import UploadRemoteFilePayload, UploadResponse
|
|
154
|
+
|
|
155
|
+
payload: UploadRemoteFilePayload = {
|
|
156
|
+
"urls": ["<file-url>", "<file-url-2>"],
|
|
157
|
+
"filenames": ["file-name", "file-name-2"], # optional
|
|
158
|
+
"metadata": {
|
|
159
|
+
"key": "value",
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
result: UploadResponse = client.files.upload(payload)
|
|
138
164
|
print(result)
|
|
139
165
|
```
|
|
140
166
|
|
|
141
|
-
#### Upload a local file
|
|
167
|
+
#### Upload a local file by deferred session
|
|
142
168
|
|
|
143
169
|
```python
|
|
170
|
+
from alfred.rest.files import UploadLocalFilePayload, UploadResponse
|
|
171
|
+
|
|
144
172
|
with open("<Path to local file>", "rb") as upload_file:
|
|
145
|
-
|
|
173
|
+
|
|
174
|
+
payload: UploadLocalFilePayload = {
|
|
146
175
|
"file": upload_file,
|
|
147
|
-
"
|
|
176
|
+
"filename": "file-name.jpeg", # optional
|
|
177
|
+
"session_id": "<session-id>",
|
|
148
178
|
"metadata": {}
|
|
149
|
-
}
|
|
179
|
+
}
|
|
180
|
+
result: UploadResponse = client.files.upload_file(payload)
|
|
150
181
|
print(result)
|
|
151
182
|
```
|
|
152
183
|
|
|
@@ -160,8 +191,7 @@ Data Points are the core of Alfred's platform and represent data that you want t
|
|
|
160
191
|
#### Get Data Point by File ID
|
|
161
192
|
|
|
162
193
|
```python
|
|
163
|
-
|
|
164
|
-
result = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
194
|
+
result = client.data_points.get_values("<file-id>")
|
|
165
195
|
print(result)
|
|
166
196
|
```
|
|
167
197
|
|
|
@@ -190,14 +220,14 @@ The `alfred-python` library provides a way to listen to events emitted by Alfred
|
|
|
190
220
|
To get started, you need to create an instance of the `AlfredRealTimeClient` class.
|
|
191
221
|
|
|
192
222
|
```python
|
|
193
|
-
from alfred import AlfredRealTimeClient
|
|
223
|
+
from alfred.realtime import AlfredRealTimeClient
|
|
194
224
|
from alfred.base import Configuration
|
|
195
|
-
from alfred import AuthConfiguration
|
|
225
|
+
from alfred.http import AuthConfiguration
|
|
196
226
|
|
|
197
227
|
config = Configuration.default()
|
|
198
228
|
|
|
199
229
|
auth_config = AuthConfiguration({
|
|
200
|
-
"api_key": "
|
|
230
|
+
"api_key": "<api-key>"
|
|
201
231
|
})
|
|
202
232
|
|
|
203
233
|
client = AlfredRealTimeClient(
|
|
@@ -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 = {
|
|
@@ -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
|
"""
|
|
@@ -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(
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "alfred-python"
|
|
7
|
-
version = "0.6.
|
|
7
|
+
version = "0.6.1"
|
|
8
8
|
authors = [{ name = "Tagshelf LLC", email = "support@tagshelf.com" }]
|
|
9
9
|
description = "Python library designed to simplify and streamline interactions with the Alfred API"
|
|
10
10
|
readme = "README.md"
|
|
@@ -20,7 +20,9 @@ dependencies = [
|
|
|
20
20
|
"pydantic-settings >= 2.0",
|
|
21
21
|
"requests >= 2.30",
|
|
22
22
|
"python-socketio >= 5.11",
|
|
23
|
-
"websocket-client >= 1.8"
|
|
23
|
+
"websocket-client >= 1.8",
|
|
24
|
+
"python-magic==0.4.27; platform_system != 'Windows'",
|
|
25
|
+
"python-magic-bin==0.4.14; platform_system == 'Windows'"
|
|
24
26
|
]
|
|
25
27
|
|
|
26
28
|
[project.urls]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|