alfred-python 0.5.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.
Files changed (42) hide show
  1. {alfred_python-0.5.0 → alfred_python-0.6.1}/PKG-INFO +82 -34
  2. {alfred_python-0.5.0 → alfred_python-0.6.1}/README.md +79 -33
  3. alfred_python-0.6.1/alfred/base/__init__.py +3 -0
  4. alfred_python-0.6.1/alfred/http/__init__.py +2 -0
  5. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/http/http_client.py +6 -3
  6. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/realtime/__init__.py +13 -5
  7. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/files/__init__.py +1 -0
  8. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/files/v1.py +20 -13
  9. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/jobs/__init__.py +1 -0
  10. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/jobs/base.py +10 -0
  11. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/jobs/v1.py +16 -0
  12. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred_python.egg-info/PKG-INFO +82 -34
  13. alfred_python-0.6.1/alfred_python.egg-info/requires.txt +11 -0
  14. {alfred_python-0.5.0 → alfred_python-0.6.1}/pyproject.toml +4 -2
  15. alfred_python-0.5.0/alfred/base/__init__.py +0 -0
  16. alfred_python-0.5.0/alfred/http/__init__.py +0 -0
  17. alfred_python-0.5.0/alfred_python.egg-info/requires.txt +0 -5
  18. {alfred_python-0.5.0 → alfred_python-0.6.1}/LICENSE +0 -0
  19. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/__init__.py +0 -0
  20. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/base/config.py +0 -0
  21. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/base/constants.py +0 -0
  22. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/base/exceptions.py +0 -0
  23. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/exceptions/__init__.py +0 -0
  24. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/http/typed.py +0 -0
  25. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/__init__.py +0 -0
  26. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/data_points/__init__.py +0 -0
  27. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/data_points/base.py +0 -0
  28. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/data_points/v1.py +0 -0
  29. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/files/base.py +0 -0
  30. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/files/typed.py +0 -0
  31. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/jobs/typed.py +0 -0
  32. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/sessions/__init__.py +0 -0
  33. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/sessions/base.py +0 -0
  34. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/rest/sessions/v1.py +0 -0
  35. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/typings/__init__.py +0 -0
  36. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/typings/misc.py +0 -0
  37. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/utils/__init__.py +0 -0
  38. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred/utils/logging.py +0 -0
  39. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred_python.egg-info/SOURCES.txt +0 -0
  40. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred_python.egg-info/dependency_links.txt +0 -0
  41. {alfred_python-0.5.0 → alfred_python-0.6.1}/alfred_python.egg-info/top_level.txt +0 -0
  42. {alfred_python-0.5.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.5.0
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 = {"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,25 @@ 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
 
98
+ #### Get paginated jobs
99
+
100
+ ```python
101
+ response = client.jobs.get_all(page_size=None, current_page=None)
102
+ print(response.is_empty)
103
+ print(response.result)
104
+ print(response.total)
105
+ ```
106
+
95
107
  #### Create job
96
108
 
97
109
  ```python
98
- job = {
110
+ from alfred.rest.jobs import CreateJobDict
111
+
112
+ job: CreateJobDict = {
99
113
  "session_id": "session-id",
100
114
  "propagate_metadata": True,
101
115
  "merge": True,
@@ -111,7 +125,6 @@ job = {
111
125
  "file_names": ["file-name-1", "file-name-2"],
112
126
  }
113
127
 
114
- # Create a job
115
128
  result = client.jobs.create(job)
116
129
  print(result)
117
130
  ```
@@ -139,41 +152,71 @@ File is an individual document or data unit undergoing specialized operations ta
139
152
  #### Get file by ID
140
153
 
141
154
  ```python
142
- # Get a file by ID
143
- 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>")
144
158
  print(result)
145
159
  ```
146
160
 
147
161
  #### Download file by ID
148
162
 
149
163
  ```python
150
- # Download a file by ID
151
- 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>")
152
167
 
153
168
  with open(result.get("original_name"), "wb") as f:
154
169
  f.write(result.get("file").getvalue())
155
170
  ```
156
171
 
157
- #### Upload remote file
172
+ #### Upload a single remote file and create a Job
158
173
 
159
174
  ```python
160
- # Upload a remote file
161
- result = client.files.upload({
162
- "url": "<File URL>",
163
- "metadata": {}
164
- })
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)
165
203
  print(result)
166
204
  ```
167
205
 
168
- #### Upload a local file
206
+ #### Upload a local file by deferred session
169
207
 
170
208
  ```python
209
+ from alfred.rest.files import UploadLocalFilePayload, UploadResponse
210
+
171
211
  with open("<Path to local file>", "rb") as upload_file:
172
- result = client.files.upload_file({
212
+
213
+ payload: UploadLocalFilePayload = {
173
214
  "file": upload_file,
174
- "session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
215
+ "filename": "file-name.jpeg", # optional
216
+ "session_id": "<session-id>",
175
217
  "metadata": {}
176
- })
218
+ }
219
+ result: UploadResponse = client.files.upload_file(payload)
177
220
  print(result)
178
221
  ```
179
222
 
@@ -187,8 +230,7 @@ Data Points are the core of Alfred's platform and represent data that you want t
187
230
  #### Get Data Point by File ID
188
231
 
189
232
  ```python
190
- # Get a data point by file ID
191
- result = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
233
+ result = client.data_points.get_values("<file-id>")
192
234
  print(result)
193
235
  ```
194
236
 
@@ -217,17 +259,23 @@ The `alfred-python` library provides a way to listen to events emitted by Alfred
217
259
  To get started, you need to create an instance of the `AlfredRealTimeClient` class.
218
260
 
219
261
  ```python
220
- from alfred import AlfredRealTimeClient
262
+ from alfred.realtime import AlfredRealTimeClient
221
263
  from alfred.base import Configuration
222
- from alfred import AuthConfiguration
264
+ from alfred.http import AuthConfiguration
223
265
 
224
266
  config = Configuration.default()
225
267
 
226
268
  auth_config = AuthConfiguration({
227
- "api_key": "AXXXXXXXXXXXXXXXXXXXXXX"
269
+ "api_key": "<api-key>"
228
270
  })
229
271
 
230
- client = AlfredRealTimeClient(config, auth_config, verbose=True)
272
+ client = AlfredRealTimeClient(
273
+ config,
274
+ auth_config,
275
+ verbose=False,
276
+ on_callback=None,
277
+ on_connect=None
278
+ )
231
279
  ```
232
280
 
233
281
  ### File Events
@@ -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,25 @@ 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
 
59
+ #### Get paginated jobs
60
+
61
+ ```python
62
+ response = client.jobs.get_all(page_size=None, current_page=None)
63
+ print(response.is_empty)
64
+ print(response.result)
65
+ print(response.total)
66
+ ```
67
+
58
68
  #### Create job
59
69
 
60
70
  ```python
61
- job = {
71
+ from alfred.rest.jobs import CreateJobDict
72
+
73
+ job: CreateJobDict = {
62
74
  "session_id": "session-id",
63
75
  "propagate_metadata": True,
64
76
  "merge": True,
@@ -74,7 +86,6 @@ job = {
74
86
  "file_names": ["file-name-1", "file-name-2"],
75
87
  }
76
88
 
77
- # Create a job
78
89
  result = client.jobs.create(job)
79
90
  print(result)
80
91
  ```
@@ -102,41 +113,71 @@ File is an individual document or data unit undergoing specialized operations ta
102
113
  #### Get file by ID
103
114
 
104
115
  ```python
105
- # Get a file by ID
106
- 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>")
107
119
  print(result)
108
120
  ```
109
121
 
110
122
  #### Download file by ID
111
123
 
112
124
  ```python
113
- # Download a file by ID
114
- 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>")
115
128
 
116
129
  with open(result.get("original_name"), "wb") as f:
117
130
  f.write(result.get("file").getvalue())
118
131
  ```
119
132
 
120
- #### Upload remote file
133
+ #### Upload a single remote file and create a Job
121
134
 
122
135
  ```python
123
- # Upload a remote file
124
- result = client.files.upload({
125
- "url": "<File URL>",
126
- "metadata": {}
127
- })
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)
128
164
  print(result)
129
165
  ```
130
166
 
131
- #### Upload a local file
167
+ #### Upload a local file by deferred session
132
168
 
133
169
  ```python
170
+ from alfred.rest.files import UploadLocalFilePayload, UploadResponse
171
+
134
172
  with open("<Path to local file>", "rb") as upload_file:
135
- result = client.files.upload_file({
173
+
174
+ payload: UploadLocalFilePayload = {
136
175
  "file": upload_file,
137
- "session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
176
+ "filename": "file-name.jpeg", # optional
177
+ "session_id": "<session-id>",
138
178
  "metadata": {}
139
- })
179
+ }
180
+ result: UploadResponse = client.files.upload_file(payload)
140
181
  print(result)
141
182
  ```
142
183
 
@@ -150,8 +191,7 @@ Data Points are the core of Alfred's platform and represent data that you want t
150
191
  #### Get Data Point by File ID
151
192
 
152
193
  ```python
153
- # Get a data point by file ID
154
- result = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
194
+ result = client.data_points.get_values("<file-id>")
155
195
  print(result)
156
196
  ```
157
197
 
@@ -180,17 +220,23 @@ The `alfred-python` library provides a way to listen to events emitted by Alfred
180
220
  To get started, you need to create an instance of the `AlfredRealTimeClient` class.
181
221
 
182
222
  ```python
183
- from alfred import AlfredRealTimeClient
223
+ from alfred.realtime import AlfredRealTimeClient
184
224
  from alfred.base import Configuration
185
- from alfred import AuthConfiguration
225
+ from alfred.http import AuthConfiguration
186
226
 
187
227
  config = Configuration.default()
188
228
 
189
229
  auth_config = AuthConfiguration({
190
- "api_key": "AXXXXXXXXXXXXXXXXXXXXXX"
230
+ "api_key": "<api-key>"
191
231
  })
192
232
 
193
- client = AlfredRealTimeClient(config, auth_config, verbose=True)
233
+ client = AlfredRealTimeClient(
234
+ config,
235
+ auth_config,
236
+ verbose=False,
237
+ on_callback=None,
238
+ on_connect=None
239
+ )
194
240
  ```
195
241
 
196
242
  ### File Events
@@ -0,0 +1,3 @@
1
+ from .config import *
2
+ from .constants import *
3
+ from .exceptions import *
@@ -0,0 +1,2 @@
1
+ from .typed import *
2
+ from .http_client import *
@@ -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 = {
@@ -13,7 +13,7 @@ from alfred.utils import logging, setup_logger
13
13
 
14
14
 
15
15
  class AlfredRealTimeClient:
16
- def __init__(self, config: ConfigurationDict, auth_config: AuthConfiguration, verbose=False):
16
+ def __init__(self, config: ConfigurationDict, auth_config: AuthConfiguration, verbose=False, error_callback=None, on_connect=None):
17
17
  """
18
18
  Initializes the AlfredRealTimeClient class.
19
19
 
@@ -27,6 +27,8 @@ class AlfredRealTimeClient:
27
27
  self.config = config
28
28
  self.auth_config = auth_config
29
29
  self.base_url = config.get("realtime_url")
30
+ self.error_callback = error_callback
31
+ self.on_connect = on_connect
30
32
 
31
33
  # Initialize logger
32
34
  self.logger = logging.getLogger("alfred-python")
@@ -35,7 +37,6 @@ class AlfredRealTimeClient:
35
37
  "level": "DEBUG" if verbose else "INFO",
36
38
  "name": "alfred-python"
37
39
  })
38
- print(self.logger.level)
39
40
 
40
41
  # Subscribe to connection life-cycle events.
41
42
  self.socket.on('connect', self.__on_connect)
@@ -55,12 +56,15 @@ class AlfredRealTimeClient:
55
56
  Handles the 'connect' event.
56
57
  """
57
58
  self.logger.info(f"Successfully connected to: {self.base_url}")
59
+ if self.on_connect:
60
+ self.on_connect()
58
61
 
59
62
  def __on_disconnect(self):
60
63
  """
61
64
  Handles the 'disconnect' event.
62
65
  """
63
- self.logger.info("Disconnected from the server.")
66
+ if self.verbose:
67
+ self.logger.info("Disconnected from the server.")
64
68
 
65
69
  def __on_connect_error(self, err):
66
70
  """
@@ -69,9 +73,12 @@ class AlfredRealTimeClient:
69
73
  Args:
70
74
  err (str): The error message.
71
75
  """
72
- self.logger.info("Connection error: %s", err)
76
+ if self.verbose:
77
+ self.logger.error("Connection error: %s", err)
73
78
  self.disconnect()
74
- raise Exception(f"Failed to connect to {self.base_url}: {err}")
79
+ # trigger error callback:
80
+ if self.error_callback:
81
+ self.error_callback(err)
75
82
 
76
83
  def __callback(self, event: Union[FileEvent, JobEvent, EventType], callback):
77
84
  """
@@ -122,3 +129,4 @@ class AlfredRealTimeClient:
122
129
  """
123
130
  self.logger.info("Closing connection...")
124
131
  self.socket.disconnect()
132
+
@@ -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
 
@@ -22,3 +22,13 @@ class JobsBase(ABC):
22
22
  Args:
23
23
  - job_id: Unique identifier of the Job.
24
24
  """
25
+
26
+ @abstractmethod
27
+ def get_all(self, page_size: int = None, current_page: int = None) -> Any:
28
+ """
29
+ Fetches all jobs for a company
30
+
31
+ Args:
32
+ - page_size: Number of jobs to fetch per page.
33
+ - current_page: Page number to fetch.
34
+ """
@@ -30,3 +30,19 @@ class Jobs(JobsBase):
30
30
  """
31
31
  parsed_resp, _ = self.http_client.get(f"/api/job/detail/{job_id}")
32
32
  return parsed_resp
33
+
34
+ def get_all(self, page_size: int = None, current_page: int = None):
35
+ """
36
+ Fetches all jobs for a company
37
+
38
+ Args:
39
+ - page_size: Number of jobs to fetch per page.
40
+ - current_page: Page number to fetch.
41
+ """
42
+ params = {}
43
+ if page_size:
44
+ params["pageSize"] = page_size
45
+ if current_page:
46
+ params["currentPage"] = current_page
47
+ parsed_resp, _ = self.http_client.get("/api/job/all", params=params)
48
+ return parsed_resp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: alfred-python
3
- Version: 0.5.0
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 = {"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,25 @@ 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
 
98
+ #### Get paginated jobs
99
+
100
+ ```python
101
+ response = client.jobs.get_all(page_size=None, current_page=None)
102
+ print(response.is_empty)
103
+ print(response.result)
104
+ print(response.total)
105
+ ```
106
+
95
107
  #### Create job
96
108
 
97
109
  ```python
98
- job = {
110
+ from alfred.rest.jobs import CreateJobDict
111
+
112
+ job: CreateJobDict = {
99
113
  "session_id": "session-id",
100
114
  "propagate_metadata": True,
101
115
  "merge": True,
@@ -111,7 +125,6 @@ job = {
111
125
  "file_names": ["file-name-1", "file-name-2"],
112
126
  }
113
127
 
114
- # Create a job
115
128
  result = client.jobs.create(job)
116
129
  print(result)
117
130
  ```
@@ -139,41 +152,71 @@ File is an individual document or data unit undergoing specialized operations ta
139
152
  #### Get file by ID
140
153
 
141
154
  ```python
142
- # Get a file by ID
143
- 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>")
144
158
  print(result)
145
159
  ```
146
160
 
147
161
  #### Download file by ID
148
162
 
149
163
  ```python
150
- # Download a file by ID
151
- 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>")
152
167
 
153
168
  with open(result.get("original_name"), "wb") as f:
154
169
  f.write(result.get("file").getvalue())
155
170
  ```
156
171
 
157
- #### Upload remote file
172
+ #### Upload a single remote file and create a Job
158
173
 
159
174
  ```python
160
- # Upload a remote file
161
- result = client.files.upload({
162
- "url": "<File URL>",
163
- "metadata": {}
164
- })
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)
165
203
  print(result)
166
204
  ```
167
205
 
168
- #### Upload a local file
206
+ #### Upload a local file by deferred session
169
207
 
170
208
  ```python
209
+ from alfred.rest.files import UploadLocalFilePayload, UploadResponse
210
+
171
211
  with open("<Path to local file>", "rb") as upload_file:
172
- result = client.files.upload_file({
212
+
213
+ payload: UploadLocalFilePayload = {
173
214
  "file": upload_file,
174
- "session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
215
+ "filename": "file-name.jpeg", # optional
216
+ "session_id": "<session-id>",
175
217
  "metadata": {}
176
- })
218
+ }
219
+ result: UploadResponse = client.files.upload_file(payload)
177
220
  print(result)
178
221
  ```
179
222
 
@@ -187,8 +230,7 @@ Data Points are the core of Alfred's platform and represent data that you want t
187
230
  #### Get Data Point by File ID
188
231
 
189
232
  ```python
190
- # Get a data point by file ID
191
- result = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
233
+ result = client.data_points.get_values("<file-id>")
192
234
  print(result)
193
235
  ```
194
236
 
@@ -217,17 +259,23 @@ The `alfred-python` library provides a way to listen to events emitted by Alfred
217
259
  To get started, you need to create an instance of the `AlfredRealTimeClient` class.
218
260
 
219
261
  ```python
220
- from alfred import AlfredRealTimeClient
262
+ from alfred.realtime import AlfredRealTimeClient
221
263
  from alfred.base import Configuration
222
- from alfred import AuthConfiguration
264
+ from alfred.http import AuthConfiguration
223
265
 
224
266
  config = Configuration.default()
225
267
 
226
268
  auth_config = AuthConfiguration({
227
- "api_key": "AXXXXXXXXXXXXXXXXXXXXXX"
269
+ "api_key": "<api-key>"
228
270
  })
229
271
 
230
- client = AlfredRealTimeClient(config, auth_config, verbose=True)
272
+ client = AlfredRealTimeClient(
273
+ config,
274
+ auth_config,
275
+ verbose=False,
276
+ on_callback=None,
277
+ on_connect=None
278
+ )
231
279
  ```
232
280
 
233
281
  ### File Events
@@ -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.5.0"
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
@@ -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