alfred-python 0.0.1__tar.gz → 0.4.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.
- alfred_python-0.4.0/PKG-INFO +283 -0
- alfred_python-0.4.0/README.md +248 -0
- alfred_python-0.4.0/pyproject.toml +29 -0
- alfred_python-0.4.0/src/alfred/__init__.py +1 -0
- alfred_python-0.4.0/src/alfred/base/__init__.py +0 -0
- alfred_python-0.4.0/src/alfred/base/config.py +31 -0
- alfred_python-0.4.0/src/alfred/base/constants.py +8 -0
- alfred_python-0.4.0/src/alfred/base/exceptions.py +11 -0
- alfred_python-0.4.0/src/alfred/http/__init__.py +0 -0
- alfred_python-0.4.0/src/alfred/http/http_client.py +520 -0
- alfred_python-0.4.0/src/alfred/http/typed.py +49 -0
- alfred_python-0.4.0/src/alfred/rest/__init__.py +86 -0
- alfred_python-0.4.0/src/alfred/rest/data_points/__init__.py +14 -0
- alfred_python-0.4.0/src/alfred/rest/data_points/base.py +14 -0
- alfred_python-0.4.0/src/alfred/rest/data_points/v1.py +21 -0
- alfred_python-0.4.0/src/alfred/rest/files/__init__.py +14 -0
- alfred_python-0.4.0/src/alfred/rest/files/base.py +51 -0
- alfred_python-0.4.0/src/alfred/rest/files/typed.py +71 -0
- alfred_python-0.4.0/src/alfred/rest/files/v1.py +84 -0
- alfred_python-0.4.0/src/alfred/rest/jobs/__init__.py +14 -0
- alfred_python-0.4.0/src/alfred/rest/jobs/base.py +24 -0
- alfred_python-0.4.0/src/alfred/rest/jobs/typed.py +15 -0
- alfred_python-0.4.0/src/alfred/rest/jobs/v1.py +32 -0
- alfred_python-0.4.0/src/alfred/rest/sessions/__init__.py +14 -0
- alfred_python-0.4.0/src/alfred/rest/sessions/base.py +20 -0
- alfred_python-0.4.0/src/alfred/rest/sessions/v1.py +28 -0
- alfred_python-0.4.0/src/alfred/typings/__init__.py +1 -0
- {alfred_python-0.0.1/app → alfred_python-0.4.0/src/alfred}/typings/misc.py +1 -1
- alfred_python-0.4.0/src/alfred/utils/__init__.py +1 -0
- {alfred_python-0.0.1/app → alfred_python-0.4.0/src/alfred}/utils/logging.py +29 -26
- alfred_python-0.4.0/src/alfred_python.egg-info/PKG-INFO +283 -0
- alfred_python-0.4.0/src/alfred_python.egg-info/SOURCES.txt +35 -0
- alfred_python-0.4.0/src/alfred_python.egg-info/requires.txt +3 -0
- alfred_python-0.4.0/src/alfred_python.egg-info/top_level.txt +1 -0
- alfred_python-0.0.1/PKG-INFO +0 -42
- alfred_python-0.0.1/README.md +0 -29
- alfred_python-0.0.1/alfred_python.egg-info/PKG-INFO +0 -42
- alfred_python-0.0.1/alfred_python.egg-info/SOURCES.txt +0 -14
- alfred_python-0.0.1/alfred_python.egg-info/top_level.txt +0 -1
- alfred_python-0.0.1/app/__init__.py +0 -24
- alfred_python-0.0.1/app/config/__init__.py +0 -1
- alfred_python-0.0.1/app/config/settings.py +0 -21
- alfred_python-0.0.1/app/typings/__init__.py +0 -1
- alfred_python-0.0.1/app/utils/__init__.py +0 -1
- alfred_python-0.0.1/pyproject.toml +0 -17
- {alfred_python-0.0.1 → alfred_python-0.4.0}/LICENSE +0 -0
- {alfred_python-0.0.1 → alfred_python-0.4.0}/setup.cfg +0 -0
- {alfred_python-0.0.1 → alfred_python-0.4.0/src}/alfred_python.egg-info/dependency_links.txt +0 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: alfred-python
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Python library designed to simplify and streamline interactions with the Alfred API
|
|
5
|
+
Author-email: Tagshelf LLC <support@tagshelf.com>
|
|
6
|
+
License: Copyright (c) 2018 The Python Packaging Authority
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
25
|
+
Project-URL: homepage, https://github.com/tagshelfsrl/alfred-python
|
|
26
|
+
Classifier: Programming Language :: Python :: 3
|
|
27
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
28
|
+
Classifier: Operating System :: OS Independent
|
|
29
|
+
Requires-Python: >=3.8
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: pydantic>=2.0
|
|
33
|
+
Requires-Dist: pydantic-settings>=2.0
|
|
34
|
+
Requires-Dist: requests>=2.30
|
|
35
|
+
|
|
36
|
+
# Overview
|
|
37
|
+
|
|
38
|
+
Welcome to the `alfred-python` SDK, the official Python library for interfacing with Alfred, your intelligent process automation platform. This SDK provides a simple and efficient way to integrate Alfred's capabilities into your Python applications.
|
|
39
|
+
|
|
40
|
+
## Prerequisites
|
|
41
|
+
|
|
42
|
+
- Python v3.8+
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
Check out this simple example to get up and running:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from alfred.rest import AlfredClient
|
|
50
|
+
from alfred.base.config import Configuration
|
|
51
|
+
|
|
52
|
+
config = Configuration.v1()
|
|
53
|
+
auth_config = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
|
|
54
|
+
|
|
55
|
+
client = AlfredClient(config, auth_config)
|
|
56
|
+
|
|
57
|
+
values = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
58
|
+
print(values)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Sessions
|
|
62
|
+
|
|
63
|
+
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).
|
|
64
|
+
|
|
65
|
+
#### Get session by ID
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
# Get a session by ID
|
|
69
|
+
result = client.sessions.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
70
|
+
print(result)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Create session
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
# Create a session
|
|
77
|
+
result = client.sessions.create()
|
|
78
|
+
print(result)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Jobs
|
|
82
|
+
|
|
83
|
+
A Job represents a single unit of work that group one or more Files within Alfred. To see more information visit our [official documentation](https://docs.tagshelf.dev/enpoints/job).
|
|
84
|
+
|
|
85
|
+
#### Get job by ID
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# Get a job by ID
|
|
89
|
+
result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
90
|
+
print(result)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Create job
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
job = {
|
|
97
|
+
"session_id": "session-id",
|
|
98
|
+
"propagate_metadata": True,
|
|
99
|
+
"merge": True,
|
|
100
|
+
"decompose": True,
|
|
101
|
+
"metadata": {
|
|
102
|
+
"key": "value",
|
|
103
|
+
},
|
|
104
|
+
"channel": "channel",
|
|
105
|
+
"parent_file_prefix": "prefix",
|
|
106
|
+
"page_rotation": 90,
|
|
107
|
+
"container": "container",
|
|
108
|
+
"file_name": "file-name",
|
|
109
|
+
"file_names": ["file-name-1", "file-name-2"],
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# Create a job
|
|
113
|
+
result = client.jobs.create(job)
|
|
114
|
+
print(result)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Here is a description for each valid argument when creating a job:
|
|
118
|
+
|
|
119
|
+
| Parameter | Type | Description |
|
|
120
|
+
| ------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
121
|
+
| session_id | string | Session ID |
|
|
122
|
+
| metadata | any | Metadata of the job |
|
|
123
|
+
| propagate_metadata | boolean | If `true` ensures that the provided metadata at the Job level is attached to all the specified Files. |
|
|
124
|
+
| merge | boolean | If `true`, when all provided Files are either images or PDFs, the system combines them into a single file for the purpose of processing. |
|
|
125
|
+
| decompose | boolean | If `true`, when the provided File is a PDF, the system will decompose it into individual pages for processing. |
|
|
126
|
+
| channel | string | Channel |
|
|
127
|
+
| parent_file_prefix | string | The `parent_file_prefix` parameter is used to specify a virtual folder destination for the uploaded files. |
|
|
128
|
+
| page_rotation | number | Page rotation |
|
|
129
|
+
| container | string | Virtual container where the referenced remote file is located. |
|
|
130
|
+
| file_name | string | Unique name of the file within an object storage source. |
|
|
131
|
+
| file_names | string[] | Array of unique names of the files within an object storage source. |
|
|
132
|
+
|
|
133
|
+
### Files
|
|
134
|
+
|
|
135
|
+
File is an individual document or data unit undergoing specialized operations tailored for document analysis and management. To see more information visit our [official documentation](https://docs.tagshelf.dev/enpoints/file).
|
|
136
|
+
|
|
137
|
+
#### Get file by ID
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
# Get a file by ID
|
|
141
|
+
result = client.files.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
142
|
+
print(result)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Download file by ID
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
# Download a file by ID
|
|
149
|
+
result = client.files.download("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
150
|
+
|
|
151
|
+
with open(result.get("original_name"), "wb") as f:
|
|
152
|
+
f.write(result.get("file").getvalue())
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### Upload remote file
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
# Upload a remote file
|
|
159
|
+
result = client.files.upload({
|
|
160
|
+
"url": "<File URL>",
|
|
161
|
+
"metadata": {}
|
|
162
|
+
})
|
|
163
|
+
print(result)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Upload a local file
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
with open("<Path to local file>", "rb") as upload_file:
|
|
170
|
+
result = client.files.upload_file({
|
|
171
|
+
"file": upload_file,
|
|
172
|
+
"session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
|
|
173
|
+
"metadata": {}
|
|
174
|
+
})
|
|
175
|
+
print(result)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Data Points
|
|
179
|
+
|
|
180
|
+
Data Points are the core of Alfred's platform and represent data that you want to extract. To see more information visit our [official documentation](https://docs.tagshelf.dev/enpoints/metadata).
|
|
181
|
+
|
|
182
|
+
> [!IMPORTANT]
|
|
183
|
+
> Data Points where previously known as Metadata.
|
|
184
|
+
|
|
185
|
+
#### Get Data Point by File ID
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# Get a data point by file ID
|
|
189
|
+
result = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
190
|
+
print(result)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Configuration
|
|
194
|
+
|
|
195
|
+
This section provides detailed instructions and guidelines for configuring the SDK to interface effectively with the target API.
|
|
196
|
+
|
|
197
|
+
### Retry Policy
|
|
198
|
+
|
|
199
|
+
In this SDK, we implement automatic retries to enhance the reliability of network requests. However, to maintain the integrity of data transactions, retries are only enabled for HTTP methods that are considered idempotent. Idempotent methods are those that can be called multiple times without different outcomes. Thus, retries are applied only to the following HTTP methods:
|
|
200
|
+
|
|
201
|
+
- `GET`: Retrieves data from the server without changing any state.
|
|
202
|
+
- `PUT`: Updates a resource in a way that it can be repeatedly updated without changing the outcome beyond the initial application.
|
|
203
|
+
- `DELETE`: Removes a resource and subsequent deletions of the same resource are redundant.
|
|
204
|
+
- `HEAD`: Fetches metadata about a resource without side-effects.
|
|
205
|
+
- `OPTIONS`: Retrieves supported communication options for a given URL or server without causing any side effects.
|
|
206
|
+
|
|
207
|
+
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
|
+
|
|
209
|
+
## Development Setup
|
|
210
|
+
|
|
211
|
+
### Setting up the development environment
|
|
212
|
+
|
|
213
|
+
To contribute to `alfred-python`, you'll need to set up a Python development environment. We recommend using Conda, a popular package and environment management system. Here’s how to set it up:
|
|
214
|
+
|
|
215
|
+
1. **Install Conda**: If you do not have Conda installed, you can download and install it from [Miniconda](https://docs.conda.io/en/latest/miniconda.html) (a minimal installer) or [Anaconda](https://www.anaconda.com/products/distribution) (a full-featured distribution).
|
|
216
|
+
|
|
217
|
+
2. **Create a new Conda environment**: Open your terminal and run the following command to create a new environment named `alfred-python`:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
conda create --name alfred-python python=3.8 -y
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
3. **Activate the environment**: Activate the newly created environment by running:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
conda activate alfred-python
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
4. **Install dependencies**: With the environment activated, install the required dependencies by running:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
pip install -r requirements.txt
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
This sets up a basic Python environment tailored for development purposes.
|
|
236
|
+
|
|
237
|
+
### Optional: Setting up a testing environment
|
|
238
|
+
|
|
239
|
+
For testing and development, it's often useful to install the package in a way that reflects changes in real-time. To do this, you can install the package in editable mode. Here’s how to create a separate environment for testing and install the SDK:
|
|
240
|
+
|
|
241
|
+
1. **Create a testing environment**: It's a good practice to separate testing and development environments to avoid conflicts. Create a new environment named `alfred-python-test`:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
conda create --name alfred-python-test python=3.8 -y
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
2. **Activate the testing environment**:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
conda activate alfred-python-test
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
3. **Install the SDK in editable mode**: Navigate to the root directory of the `alfred-python` project and run:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
pip install --editable .
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Building the Project
|
|
260
|
+
|
|
261
|
+
To package `alfred-python` into distributable formats such as source archives and wheels, you will need to use the `build` module, a modern tool for building packages that adheres to PEP 517. Follow these steps to build the project:
|
|
262
|
+
|
|
263
|
+
### Preparing the build environment
|
|
264
|
+
|
|
265
|
+
Before building the project, ensure that your development environment is activated and up-to-date. If you don’t have an environment set up, please refer to the [Development Setup](#development-setup) section to create and activate one.
|
|
266
|
+
|
|
267
|
+
### Installing the build Tool
|
|
268
|
+
|
|
269
|
+
With your environment ready, install the `build` package. This package provides a simple, reliable way to build your project. Install it using pip:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
pip install -U build
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Running the build process
|
|
276
|
+
|
|
277
|
+
Once `build` is installed, you can generate the build artifacts by running the following command from the root directory of your project:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
python -m build
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
This command will produce a source distribution (`tar.gz`) and a wheel file (`whl`) in the `dist/` directory. These files are what you would upload to a package index like PyPI, or distribute to other developers.
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
Welcome to the `alfred-python` SDK, the official Python library for interfacing with Alfred, your intelligent process automation platform. This SDK provides a simple and efficient way to integrate Alfred's capabilities into your Python applications.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Python v3.8+
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Check out this simple example to get up and running:
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from alfred.rest import AlfredClient
|
|
15
|
+
from alfred.base.config import Configuration
|
|
16
|
+
|
|
17
|
+
config = Configuration.v1()
|
|
18
|
+
auth_config = {"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"}
|
|
19
|
+
|
|
20
|
+
client = AlfredClient(config, auth_config)
|
|
21
|
+
|
|
22
|
+
values = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
23
|
+
print(values)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Sessions
|
|
27
|
+
|
|
28
|
+
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
|
+
|
|
30
|
+
#### Get session by ID
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
# Get a session by ID
|
|
34
|
+
result = client.sessions.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
35
|
+
print(result)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Create session
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
# Create a session
|
|
42
|
+
result = client.sessions.create()
|
|
43
|
+
print(result)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Jobs
|
|
47
|
+
|
|
48
|
+
A Job represents a single unit of work that group one or more Files within Alfred. To see more information visit our [official documentation](https://docs.tagshelf.dev/enpoints/job).
|
|
49
|
+
|
|
50
|
+
#### Get job by ID
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
# Get a job by ID
|
|
54
|
+
result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
55
|
+
print(result)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### Create job
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
job = {
|
|
62
|
+
"session_id": "session-id",
|
|
63
|
+
"propagate_metadata": True,
|
|
64
|
+
"merge": True,
|
|
65
|
+
"decompose": True,
|
|
66
|
+
"metadata": {
|
|
67
|
+
"key": "value",
|
|
68
|
+
},
|
|
69
|
+
"channel": "channel",
|
|
70
|
+
"parent_file_prefix": "prefix",
|
|
71
|
+
"page_rotation": 90,
|
|
72
|
+
"container": "container",
|
|
73
|
+
"file_name": "file-name",
|
|
74
|
+
"file_names": ["file-name-1", "file-name-2"],
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# Create a job
|
|
78
|
+
result = client.jobs.create(job)
|
|
79
|
+
print(result)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Here is a description for each valid argument when creating a job:
|
|
83
|
+
|
|
84
|
+
| Parameter | Type | Description |
|
|
85
|
+
| ------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
|
+
| session_id | string | Session ID |
|
|
87
|
+
| metadata | any | Metadata of the job |
|
|
88
|
+
| propagate_metadata | boolean | If `true` ensures that the provided metadata at the Job level is attached to all the specified Files. |
|
|
89
|
+
| merge | boolean | If `true`, when all provided Files are either images or PDFs, the system combines them into a single file for the purpose of processing. |
|
|
90
|
+
| decompose | boolean | If `true`, when the provided File is a PDF, the system will decompose it into individual pages for processing. |
|
|
91
|
+
| channel | string | Channel |
|
|
92
|
+
| parent_file_prefix | string | The `parent_file_prefix` parameter is used to specify a virtual folder destination for the uploaded files. |
|
|
93
|
+
| page_rotation | number | Page rotation |
|
|
94
|
+
| container | string | Virtual container where the referenced remote file is located. |
|
|
95
|
+
| file_name | string | Unique name of the file within an object storage source. |
|
|
96
|
+
| file_names | string[] | Array of unique names of the files within an object storage source. |
|
|
97
|
+
|
|
98
|
+
### Files
|
|
99
|
+
|
|
100
|
+
File is an individual document or data unit undergoing specialized operations tailored for document analysis and management. To see more information visit our [official documentation](https://docs.tagshelf.dev/enpoints/file).
|
|
101
|
+
|
|
102
|
+
#### Get file by ID
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
# Get a file by ID
|
|
106
|
+
result = client.files.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
107
|
+
print(result)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Download file by ID
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
# Download a file by ID
|
|
114
|
+
result = client.files.download("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
115
|
+
|
|
116
|
+
with open(result.get("original_name"), "wb") as f:
|
|
117
|
+
f.write(result.get("file").getvalue())
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### Upload remote file
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
# Upload a remote file
|
|
124
|
+
result = client.files.upload({
|
|
125
|
+
"url": "<File URL>",
|
|
126
|
+
"metadata": {}
|
|
127
|
+
})
|
|
128
|
+
print(result)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### Upload a local file
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
with open("<Path to local file>", "rb") as upload_file:
|
|
135
|
+
result = client.files.upload_file({
|
|
136
|
+
"file": upload_file,
|
|
137
|
+
"session_id": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
|
|
138
|
+
"metadata": {}
|
|
139
|
+
})
|
|
140
|
+
print(result)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Data Points
|
|
144
|
+
|
|
145
|
+
Data Points are the core of Alfred's platform and represent data that you want to extract. To see more information visit our [official documentation](https://docs.tagshelf.dev/enpoints/metadata).
|
|
146
|
+
|
|
147
|
+
> [!IMPORTANT]
|
|
148
|
+
> Data Points where previously known as Metadata.
|
|
149
|
+
|
|
150
|
+
#### Get Data Point by File ID
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
# Get a data point by file ID
|
|
154
|
+
result = client.data_points.get_values("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
|
|
155
|
+
print(result)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Configuration
|
|
159
|
+
|
|
160
|
+
This section provides detailed instructions and guidelines for configuring the SDK to interface effectively with the target API.
|
|
161
|
+
|
|
162
|
+
### Retry Policy
|
|
163
|
+
|
|
164
|
+
In this SDK, we implement automatic retries to enhance the reliability of network requests. However, to maintain the integrity of data transactions, retries are only enabled for HTTP methods that are considered idempotent. Idempotent methods are those that can be called multiple times without different outcomes. Thus, retries are applied only to the following HTTP methods:
|
|
165
|
+
|
|
166
|
+
- `GET`: Retrieves data from the server without changing any state.
|
|
167
|
+
- `PUT`: Updates a resource in a way that it can be repeatedly updated without changing the outcome beyond the initial application.
|
|
168
|
+
- `DELETE`: Removes a resource and subsequent deletions of the same resource are redundant.
|
|
169
|
+
- `HEAD`: Fetches metadata about a resource without side-effects.
|
|
170
|
+
- `OPTIONS`: Retrieves supported communication options for a given URL or server without causing any side effects.
|
|
171
|
+
|
|
172
|
+
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
|
+
|
|
174
|
+
## Development Setup
|
|
175
|
+
|
|
176
|
+
### Setting up the development environment
|
|
177
|
+
|
|
178
|
+
To contribute to `alfred-python`, you'll need to set up a Python development environment. We recommend using Conda, a popular package and environment management system. Here’s how to set it up:
|
|
179
|
+
|
|
180
|
+
1. **Install Conda**: If you do not have Conda installed, you can download and install it from [Miniconda](https://docs.conda.io/en/latest/miniconda.html) (a minimal installer) or [Anaconda](https://www.anaconda.com/products/distribution) (a full-featured distribution).
|
|
181
|
+
|
|
182
|
+
2. **Create a new Conda environment**: Open your terminal and run the following command to create a new environment named `alfred-python`:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
conda create --name alfred-python python=3.8 -y
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
3. **Activate the environment**: Activate the newly created environment by running:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
conda activate alfred-python
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
4. **Install dependencies**: With the environment activated, install the required dependencies by running:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
pip install -r requirements.txt
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
This sets up a basic Python environment tailored for development purposes.
|
|
201
|
+
|
|
202
|
+
### Optional: Setting up a testing environment
|
|
203
|
+
|
|
204
|
+
For testing and development, it's often useful to install the package in a way that reflects changes in real-time. To do this, you can install the package in editable mode. Here’s how to create a separate environment for testing and install the SDK:
|
|
205
|
+
|
|
206
|
+
1. **Create a testing environment**: It's a good practice to separate testing and development environments to avoid conflicts. Create a new environment named `alfred-python-test`:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
conda create --name alfred-python-test python=3.8 -y
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
2. **Activate the testing environment**:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
conda activate alfred-python-test
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
3. **Install the SDK in editable mode**: Navigate to the root directory of the `alfred-python` project and run:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
pip install --editable .
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Building the Project
|
|
225
|
+
|
|
226
|
+
To package `alfred-python` into distributable formats such as source archives and wheels, you will need to use the `build` module, a modern tool for building packages that adheres to PEP 517. Follow these steps to build the project:
|
|
227
|
+
|
|
228
|
+
### Preparing the build environment
|
|
229
|
+
|
|
230
|
+
Before building the project, ensure that your development environment is activated and up-to-date. If you don’t have an environment set up, please refer to the [Development Setup](#development-setup) section to create and activate one.
|
|
231
|
+
|
|
232
|
+
### Installing the build Tool
|
|
233
|
+
|
|
234
|
+
With your environment ready, install the `build` package. This package provides a simple, reliable way to build your project. Install it using pip:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
pip install -U build
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Running the build process
|
|
241
|
+
|
|
242
|
+
Once `build` is installed, you can generate the build artifacts by running the following command from the root directory of your project:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
python -m build
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
This command will produce a source distribution (`tar.gz`) and a wheel file (`whl`) in the `dist/` directory. These files are what you would upload to a package index like PyPI, or distribute to other developers.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "alfred-python"
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
authors = [{ name = "Tagshelf LLC", email = "support@tagshelf.com" }]
|
|
9
|
+
description = "Python library designed to simplify and streamline interactions with the Alfred API"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"pydantic >= 2.0",
|
|
20
|
+
"pydantic-settings >= 2.0",
|
|
21
|
+
"requests >= 2.30",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
homepage = "https://github.com/tagshelfsrl/alfred-python"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["src"]
|
|
29
|
+
include = ["alfred", "alfred.*"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.1"
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Native imports
|
|
2
|
+
from typing import TypedDict, Optional, Text
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ConfigurationDict(TypedDict):
|
|
6
|
+
base_url: Text
|
|
7
|
+
version: int
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class OverridesDict(TypedDict):
|
|
11
|
+
base_url: Optional[Text]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Configuration:
|
|
15
|
+
@staticmethod
|
|
16
|
+
def default() -> ConfigurationDict:
|
|
17
|
+
"""
|
|
18
|
+
Returns default client configuration. Currently targets Alfred V1.
|
|
19
|
+
"""
|
|
20
|
+
return Configuration.v1()
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def v1(overrides: Optional[OverridesDict] = None) -> ConfigurationDict:
|
|
24
|
+
"""
|
|
25
|
+
Returns client configuration for Alfred V1.
|
|
26
|
+
"""
|
|
27
|
+
overrides = overrides or {}
|
|
28
|
+
return {
|
|
29
|
+
"version": 1,
|
|
30
|
+
"base_url": overrides.get("base_url", "https://app.tagshelf.com"),
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class AlfredMissingAuthException(Exception):
|
|
2
|
+
"""
|
|
3
|
+
Raised when proper authentication/authorization have not been provided.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AlfredMissingArgument(Exception):
|
|
8
|
+
"""
|
|
9
|
+
Raised when a payload is missing a required argument based on the whole context
|
|
10
|
+
of the operation.
|
|
11
|
+
"""
|
|
File without changes
|