alfred-python 0.4.0__tar.gz → 0.6.0__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 (44) hide show
  1. {alfred_python-0.4.0 → alfred_python-0.6.0}/PKG-INFO +104 -3
  2. {alfred_python-0.4.0 → alfred_python-0.6.0}/README.md +101 -2
  3. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/base/config.py +3 -1
  4. alfred_python-0.6.0/alfred/base/constants.py +94 -0
  5. alfred_python-0.6.0/alfred/exceptions/__init__.py +7 -0
  6. alfred_python-0.6.0/alfred/realtime/__init__.py +132 -0
  7. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/__init__.py +7 -7
  8. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/data_points/v1.py +2 -2
  9. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/files/v1.py +3 -4
  10. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/jobs/base.py +11 -1
  11. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/jobs/v1.py +19 -3
  12. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/sessions/v1.py +2 -2
  13. alfred_python-0.6.0/alfred/typings/__init__.py +1 -0
  14. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/typings/misc.py +2 -2
  15. alfred_python-0.6.0/alfred/utils/__init__.py +1 -0
  16. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/utils/logging.py +1 -1
  17. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred_python.egg-info/PKG-INFO +104 -3
  18. alfred_python-0.6.0/alfred_python.egg-info/SOURCES.txt +37 -0
  19. alfred_python-0.6.0/alfred_python.egg-info/dependency_links.txt +1 -0
  20. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred_python.egg-info/requires.txt +2 -0
  21. {alfred_python-0.4.0 → alfred_python-0.6.0}/pyproject.toml +3 -2
  22. alfred_python-0.4.0/src/alfred/__init__.py +0 -1
  23. alfred_python-0.4.0/src/alfred/base/constants.py +0 -8
  24. alfred_python-0.4.0/src/alfred/typings/__init__.py +0 -1
  25. alfred_python-0.4.0/src/alfred/utils/__init__.py +0 -1
  26. alfred_python-0.4.0/src/alfred_python.egg-info/SOURCES.txt +0 -35
  27. {alfred_python-0.4.0 → alfred_python-0.6.0}/LICENSE +0 -0
  28. /alfred_python-0.4.0/src/alfred_python.egg-info/dependency_links.txt → /alfred_python-0.6.0/alfred/__init__.py +0 -0
  29. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/base/__init__.py +0 -0
  30. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/base/exceptions.py +0 -0
  31. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/http/__init__.py +0 -0
  32. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/http/http_client.py +0 -0
  33. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/http/typed.py +0 -0
  34. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/data_points/__init__.py +0 -0
  35. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/data_points/base.py +0 -0
  36. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/files/__init__.py +0 -0
  37. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/files/base.py +0 -0
  38. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/files/typed.py +0 -0
  39. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/jobs/__init__.py +0 -0
  40. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/jobs/typed.py +0 -0
  41. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/sessions/__init__.py +0 -0
  42. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred/rest/sessions/base.py +0 -0
  43. {alfred_python-0.4.0/src → alfred_python-0.6.0}/alfred_python.egg-info/top_level.txt +0 -0
  44. {alfred_python-0.4.0 → alfred_python-0.6.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: alfred-python
3
- Version: 0.4.0
3
+ Version: 0.6.0
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
@@ -32,6 +32,8 @@ License-File: LICENSE
32
32
  Requires-Dist: pydantic>=2.0
33
33
  Requires-Dist: pydantic-settings>=2.0
34
34
  Requires-Dist: requests>=2.30
35
+ Requires-Dist: python-socketio>=5.11
36
+ Requires-Dist: websocket-client>=1.8
35
37
 
36
38
  # Overview
37
39
 
@@ -47,9 +49,9 @@ Check out this simple example to get up and running:
47
49
 
48
50
  ```python
49
51
  from alfred.rest import AlfredClient
50
- from alfred.base.config import Configuration
52
+ from alfred.base import Configuration
51
53
 
52
- config = Configuration.v1()
54
+ config = Configuration.default()
53
55
  auth_config = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
54
56
 
55
57
  client = AlfredClient(config, auth_config)
@@ -90,6 +92,16 @@ result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
90
92
  print(result)
91
93
  ```
92
94
 
95
+ #### Get paginated jobs
96
+
97
+ ```python
98
+ # Get paginated jobs
99
+ response = client.jobs.get_all(page_size=None, current_page=None)
100
+ print(response.is_empty)
101
+ print(response.result)
102
+ print(response.total)
103
+ ```
104
+
93
105
  #### Create job
94
106
 
95
107
  ```python
@@ -206,6 +218,95 @@ In this SDK, we implement automatic retries to enhance the reliability of networ
206
218
 
207
219
  For non-idempotent methods like POST and PATCH, the SDK does not perform retries by default because doing so could potentially result in unwanted side effects or duplicate operations. If you need to enable retries for these methods under specific circumstances, please handle them cautiously in your application logic.
208
220
 
221
+ ## Real-time Events
222
+
223
+ The `alfred-python` library provides a way to listen to events emitted by Alfred IPA in real-time through a websockets implementation. This feature is particularly useful when you need to monitor the progress of a Job, File, or any other event that occurs within the Alfred platform. To see more information visit our [official documentation](https://docs.tagshelf.dev).
224
+
225
+ ### Getting started
226
+
227
+ To get started, you need to create an instance of the `AlfredRealTimeClient` class.
228
+
229
+ ```python
230
+ from alfred import AlfredRealTimeClient
231
+ from alfred.base import Configuration
232
+ from alfred import AuthConfiguration
233
+
234
+ config = Configuration.default()
235
+
236
+ auth_config = AuthConfiguration({
237
+ "api_key": "AXXXXXXXXXXXXXXXXXXXXXX"
238
+ })
239
+
240
+ client = AlfredRealTimeClient(
241
+ config,
242
+ auth_config,
243
+ verbose=False,
244
+ on_callback=None,
245
+ on_connect=None
246
+ )
247
+ ```
248
+
249
+ ### File Events
250
+ These events are specifically designed to respond to a variety of actions or status changes related to Files. To see more details about File events, visit our [official documentation](https://docs.tagshelf.dev/event-api/fileevents).
251
+ ```python
252
+ # Listen to all File events
253
+ client.on_file_event(lambda data: print(data))
254
+ ```
255
+
256
+ ### Job Events
257
+ Alfred performs asynchronous document classification, extraction, and indexing on a variety of file types. The events detailed here offer insights into how a Job progresses, fails, retries, or completes its tasks. To see more details about Job events, visit our [official documentation](https://docs.tagshelf.dev/event-api/jobevents).
258
+
259
+ ```python
260
+ # Listen to all Job events
261
+ client.on_job_event(lambda data: print(data))
262
+ ```
263
+
264
+ ### Specific Events
265
+
266
+ This enables you to select a specific event you wish to monitor from the list of supported events.
267
+ It's particularly useful when you want to listen to a specific event instead of all events of a particular type.
268
+
269
+ Here's an example of how to listen to a specific event:
270
+
271
+ ```python
272
+ from alfred.base import FileEvent, JobEvent
273
+
274
+ # Listen to the specific File Done event
275
+ client.on(FileEvent.FILE_DONE_EVENT.value, lambda data: print(data))
276
+
277
+ # Listen to the specific Job Finished event
278
+ client.on(JobEvent.JOB_FINISHED_EVENT.value, lambda data: print(data))
279
+ ```
280
+
281
+ Here is a list of all supported events:
282
+
283
+ | Event Type | Event Name | Description |
284
+ | --- | --- | --- |
285
+ | FileEvent | `FILE_ADD_TO_JOB_EVENT` | Triggered when a file is added to a job for processing. |
286
+ | FileEvent | `FILE_CATEGORY_CREATE_EVENT` | Occurs when a new category is created for a file. |
287
+ | FileEvent | `FILE_CATEGORY_DELETE_EVENT` | Signals the deletion of a file's category. |
288
+ | FileEvent | `FILE_CHANGE_TAG_EVENT` | Indicates a change in the tag associated with a file. |
289
+ | FileEvent | `FILE_DONE_EVENT` | Marks the completion of file processing. |
290
+ | FileEvent | `FILE_EXTRACTED_DATA_CREATE_EVENT` | Triggered when new data is extracted from a file. |
291
+ | FileEvent | `FILE_EXTRACTED_DATA_DELETE_EVENT` | Occurs when extracted data from a file is deleted. |
292
+ | FileEvent | `FILE_FAILED_EVENT` | Indicates a failure in file processing. |
293
+ | FileEvent | `FILE_MOVE_EVENT` | Signals the movement of a file within the system. |
294
+ | FileEvent | `FILE_MOVE_TO_PENDING_EVENT` | Triggered when a file is moved to a pending state. |
295
+ | FileEvent | `FILE_MOVE_TO_RECYCLE_BIN_EVENT` | Indicates movement of a file to the recycle bin. |
296
+ | FileEvent | `FILE_PROPERTY_CREATE_EVENT` | Reflects the creation of a file property. |
297
+ | FileEvent | `FILE_PROPERTY_DELETE_EVENT` | Signals the deletion of a file property. |
298
+ | FileEvent | `FILE_REMOVE_TAG_EVENT` | Signals the removal of a tag from a file. |
299
+ | FileEvent | `FILE_STATUS_UPDATE_EVENT` | Indicates an update in the file's status. |
300
+ | FileEvent | `FILE_UPDATE_EVENT` | Triggered when a file is updated in any manner. |
301
+ | JobEvent | `JOB_CREATE_EVENT` | Triggered when a new job is instantiated for file operations. |
302
+ | JobEvent | `JOB_EXCEEDED_RETRIES_EVENT` | Fires when job exceeds maximum retry attempts for a stage. |
303
+ | JobEvent | `JOB_FAILED_EVENT` | Occurs when a job halts due to an unrecoverable error. |
304
+ | JobEvent | `JOB_FINISHED_EVENT` | Triggered when job successfully completes all workflow stages. |
305
+ | JobEvent | `JOB_INVALID_EVENT` | Fires when job fails initial validation of input files or parameters. |
306
+ | JobEvent | `JOB_RETRY_EVENT` | Triggered when job retries a stage after a recoverable failure. |
307
+ | JobEvent | `JOB_STAGE_UPDATE_EVENT` | Occurs when job transitions from one workflow stage to another. |
308
+ | JobEvent | `JOB_START_EVENT` | Triggered when job begins its workflow and state machine. |
309
+
209
310
  ## Development Setup
210
311
 
211
312
  ### Setting up the development environment
@@ -12,9 +12,9 @@ Check out this simple example to get up and running:
12
12
 
13
13
  ```python
14
14
  from alfred.rest import AlfredClient
15
- from alfred.base.config import Configuration
15
+ from alfred.base import Configuration
16
16
 
17
- config = Configuration.v1()
17
+ config = Configuration.default()
18
18
  auth_config = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
19
19
 
20
20
  client = AlfredClient(config, auth_config)
@@ -55,6 +55,16 @@ result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
55
55
  print(result)
56
56
  ```
57
57
 
58
+ #### Get paginated jobs
59
+
60
+ ```python
61
+ # Get paginated jobs
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
@@ -171,6 +181,95 @@ In this SDK, we implement automatic retries to enhance the reliability of networ
171
181
 
172
182
  For non-idempotent methods like POST and PATCH, the SDK does not perform retries by default because doing so could potentially result in unwanted side effects or duplicate operations. If you need to enable retries for these methods under specific circumstances, please handle them cautiously in your application logic.
173
183
 
184
+ ## Real-time Events
185
+
186
+ The `alfred-python` library provides a way to listen to events emitted by Alfred IPA in real-time through a websockets implementation. This feature is particularly useful when you need to monitor the progress of a Job, File, or any other event that occurs within the Alfred platform. To see more information visit our [official documentation](https://docs.tagshelf.dev).
187
+
188
+ ### Getting started
189
+
190
+ To get started, you need to create an instance of the `AlfredRealTimeClient` class.
191
+
192
+ ```python
193
+ from alfred import AlfredRealTimeClient
194
+ from alfred.base import Configuration
195
+ from alfred import AuthConfiguration
196
+
197
+ config = Configuration.default()
198
+
199
+ auth_config = AuthConfiguration({
200
+ "api_key": "AXXXXXXXXXXXXXXXXXXXXXX"
201
+ })
202
+
203
+ client = AlfredRealTimeClient(
204
+ config,
205
+ auth_config,
206
+ verbose=False,
207
+ on_callback=None,
208
+ on_connect=None
209
+ )
210
+ ```
211
+
212
+ ### File Events
213
+ These events are specifically designed to respond to a variety of actions or status changes related to Files. To see more details about File events, visit our [official documentation](https://docs.tagshelf.dev/event-api/fileevents).
214
+ ```python
215
+ # Listen to all File events
216
+ client.on_file_event(lambda data: print(data))
217
+ ```
218
+
219
+ ### Job Events
220
+ Alfred performs asynchronous document classification, extraction, and indexing on a variety of file types. The events detailed here offer insights into how a Job progresses, fails, retries, or completes its tasks. To see more details about Job events, visit our [official documentation](https://docs.tagshelf.dev/event-api/jobevents).
221
+
222
+ ```python
223
+ # Listen to all Job events
224
+ client.on_job_event(lambda data: print(data))
225
+ ```
226
+
227
+ ### Specific Events
228
+
229
+ This enables you to select a specific event you wish to monitor from the list of supported events.
230
+ It's particularly useful when you want to listen to a specific event instead of all events of a particular type.
231
+
232
+ Here's an example of how to listen to a specific event:
233
+
234
+ ```python
235
+ from alfred.base import FileEvent, JobEvent
236
+
237
+ # Listen to the specific File Done event
238
+ client.on(FileEvent.FILE_DONE_EVENT.value, lambda data: print(data))
239
+
240
+ # Listen to the specific Job Finished event
241
+ client.on(JobEvent.JOB_FINISHED_EVENT.value, lambda data: print(data))
242
+ ```
243
+
244
+ Here is a list of all supported events:
245
+
246
+ | Event Type | Event Name | Description |
247
+ | --- | --- | --- |
248
+ | FileEvent | `FILE_ADD_TO_JOB_EVENT` | Triggered when a file is added to a job for processing. |
249
+ | FileEvent | `FILE_CATEGORY_CREATE_EVENT` | Occurs when a new category is created for a file. |
250
+ | FileEvent | `FILE_CATEGORY_DELETE_EVENT` | Signals the deletion of a file's category. |
251
+ | FileEvent | `FILE_CHANGE_TAG_EVENT` | Indicates a change in the tag associated with a file. |
252
+ | FileEvent | `FILE_DONE_EVENT` | Marks the completion of file processing. |
253
+ | FileEvent | `FILE_EXTRACTED_DATA_CREATE_EVENT` | Triggered when new data is extracted from a file. |
254
+ | FileEvent | `FILE_EXTRACTED_DATA_DELETE_EVENT` | Occurs when extracted data from a file is deleted. |
255
+ | FileEvent | `FILE_FAILED_EVENT` | Indicates a failure in file processing. |
256
+ | FileEvent | `FILE_MOVE_EVENT` | Signals the movement of a file within the system. |
257
+ | FileEvent | `FILE_MOVE_TO_PENDING_EVENT` | Triggered when a file is moved to a pending state. |
258
+ | FileEvent | `FILE_MOVE_TO_RECYCLE_BIN_EVENT` | Indicates movement of a file to the recycle bin. |
259
+ | FileEvent | `FILE_PROPERTY_CREATE_EVENT` | Reflects the creation of a file property. |
260
+ | FileEvent | `FILE_PROPERTY_DELETE_EVENT` | Signals the deletion of a file property. |
261
+ | FileEvent | `FILE_REMOVE_TAG_EVENT` | Signals the removal of a tag from a file. |
262
+ | FileEvent | `FILE_STATUS_UPDATE_EVENT` | Indicates an update in the file's status. |
263
+ | FileEvent | `FILE_UPDATE_EVENT` | Triggered when a file is updated in any manner. |
264
+ | JobEvent | `JOB_CREATE_EVENT` | Triggered when a new job is instantiated for file operations. |
265
+ | JobEvent | `JOB_EXCEEDED_RETRIES_EVENT` | Fires when job exceeds maximum retry attempts for a stage. |
266
+ | JobEvent | `JOB_FAILED_EVENT` | Occurs when a job halts due to an unrecoverable error. |
267
+ | JobEvent | `JOB_FINISHED_EVENT` | Triggered when job successfully completes all workflow stages. |
268
+ | JobEvent | `JOB_INVALID_EVENT` | Fires when job fails initial validation of input files or parameters. |
269
+ | JobEvent | `JOB_RETRY_EVENT` | Triggered when job retries a stage after a recoverable failure. |
270
+ | JobEvent | `JOB_STAGE_UPDATE_EVENT` | Occurs when job transitions from one workflow stage to another. |
271
+ | JobEvent | `JOB_START_EVENT` | Triggered when job begins its workflow and state machine. |
272
+
174
273
  ## Development Setup
175
274
 
176
275
  ### Setting up the development environment
@@ -4,6 +4,7 @@ from typing import TypedDict, Optional, Text
4
4
 
5
5
  class ConfigurationDict(TypedDict):
6
6
  base_url: Text
7
+ realtime_url: Text
7
8
  version: int
8
9
 
9
10
 
@@ -15,7 +16,7 @@ class Configuration:
15
16
  @staticmethod
16
17
  def default() -> ConfigurationDict:
17
18
  """
18
- Returns default client configuration. Currently targets Alfred V1.
19
+ Returns default client configuration. Currently, targets Alfred V1.
19
20
  """
20
21
  return Configuration.v1()
21
22
 
@@ -28,4 +29,5 @@ class Configuration:
28
29
  return {
29
30
  "version": 1,
30
31
  "base_url": overrides.get("base_url", "https://app.tagshelf.com"),
32
+ "realtime_url": overrides.get("realtime_url", "https://sockets.tagshelf.io"),
31
33
  }
@@ -0,0 +1,94 @@
1
+ from enum import Enum
2
+
3
+ from alfred.http.typed import ResponseType
4
+
5
+ # Response type/header mapping
6
+ RESPONSE_TYPE_HEADER_MAPPING = {
7
+ ResponseType.JSON: "application/json",
8
+ ResponseType.TEXT: "text/plain",
9
+ ResponseType.XML: "application/xml",
10
+ }
11
+
12
+
13
+ class EventType(Enum):
14
+ """
15
+ Enumeration of event types.
16
+ """
17
+ JOB_EVENT = "job_event"
18
+ FILE_EVENT = "file_event"
19
+
20
+
21
+ class FileEvent(Enum):
22
+ # Triggered when a file is added to a job for processing.
23
+ FILE_ADD_TO_JOB_EVENT = "file_add_to_job_event"
24
+
25
+ # Occurs when a new category is created for a file.
26
+ FILE_CATEGORY_CREATE_EVENT = "file_category_create_event"
27
+
28
+ # Signals the deletion of a file's category.
29
+ FILE_CATEGORY_DELETE_EVENT = "file_category_delete_event"
30
+
31
+ # Indicates a change in the tag associated with a file.
32
+ FILE_CHANGE_TAG_EVENT = "file_change_tag_event"
33
+
34
+ # Marks the completion of file processing.
35
+ FILE_DONE_EVENT = "file_done_event"
36
+
37
+ # Triggered when new data is extracted from a file.
38
+ FILE_EXTRACTED_DATA_CREATE_EVENT = "file_extracted_data_create_event"
39
+
40
+ # Occurs when extracted data from a file is deleted.
41
+ FILE_EXTRACTED_DATA_DELETE_EVENT = "file_extracted_data_delete_event"
42
+
43
+ # Indicates a failure in file processing.
44
+ FILE_FAILED_EVENT = "file_failed_event"
45
+
46
+ # Signals the movement of a file within the system.
47
+ FILE_MOVE_EVENT = "file_move_event"
48
+
49
+ # Triggered when a file is moved to a pending state.
50
+ FILE_MOVE_TO_PENDING_EVENT = "file_move_to_pending_event"
51
+
52
+ # Indicates movement of a file to the recycle bin.
53
+ FILE_MOVE_TO_RECYCLE_BIN_EVENT = "file_move_to_recycle_bin_event"
54
+
55
+ # Reflects the creation of a file property.
56
+ FILE_PROPERTY_CREATE_EVENT = "file_property_create_event"
57
+
58
+ # Signals the deletion of a file property.
59
+ FILE_PROPERTY_DELETE_EVENT = "file_property_delete_event"
60
+
61
+ # Signals the removal of a tag from a file.
62
+ FILE_REMOVE_TAG_EVENT = "file_remove_tag_event"
63
+
64
+ # Indicates an update in the file's status.
65
+ FILE_STATUS_UPDATE_EVENT = "file_status_update_event"
66
+
67
+ # Triggered when a file is updated in any manner.
68
+ FILE_UPDATE_EVENT = "file_update_event"
69
+
70
+
71
+ class JobEvent(Enum):
72
+ # Triggered when a new job is instantiated for file operations.
73
+ JOB_CREATE_EVENT = "job_create_event"
74
+
75
+ # Fires when job exceeds maximum retry attempts for a stage.
76
+ JOB_EXCEEDED_RETRIES_EVENT = "job_exceeded_retries_event"
77
+
78
+ # Occurs when a job halts due to an unrecoverable error.
79
+ JOB_FAILED_EVENT = "job_failed_event"
80
+
81
+ # Triggered when job successfully completes all workflow stages.
82
+ JOB_FINISHED_EVENT = "job_finished_event"
83
+
84
+ # Fires when job fails initial validation of input files or parameters.
85
+ JOB_INVALID_EVENT = "job_invalid_event"
86
+
87
+ # Triggered when job retries a stage after a recoverable failure.
88
+ JOB_RETRY_EVENT = "job_retry_event"
89
+
90
+ # Occurs when job transitions from one workflow stage to another.
91
+ JOB_STAGE_UPDATE_EVENT = "job_stage_update_event"
92
+
93
+ # Triggered when job begins its workflow and state machine.
94
+ JOB_START_EVENT = "job_start_event"
@@ -0,0 +1,7 @@
1
+ class ConnectionError(Exception):
2
+ """
3
+ Raised when a connection error occurs.
4
+ """
5
+ def __init__(self, message="A connection error occurred"):
6
+ self.message = message
7
+ super().__init__(self.message)
@@ -0,0 +1,132 @@
1
+ # Native Imports
2
+ from typing import Union
3
+
4
+ # 3rd Party Imports
5
+ import socketio
6
+
7
+ # Project Imports
8
+ import alfred.exceptions
9
+ from alfred.base.config import ConfigurationDict
10
+ from alfred.base.constants import EventType, FileEvent, JobEvent
11
+ from alfred.http.typed import AuthConfiguration
12
+ from alfred.utils import logging, setup_logger
13
+
14
+
15
+ class AlfredRealTimeClient:
16
+ def __init__(self, config: ConfigurationDict, auth_config: AuthConfiguration, verbose=False, error_callback=None, on_connect=None):
17
+ """
18
+ Initializes the AlfredRealTimeClient class.
19
+
20
+ Args:
21
+ config (ConfigurationDict): The configuration dictionary.
22
+ auth_config (AuthConfiguration): The authentication configuration.
23
+ verbose (bool, optional): Whether to print verbose output. Defaults to False.
24
+ """
25
+ self.socket = socketio.Client()
26
+ self.verbose = verbose
27
+ self.config = config
28
+ self.auth_config = auth_config
29
+ self.base_url = config.get("realtime_url")
30
+ self.error_callback = error_callback
31
+ self.on_connect = on_connect
32
+
33
+ # Initialize logger
34
+ self.logger = logging.getLogger("alfred-python")
35
+ if self.logger.level == logging.NOTSET:
36
+ setup_logger({
37
+ "level": "DEBUG" if verbose else "INFO",
38
+ "name": "alfred-python"
39
+ })
40
+
41
+ # Subscribe to connection life-cycle events.
42
+ self.socket.on('connect', self.__on_connect)
43
+ self.socket.on('disconnect', self.__on_disconnect)
44
+ self.socket.on('connect_error', self.__on_connect_error)
45
+
46
+ # Establish connection with verbose output if enabled
47
+ if self.verbose:
48
+ self.logger.debug("Attempting to establish a connection...")
49
+ try:
50
+ self.socket.connect(f"{self.base_url}?apiKey={auth_config.get('api_key')}")
51
+ except Exception as err:
52
+ raise alfred.exceptions.ConnectionError(f"Could not establish connection with server: {err}")
53
+
54
+ def __on_connect(self):
55
+ """
56
+ Handles the 'connect' event.
57
+ """
58
+ self.logger.info(f"Successfully connected to: {self.base_url}")
59
+ if self.on_connect:
60
+ self.on_connect()
61
+
62
+ def __on_disconnect(self):
63
+ """
64
+ Handles the 'disconnect' event.
65
+ """
66
+ if self.verbose:
67
+ self.logger.info("Disconnected from the server.")
68
+
69
+ def __on_connect_error(self, err):
70
+ """
71
+ Handles the 'connect_error' event.
72
+
73
+ Args:
74
+ err (str): The error message.
75
+ """
76
+ if self.verbose:
77
+ self.logger.error("Connection error: %s", err)
78
+ self.disconnect()
79
+ # trigger error callback:
80
+ if self.error_callback:
81
+ self.error_callback(err)
82
+
83
+ def __callback(self, event: Union[FileEvent, JobEvent, EventType], callback):
84
+ """
85
+ Wrapper function to subscribe a specific event.
86
+
87
+ Args:
88
+ event (str): The event name.
89
+ callback (function): The callback function to handle the event.
90
+ """
91
+ def handle_event(data):
92
+ if self.verbose:
93
+ self.logger.debug(f"Event {event} received: %s", data)
94
+ callback(data)
95
+
96
+ self.socket.on(event, handle_event)
97
+
98
+ def on_file_event(self, callback):
99
+ """
100
+ Listens to all file-related events.
101
+
102
+ Args:
103
+ callback (function): The callback function to handle the event.
104
+ """
105
+ self.__callback(EventType.FILE_EVENT.value, callback)
106
+
107
+ def on_job_event(self, callback):
108
+ """
109
+ Listens to all job-related events.
110
+
111
+ Args:
112
+ callback (function): The callback function to handle the event.
113
+ """
114
+ self.__callback(EventType.JOB_EVENT.value, callback)
115
+
116
+ def on(self, event: Union[FileEvent, JobEvent], callback):
117
+ """
118
+ Listens to a specific event.
119
+
120
+ Args:
121
+ event (str): The event name.
122
+ callback (function): The callback function to handle the event.
123
+ """
124
+ self.__callback(event, callback)
125
+
126
+ def disconnect(self):
127
+ """
128
+ Disconnects client from the server.
129
+ """
130
+ self.logger.info("Closing connection...")
131
+ self.socket.disconnect()
132
+
@@ -2,13 +2,13 @@
2
2
  from typing import Optional
3
3
 
4
4
  # Project imports
5
- from src.alfred.base.config import ConfigurationDict
6
- from src.alfred.http.http_client import HttpClient
7
- from src.alfred.http.typed import AuthConfiguration, HttpConfiguration
8
- from src.alfred.rest.data_points import DataPointsBase, DataPointsFactory
9
- from src.alfred.rest.sessions import SessionsBase, SessionsFactory
10
- from src.alfred.rest.jobs import JobsBase, JobsFactory
11
- from src.alfred.rest.files import FilesBase, FilesFactory
5
+ from alfred.base.config import ConfigurationDict
6
+ from alfred.http.http_client import HttpClient
7
+ from alfred.http.typed import AuthConfiguration, HttpConfiguration
8
+ from alfred.rest.data_points import DataPointsBase, DataPointsFactory
9
+ from alfred.rest.sessions import SessionsBase, SessionsFactory
10
+ from alfred.rest.jobs import JobsBase, JobsFactory
11
+ from alfred.rest.files import FilesBase, FilesFactory
12
12
 
13
13
 
14
14
  class AlfredClient:
@@ -2,8 +2,8 @@
2
2
  from typing import Text
3
3
 
4
4
  # Project imports
5
- from src.alfred.http.http_client import HttpClient
6
- from src.alfred.rest.data_points.base import DataPointsBase
5
+ from alfred.http.http_client import HttpClient
6
+ from alfred.rest.data_points.base import DataPointsBase
7
7
 
8
8
 
9
9
  class DataPoints(DataPointsBase):
@@ -2,13 +2,12 @@
2
2
  import os
3
3
  import json
4
4
  from typing import Text
5
- from io import BufferedReader
6
5
  from urllib.parse import unquote
7
6
 
8
7
  # Project imports
9
- from src.alfred.rest.files.typed import * # pylint: disable=W0401, W0614
10
- from src.alfred.http.http_client import HttpClient
11
- from src.alfred.base.exceptions import AlfredMissingArgument
8
+ from alfred.rest.files.typed import * # pylint: disable=W0401, W0614
9
+ from alfred.http.http_client import HttpClient
10
+ from alfred.base.exceptions import AlfredMissingArgument
12
11
  from .base import FilesBase
13
12
  from .typed import FileDetailsResponse
14
13
 
@@ -1,6 +1,6 @@
1
1
  # Native imports
2
2
  from typing import Text, Any
3
- from src.alfred.rest.jobs.typed import CreateJobDict
3
+ from alfred.rest.jobs.typed import CreateJobDict
4
4
  from abc import ABC, abstractmethod
5
5
 
6
6
 
@@ -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
+ """
@@ -2,9 +2,9 @@
2
2
  from typing import Text
3
3
 
4
4
  # Project imports
5
- from src.alfred.rest.jobs.typed import CreateJobDict
6
- from src.alfred.http.http_client import HttpClient
7
- from src.alfred.rest.jobs.base import JobsBase
5
+ from alfred.rest.jobs.typed import CreateJobDict
6
+ from alfred.http.http_client import HttpClient
7
+ from alfred.rest.jobs.base import JobsBase
8
8
 
9
9
 
10
10
  class Jobs(JobsBase):
@@ -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
@@ -2,8 +2,8 @@
2
2
  from typing import Text
3
3
 
4
4
  # Project imports
5
- from src.alfred.http.http_client import HttpClient
6
- from src.alfred.rest.sessions.base import SessionsBase
5
+ from alfred.http.http_client import HttpClient
6
+ from alfred.rest.sessions.base import SessionsBase
7
7
 
8
8
 
9
9
  class Sessions(SessionsBase):
@@ -0,0 +1 @@
1
+ from alfred.typings.misc import *
@@ -1,10 +1,10 @@
1
1
  # Native imports
2
- from typing import TypedDict
2
+ from typing import TypedDict, Union
3
3
 
4
4
 
5
5
  # Typed dictionaries
6
6
  class LoggingOptions(TypedDict):
7
- level: int
7
+ level: Union[str, int]
8
8
  name: str
9
9
  format: str
10
10
  papertrail_host: str
@@ -0,0 +1 @@
1
+ from alfred.utils.logging import *
@@ -6,7 +6,7 @@ from logging.handlers import SysLogHandler
6
6
  from typing import Union
7
7
 
8
8
  # Project imports
9
- from src.alfred.typings import LoggingOptions
9
+ from alfred.typings import LoggingOptions
10
10
 
11
11
 
12
12
  def setup_logger(options: LoggingOptions):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: alfred-python
3
- Version: 0.4.0
3
+ Version: 0.6.0
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
@@ -32,6 +32,8 @@ License-File: LICENSE
32
32
  Requires-Dist: pydantic>=2.0
33
33
  Requires-Dist: pydantic-settings>=2.0
34
34
  Requires-Dist: requests>=2.30
35
+ Requires-Dist: python-socketio>=5.11
36
+ Requires-Dist: websocket-client>=1.8
35
37
 
36
38
  # Overview
37
39
 
@@ -47,9 +49,9 @@ Check out this simple example to get up and running:
47
49
 
48
50
  ```python
49
51
  from alfred.rest import AlfredClient
50
- from alfred.base.config import Configuration
52
+ from alfred.base import Configuration
51
53
 
52
- config = Configuration.v1()
54
+ config = Configuration.default()
53
55
  auth_config = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
54
56
 
55
57
  client = AlfredClient(config, auth_config)
@@ -90,6 +92,16 @@ result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
90
92
  print(result)
91
93
  ```
92
94
 
95
+ #### Get paginated jobs
96
+
97
+ ```python
98
+ # Get paginated jobs
99
+ response = client.jobs.get_all(page_size=None, current_page=None)
100
+ print(response.is_empty)
101
+ print(response.result)
102
+ print(response.total)
103
+ ```
104
+
93
105
  #### Create job
94
106
 
95
107
  ```python
@@ -206,6 +218,95 @@ In this SDK, we implement automatic retries to enhance the reliability of networ
206
218
 
207
219
  For non-idempotent methods like POST and PATCH, the SDK does not perform retries by default because doing so could potentially result in unwanted side effects or duplicate operations. If you need to enable retries for these methods under specific circumstances, please handle them cautiously in your application logic.
208
220
 
221
+ ## Real-time Events
222
+
223
+ The `alfred-python` library provides a way to listen to events emitted by Alfred IPA in real-time through a websockets implementation. This feature is particularly useful when you need to monitor the progress of a Job, File, or any other event that occurs within the Alfred platform. To see more information visit our [official documentation](https://docs.tagshelf.dev).
224
+
225
+ ### Getting started
226
+
227
+ To get started, you need to create an instance of the `AlfredRealTimeClient` class.
228
+
229
+ ```python
230
+ from alfred import AlfredRealTimeClient
231
+ from alfred.base import Configuration
232
+ from alfred import AuthConfiguration
233
+
234
+ config = Configuration.default()
235
+
236
+ auth_config = AuthConfiguration({
237
+ "api_key": "AXXXXXXXXXXXXXXXXXXXXXX"
238
+ })
239
+
240
+ client = AlfredRealTimeClient(
241
+ config,
242
+ auth_config,
243
+ verbose=False,
244
+ on_callback=None,
245
+ on_connect=None
246
+ )
247
+ ```
248
+
249
+ ### File Events
250
+ These events are specifically designed to respond to a variety of actions or status changes related to Files. To see more details about File events, visit our [official documentation](https://docs.tagshelf.dev/event-api/fileevents).
251
+ ```python
252
+ # Listen to all File events
253
+ client.on_file_event(lambda data: print(data))
254
+ ```
255
+
256
+ ### Job Events
257
+ Alfred performs asynchronous document classification, extraction, and indexing on a variety of file types. The events detailed here offer insights into how a Job progresses, fails, retries, or completes its tasks. To see more details about Job events, visit our [official documentation](https://docs.tagshelf.dev/event-api/jobevents).
258
+
259
+ ```python
260
+ # Listen to all Job events
261
+ client.on_job_event(lambda data: print(data))
262
+ ```
263
+
264
+ ### Specific Events
265
+
266
+ This enables you to select a specific event you wish to monitor from the list of supported events.
267
+ It's particularly useful when you want to listen to a specific event instead of all events of a particular type.
268
+
269
+ Here's an example of how to listen to a specific event:
270
+
271
+ ```python
272
+ from alfred.base import FileEvent, JobEvent
273
+
274
+ # Listen to the specific File Done event
275
+ client.on(FileEvent.FILE_DONE_EVENT.value, lambda data: print(data))
276
+
277
+ # Listen to the specific Job Finished event
278
+ client.on(JobEvent.JOB_FINISHED_EVENT.value, lambda data: print(data))
279
+ ```
280
+
281
+ Here is a list of all supported events:
282
+
283
+ | Event Type | Event Name | Description |
284
+ | --- | --- | --- |
285
+ | FileEvent | `FILE_ADD_TO_JOB_EVENT` | Triggered when a file is added to a job for processing. |
286
+ | FileEvent | `FILE_CATEGORY_CREATE_EVENT` | Occurs when a new category is created for a file. |
287
+ | FileEvent | `FILE_CATEGORY_DELETE_EVENT` | Signals the deletion of a file's category. |
288
+ | FileEvent | `FILE_CHANGE_TAG_EVENT` | Indicates a change in the tag associated with a file. |
289
+ | FileEvent | `FILE_DONE_EVENT` | Marks the completion of file processing. |
290
+ | FileEvent | `FILE_EXTRACTED_DATA_CREATE_EVENT` | Triggered when new data is extracted from a file. |
291
+ | FileEvent | `FILE_EXTRACTED_DATA_DELETE_EVENT` | Occurs when extracted data from a file is deleted. |
292
+ | FileEvent | `FILE_FAILED_EVENT` | Indicates a failure in file processing. |
293
+ | FileEvent | `FILE_MOVE_EVENT` | Signals the movement of a file within the system. |
294
+ | FileEvent | `FILE_MOVE_TO_PENDING_EVENT` | Triggered when a file is moved to a pending state. |
295
+ | FileEvent | `FILE_MOVE_TO_RECYCLE_BIN_EVENT` | Indicates movement of a file to the recycle bin. |
296
+ | FileEvent | `FILE_PROPERTY_CREATE_EVENT` | Reflects the creation of a file property. |
297
+ | FileEvent | `FILE_PROPERTY_DELETE_EVENT` | Signals the deletion of a file property. |
298
+ | FileEvent | `FILE_REMOVE_TAG_EVENT` | Signals the removal of a tag from a file. |
299
+ | FileEvent | `FILE_STATUS_UPDATE_EVENT` | Indicates an update in the file's status. |
300
+ | FileEvent | `FILE_UPDATE_EVENT` | Triggered when a file is updated in any manner. |
301
+ | JobEvent | `JOB_CREATE_EVENT` | Triggered when a new job is instantiated for file operations. |
302
+ | JobEvent | `JOB_EXCEEDED_RETRIES_EVENT` | Fires when job exceeds maximum retry attempts for a stage. |
303
+ | JobEvent | `JOB_FAILED_EVENT` | Occurs when a job halts due to an unrecoverable error. |
304
+ | JobEvent | `JOB_FINISHED_EVENT` | Triggered when job successfully completes all workflow stages. |
305
+ | JobEvent | `JOB_INVALID_EVENT` | Fires when job fails initial validation of input files or parameters. |
306
+ | JobEvent | `JOB_RETRY_EVENT` | Triggered when job retries a stage after a recoverable failure. |
307
+ | JobEvent | `JOB_STAGE_UPDATE_EVENT` | Occurs when job transitions from one workflow stage to another. |
308
+ | JobEvent | `JOB_START_EVENT` | Triggered when job begins its workflow and state machine. |
309
+
209
310
  ## Development Setup
210
311
 
211
312
  ### Setting up the development environment
@@ -0,0 +1,37 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ alfred/__init__.py
5
+ alfred/base/__init__.py
6
+ alfred/base/config.py
7
+ alfred/base/constants.py
8
+ alfred/base/exceptions.py
9
+ alfred/exceptions/__init__.py
10
+ alfred/http/__init__.py
11
+ alfred/http/http_client.py
12
+ alfred/http/typed.py
13
+ alfred/realtime/__init__.py
14
+ alfred/rest/__init__.py
15
+ alfred/rest/data_points/__init__.py
16
+ alfred/rest/data_points/base.py
17
+ alfred/rest/data_points/v1.py
18
+ alfred/rest/files/__init__.py
19
+ alfred/rest/files/base.py
20
+ alfred/rest/files/typed.py
21
+ alfred/rest/files/v1.py
22
+ alfred/rest/jobs/__init__.py
23
+ alfred/rest/jobs/base.py
24
+ alfred/rest/jobs/typed.py
25
+ alfred/rest/jobs/v1.py
26
+ alfred/rest/sessions/__init__.py
27
+ alfred/rest/sessions/base.py
28
+ alfred/rest/sessions/v1.py
29
+ alfred/typings/__init__.py
30
+ alfred/typings/misc.py
31
+ alfred/utils/__init__.py
32
+ alfred/utils/logging.py
33
+ alfred_python.egg-info/PKG-INFO
34
+ alfred_python.egg-info/SOURCES.txt
35
+ alfred_python.egg-info/dependency_links.txt
36
+ alfred_python.egg-info/requires.txt
37
+ alfred_python.egg-info/top_level.txt
@@ -1,3 +1,5 @@
1
1
  pydantic>=2.0
2
2
  pydantic-settings>=2.0
3
3
  requests>=2.30
4
+ python-socketio>=5.11
5
+ websocket-client>=1.8
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "alfred-python"
7
- version = "0.4.0"
7
+ version = "0.6.0"
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"
@@ -19,11 +19,12 @@ dependencies = [
19
19
  "pydantic >= 2.0",
20
20
  "pydantic-settings >= 2.0",
21
21
  "requests >= 2.30",
22
+ "python-socketio >= 5.11",
23
+ "websocket-client >= 1.8"
22
24
  ]
23
25
 
24
26
  [project.urls]
25
27
  homepage = "https://github.com/tagshelfsrl/alfred-python"
26
28
 
27
29
  [tool.setuptools.packages.find]
28
- where = ["src"]
29
30
  include = ["alfred", "alfred.*"]
@@ -1 +0,0 @@
1
- __version__ = "0.0.1"
@@ -1,8 +0,0 @@
1
- from src.alfred.http.typed import ResponseType
2
-
3
- # Response type/header mapping
4
- RESPONSE_TYPE_HEADER_MAPPING = {
5
- ResponseType.JSON: "application/json",
6
- ResponseType.TEXT: "text/plain",
7
- ResponseType.XML: "application/xml",
8
- }
@@ -1 +0,0 @@
1
- from src.alfred.typings.misc import *
@@ -1 +0,0 @@
1
- from src.alfred.utils.logging import *
@@ -1,35 +0,0 @@
1
- LICENSE
2
- README.md
3
- pyproject.toml
4
- src/alfred/__init__.py
5
- src/alfred/base/__init__.py
6
- src/alfred/base/config.py
7
- src/alfred/base/constants.py
8
- src/alfred/base/exceptions.py
9
- src/alfred/http/__init__.py
10
- src/alfred/http/http_client.py
11
- src/alfred/http/typed.py
12
- src/alfred/rest/__init__.py
13
- src/alfred/rest/data_points/__init__.py
14
- src/alfred/rest/data_points/base.py
15
- src/alfred/rest/data_points/v1.py
16
- src/alfred/rest/files/__init__.py
17
- src/alfred/rest/files/base.py
18
- src/alfred/rest/files/typed.py
19
- src/alfred/rest/files/v1.py
20
- src/alfred/rest/jobs/__init__.py
21
- src/alfred/rest/jobs/base.py
22
- src/alfred/rest/jobs/typed.py
23
- src/alfred/rest/jobs/v1.py
24
- src/alfred/rest/sessions/__init__.py
25
- src/alfred/rest/sessions/base.py
26
- src/alfred/rest/sessions/v1.py
27
- src/alfred/typings/__init__.py
28
- src/alfred/typings/misc.py
29
- src/alfred/utils/__init__.py
30
- src/alfred/utils/logging.py
31
- src/alfred_python.egg-info/PKG-INFO
32
- src/alfred_python.egg-info/SOURCES.txt
33
- src/alfred_python.egg-info/dependency_links.txt
34
- src/alfred_python.egg-info/requires.txt
35
- src/alfred_python.egg-info/top_level.txt
File without changes
File without changes