alfred-python 0.6.0__tar.gz → 0.6.2__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.
Files changed (43) hide show
  1. {alfred_python-0.6.0 → alfred_python-0.6.2}/PKG-INFO +66 -34
  2. {alfred_python-0.6.0 → alfred_python-0.6.2}/README.md +63 -33
  3. alfred_python-0.6.2/alfred/base/__init__.py +3 -0
  4. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/base/constants.py +1 -1
  5. alfred_python-0.6.2/alfred/base/typed.py +4 -0
  6. alfred_python-0.6.2/alfred/http/__init__.py +2 -0
  7. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/http/http_client.py +7 -3
  8. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/http/typed.py +3 -6
  9. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/files/__init__.py +1 -0
  10. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/files/v1.py +20 -13
  11. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/jobs/__init__.py +1 -0
  12. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred_python.egg-info/PKG-INFO +66 -34
  13. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred_python.egg-info/SOURCES.txt +1 -0
  14. alfred_python-0.6.2/alfred_python.egg-info/requires.txt +11 -0
  15. {alfred_python-0.6.0 → alfred_python-0.6.2}/pyproject.toml +4 -2
  16. alfred_python-0.6.0/alfred/base/__init__.py +0 -0
  17. alfred_python-0.6.0/alfred/http/__init__.py +0 -0
  18. alfred_python-0.6.0/alfred_python.egg-info/requires.txt +0 -5
  19. {alfred_python-0.6.0 → alfred_python-0.6.2}/LICENSE +0 -0
  20. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/__init__.py +0 -0
  21. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/base/config.py +0 -0
  22. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/base/exceptions.py +0 -0
  23. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/exceptions/__init__.py +0 -0
  24. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/realtime/__init__.py +0 -0
  25. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/__init__.py +0 -0
  26. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/data_points/__init__.py +0 -0
  27. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/data_points/base.py +0 -0
  28. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/data_points/v1.py +0 -0
  29. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/files/base.py +0 -0
  30. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/files/typed.py +0 -0
  31. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/jobs/base.py +0 -0
  32. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/jobs/typed.py +0 -0
  33. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/jobs/v1.py +0 -0
  34. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/sessions/__init__.py +0 -0
  35. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/sessions/base.py +0 -0
  36. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/rest/sessions/v1.py +0 -0
  37. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/typings/__init__.py +0 -0
  38. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/typings/misc.py +0 -0
  39. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/utils/__init__.py +0 -0
  40. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred/utils/logging.py +0 -0
  41. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred_python.egg-info/dependency_links.txt +0 -0
  42. {alfred_python-0.6.0 → alfred_python-0.6.2}/alfred_python.egg-info/top_level.txt +0 -0
  43. {alfred_python-0.6.0 → alfred_python-0.6.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: alfred-python
3
- Version: 0.6.0
3
+ Version: 0.6.2
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 = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
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("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- #### Get session by ID
72
+ #### Create session
68
73
 
69
74
  ```python
70
- # Get a session by ID
71
- result = client.sessions.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
72
- print(result)
75
+ result = client.sessions.create()
76
+ session_id = result.get("session_id")
77
+ print(session_id)
73
78
  ```
74
79
 
75
- #### Create session
80
+ #### Get session by ID
76
81
 
77
82
  ```python
78
- # Create a session
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
- # Get a job by ID
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
- job = {
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
- # Get a file by ID
153
- result = client.files.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- # Download a file by ID
161
- result = client.files.download("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- # Upload a remote file
171
- result = client.files.upload({
172
- "url": "<File URL>",
173
- "metadata": {}
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
- result = client.files.upload_file({
212
+
213
+ payload: UploadLocalFilePayload = {
183
214
  "file": upload_file,
184
- "session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
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
- # Get a data point by file ID
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": "AXXXXXXXXXXXXXXXXXXXXXX"
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 = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
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("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- #### Get session by ID
33
+ #### Create session
31
34
 
32
35
  ```python
33
- # Get a session by ID
34
- result = client.sessions.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
35
- print(result)
36
+ result = client.sessions.create()
37
+ session_id = result.get("session_id")
38
+ print(session_id)
36
39
  ```
37
40
 
38
- #### Create session
41
+ #### Get session by ID
39
42
 
40
43
  ```python
41
- # Create a session
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
- # Get a job by ID
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
- job = {
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
- # Get a file by ID
116
- result = client.files.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- # Download a file by ID
124
- result = client.files.download("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- # Upload a remote file
134
- result = client.files.upload({
135
- "url": "<File URL>",
136
- "metadata": {}
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
- result = client.files.upload_file({
173
+
174
+ payload: UploadLocalFilePayload = {
146
175
  "file": upload_file,
147
- "session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
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
- # Get a data point by file ID
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": "AXXXXXXXXXXXXXXXXXXXXXX"
230
+ "api_key": "<api-key>"
201
231
  })
202
232
 
203
233
  client = AlfredRealTimeClient(
@@ -0,0 +1,3 @@
1
+ from .config import *
2
+ from .constants import *
3
+ from .exceptions import *
@@ -1,6 +1,6 @@
1
1
  from enum import Enum
2
2
 
3
- from alfred.http.typed import ResponseType
3
+ from alfred.base.typed import ResponseType
4
4
 
5
5
  # Response type/header mapping
6
6
  RESPONSE_TYPE_HEADER_MAPPING = {
@@ -0,0 +1,4 @@
1
+ class ResponseType:
2
+ JSON = "json"
3
+ TEXT = "text"
4
+ XML = "xml"
@@ -0,0 +1,2 @@
1
+ from .typed import *
2
+ from .http_client import *
@@ -17,6 +17,7 @@ from urllib3.util.retry import Retry
17
17
 
18
18
  # Project imports
19
19
  from .typed import * # pylint: disable=W0401, W0614
20
+ from ..base.typed import ResponseType
20
21
  from ..base.constants import RESPONSE_TYPE_HEADER_MAPPING
21
22
  from ..base.exceptions import AlfredMissingAuthException
22
23
  from ..utils import logging
@@ -255,7 +256,7 @@ class HttpClient:
255
256
  hmac_key = f"amx {secret_key}:{signature_base64}:{nonce}:{request_timestamp}"
256
257
  prepped_request.headers.update({"Authorization": hmac_key})
257
258
 
258
- def __get_headers(self, headers: Optional[Dict[str, str]]) -> Dict[str, str]:
259
+ def __get_headers(self, headers: Optional[Dict[str, str]], has_files: bool = False) -> Dict[str, str]:
259
260
  """
260
261
  Get the request headers.
261
262
 
@@ -265,10 +266,13 @@ class HttpClient:
265
266
  headers = headers or {}
266
267
  default_headers = {
267
268
  "Accept-Charset": "utf-8",
268
- "Content-Type": "application/json",
269
269
  "Accept": RESPONSE_TYPE_HEADER_MAPPING.get(self.response_type),
270
270
  }
271
271
 
272
+ # Set default Content-Type only if it's not a file upload
273
+ if "Content-Type" not in headers and not has_files:
274
+ default_headers["Content-Type"] = "application/json"
275
+
272
276
  return {**default_headers, **headers}
273
277
 
274
278
  @staticmethod
@@ -326,7 +330,7 @@ class HttpClient:
326
330
  elif timeout <= 0:
327
331
  raise ValueError(timeout)
328
332
 
329
- headers = self.__get_headers(headers)
333
+ headers = self.__get_headers(headers, has_files=bool(files))
330
334
  url = self.base_url + uri
331
335
 
332
336
  kwargs = {
@@ -2,6 +2,9 @@
2
2
  from enum import Enum
3
3
  from typing import TypedDict, Optional, Text
4
4
 
5
+ # Project Imports
6
+ from alfred.base import ResponseType
7
+
5
8
 
6
9
  class HttpMethod(Enum):
7
10
  POST = "POST"
@@ -18,12 +21,6 @@ class AuthMethod(Enum):
18
21
  HMAC = ("hmac",)
19
22
 
20
23
 
21
- class ResponseType:
22
- JSON = "json"
23
- TEXT = "text"
24
- XML = "xml"
25
-
26
-
27
24
  class OAuthConfiguration(TypedDict):
28
25
  username: Text
29
26
  password: Text
@@ -1,4 +1,5 @@
1
1
  from .base import FilesBase
2
+ from .typed import *
2
3
  from .v1 import Files as V1
3
4
 
4
5
 
@@ -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
- ("file", (filename, file, "application/octet-stream")),
53
- ("session_id", (None, payload["session_id"], "text/plain")),
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
- parsed_resp, _ = self.http_client.post(
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
- files=files,
63
- headers={"content-type": None},
68
+ data=data,
69
+ files=files
64
70
  )
65
- return parsed_resp
71
+
72
+ return parsed_response
66
73
 
67
74
  def __extract_filename(self, content_disposition: Text):
68
75
  """
@@ -1,4 +1,5 @@
1
1
  from .base import JobsBase
2
+ from .typed import *
2
3
  from .v1 import Jobs as V1
3
4
 
4
5
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: alfred-python
3
- Version: 0.6.0
3
+ Version: 0.6.2
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 = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
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("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- #### Get session by ID
72
+ #### Create session
68
73
 
69
74
  ```python
70
- # Get a session by ID
71
- result = client.sessions.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
72
- print(result)
75
+ result = client.sessions.create()
76
+ session_id = result.get("session_id")
77
+ print(session_id)
73
78
  ```
74
79
 
75
- #### Create session
80
+ #### Get session by ID
76
81
 
77
82
  ```python
78
- # Create a session
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
- # Get a job by ID
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
- job = {
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
- # Get a file by ID
153
- result = client.files.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- # Download a file by ID
161
- result = client.files.download("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
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
- # Upload a remote file
171
- result = client.files.upload({
172
- "url": "<File URL>",
173
- "metadata": {}
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
- result = client.files.upload_file({
212
+
213
+ payload: UploadLocalFilePayload = {
183
214
  "file": upload_file,
184
- "session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
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
- # Get a data point by file ID
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": "AXXXXXXXXXXXXXXXXXXXXXX"
269
+ "api_key": "<api-key>"
238
270
  })
239
271
 
240
272
  client = AlfredRealTimeClient(
@@ -6,6 +6,7 @@ alfred/base/__init__.py
6
6
  alfred/base/config.py
7
7
  alfred/base/constants.py
8
8
  alfred/base/exceptions.py
9
+ alfred/base/typed.py
9
10
  alfred/exceptions/__init__.py
10
11
  alfred/http/__init__.py
11
12
  alfred/http/http_client.py
@@ -0,0 +1,11 @@
1
+ pydantic>=2.0
2
+ pydantic-settings>=2.0
3
+ requests>=2.30
4
+ python-socketio>=5.11
5
+ websocket-client>=1.8
6
+
7
+ [:platform_system != "Windows"]
8
+ python-magic==0.4.27
9
+
10
+ [:platform_system == "Windows"]
11
+ python-magic-bin==0.4.14
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "alfred-python"
7
- version = "0.6.0"
7
+ version = "0.6.2"
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
@@ -1,5 +0,0 @@
1
- pydantic>=2.0
2
- pydantic-settings>=2.0
3
- requests>=2.30
4
- python-socketio>=5.11
5
- websocket-client>=1.8
File without changes
File without changes