bosa-connectors-binary 0.1.3__cp313-cp313-win_amd64.whl → 0.1.6__cp313-cp313-win_amd64.whl

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.
@@ -1,413 +1,415 @@
1
- Metadata-Version: 2.1
2
- Name: bosa-connectors-binary
3
- Version: 0.1.3
4
- Summary: BOSA Connectors
5
- Author: Bosa Engineers
6
- Author-email: bosa-eng@gdplabs.id
7
- Requires-Python: >=3.11,<3.14
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.11
10
- Classifier: Programming Language :: Python :: 3.12
11
- Provides-Extra: flag-embedding
12
- Provides-Extra: langchain-huggingface
13
- Provides-Extra: semantic-router
14
- Requires-Dist: langchain-core (>=0.3.61,<0.4.0)
15
- Requires-Dist: legacy-cgi (>=2.6.3,<3.0.0)
16
- Requires-Dist: libmagic (>=1.0,<2.0) ; sys_platform == "win32"
17
- Requires-Dist: pydantic (>=2.9.2,<3.0.0)
18
- Requires-Dist: python-magic-bin (>=0.4.14,<0.5.0) ; sys_platform == "win32"
19
- Requires-Dist: requests (>=2.32.4,<3.0.0)
20
- Description-Content-Type: text/markdown
21
-
22
- # BOSA API SDK (Bosa Connector)
23
-
24
- A Python SDK for seamlessly connecting to APIs that implement BOSA's Plugin Architecture under HTTP Interface. This connector acts as a proxy, simplifying the integration with BOSA-compatible APIs.
25
-
26
- ## Features
27
-
28
- - Simple and intuitive API for connecting to BOSA-compatible services
29
- - Automatic endpoint discovery and schema validation
30
- - Built-in authentication support (BOSA API Key and User Token)
31
- - User management and OAuth2 integration flow support
32
- - Type-safe parameter validation
33
- - Flexible parameter passing (dictionary or keyword arguments)
34
- - Retry support for requests that fail (429 or 5xx)
35
- - Response fields filtering based on action and output
36
-
37
- ## Prerequisites
38
- After the `bosa-api` ready, you can perform the following tasks:
39
- - Ensure Bosa API is running. If you want to test locally, or you can use Staging or Production environments.
40
- - Create Client
41
- - You can send a `create-client` request to the `bosa-api` using Postman with the following header and body:
42
- - Header
43
- - `x-api-user`: KEY1
44
- - Body
45
- - `name`: "`{client name}`"
46
- - Response :
47
- ```json
48
- {
49
- "data": {
50
- "id": "{client_id}",
51
- "name": "admin",
52
- "api_key": "{client_api_key}",
53
- "is_active": true
54
- },
55
- "meta": null
56
- }
57
- ```
58
- - Register the user, see the details [here](/python/bosa-connectors/README.md#user-authentication).
59
-
60
-
61
- ## Installation
62
-
63
- ### Prerequisites
64
- - Python 3.11+ - [Install here](https://www.python.org/downloads/)
65
- - Pip (if using Pip) - [Install here](https://pip.pypa.io/en/stable/installation/)
66
- - Poetry 1.8.1+ (if using Poetry) - [Install here](https://python-poetry.org/docs/#installation)
67
- - Git (if using Git) - [Install here](https://git-scm.com/downloads)
68
- - For git installation:
69
- - Access to the [GDP Labs SDK github repository](https://github.com/GDP-ADMIN/bosa-sdk)
70
-
71
- ### 1. Installation from Pypi
72
- Choose one of the following methods to install the package:
73
-
74
- #### Using pip
75
- ```bash
76
- pip install bosa-connectors-binary
77
- ```
78
-
79
- #### Using Poetry
80
- ```bash
81
- poetry add bosa-connectors-binary
82
- ```
83
-
84
- ### 2. Development Installation (Git)
85
- For development purposes, you can install directly from the Git repository:
86
- ```bash
87
- poetry add "git+ssh://git@github.com/GDP-ADMIN/bosa-sdk.git#subdirectory=python/bosa-connectors"
88
- ```
89
-
90
- ## Quick Start
91
-
92
- Here's a simple example of how to use the BOSA Connector with API key authentication and user token.
93
-
94
- ### Initialization
95
-
96
- Before using the connector, you need to initialize it with your BOSA API base URL and API key.
97
-
98
- ```python
99
- from bosa_connectors.connector import BosaConnector
100
-
101
- # Initialize the connector
102
- bosa = BosaConnector(api_base_url="YOUR_BOSA_API_BASE_URL", api_key="YOUR_API_KEY")
103
- ```
104
-
105
- ### Authentication
106
-
107
- After initializing the connector, you can authenticate with your BOSA API key.
108
-
109
-
110
- ```python
111
- # User token from authentication
112
- user_token = "Enter your key (bearer token) here from authentication, or refer to User Authentication section below"
113
-
114
- # Check if a user has an integration for a connector
115
- has_integration = bosa.user_has_integration("github", user_token)
116
-
117
- if not has_integration:
118
- # Initiate the OAuth2 flow for a connector
119
- auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
120
- # Redirect the user to auth_url to complete authentication, we exit here.
121
- print("Integration with GitHub not found.")
122
- print(f"Please visit {auth_url} to complete authentication.")
123
- exit()
124
- ```
125
-
126
- Alternatively, you can authenticate the user first and then use their token:
127
-
128
- ```python
129
- user = bosa.authenticate_bosa_user("username", "password")
130
-
131
- # Get user token
132
- user_token = user.token
133
- ```
134
-
135
- ### Basic Example (Direct Execution)
136
-
137
- It is the basic way to execute actions, where you need to provide the connector name, action name, and user token. The response will contain the data and status:
138
-
139
- ```python
140
- # Prepare input parameters
141
- params = {
142
- "repo": "my-local-repo", # try to use your local repo for testing
143
- "owner": "rexywjy",
144
- }
145
-
146
- # Execute the action with user token
147
- data, status = bosa.execute("github", "list_collaborators", token=user_token, max_attempts=1, input_=params)
148
- print(data)
149
- print(status)
150
- ```
151
- More details about parameters and actions in bosa-api docs `{domain}/docs`
152
-
153
- ### Alternative Approach (Fluent Interface)
154
-
155
- For more complex scenarios or more control over the execution, you can use the fluent interface. We're recommending this approach if you:
156
-
157
- - Need to execute multiple actions with different parameters
158
- - Expecting list response
159
- - Need to execute actions in a loop
160
-
161
- ```python
162
- # Prepare input parameters
163
- params = {
164
- "owner": "gdp-admin",
165
- "author": "samuellusandi",
166
- "per_page": 1,
167
- "sort": "author_date",
168
- "created_date_start": "2025-02-01",
169
- "created_date_end": "2025-02-02"
170
- }
171
-
172
- # Create a connector instance to a service
173
- github = bosa.connect('github')
174
-
175
- # Execute actions with fluent interface
176
- response = github.action('list_pull_requests')\
177
- .params(params)\
178
- .max_attempts(3)\
179
- .token('user-token')\
180
- .run() # Execute and return ActionResponse for advanced data handling
181
-
182
- # Get initial data
183
- initial_data = response.get_data()
184
-
185
- # Iterate the following next pages
186
- while response.has_next():
187
- response = response.next_page()
188
- data = response.get_data()
189
- # Process data here
190
- ...
191
-
192
- # You can also navigate backwards
193
- while response.has_prev():
194
- response = response.prev_page()
195
- data = response.get_data()
196
- # Process data here
197
- ...
198
-
199
- # Execute multiple independent actions using the same connector instance
200
- commits_response = github.action('list_commits')\
201
- .params({
202
- 'owner': 'GDP-ADMIN',
203
- 'repo': 'bosa',
204
- 'page': 1,
205
- 'per_page': 10
206
- })\
207
- .token('user-token')\
208
- .run()
209
- ```
210
-
211
- `run` method also available for direct execution from connector instance, without using fluent interface.
212
-
213
- ```python
214
- # Prepare input parameters
215
- params = {
216
- "owner": "gdp-admin",
217
- "author": "samuellusandi",
218
- "per_page": 1,
219
- "sort": "author_date",
220
- "created_date_start": "2025-02-01",
221
- "created_date_end": "2025-02-02"
222
- }
223
-
224
- # Execute actions with run method
225
- response = bosa.run('github', 'list_pull_requests', params)
226
- print(response.get_data())
227
- ```
228
-
229
- ### Working with Files using ConnectorFile
230
-
231
- When working with APIs that require file uploads or return file downloads, use the `ConnectorFile` model:
232
-
233
- ```python
234
- from bosa_connectors.models.file import ConnectorFile
235
-
236
- # For uploads: Create a ConnectorFile object
237
- with open("document.pdf", "rb") as f:
238
- upload_file = ConnectorFile(
239
- file=f.read(),
240
- filename="document.pdf",
241
- content_type="application/pdf"
242
- )
243
-
244
- params = {
245
- "file": upload_file,
246
- "name": "My Document"
247
- }
248
-
249
- # Include in your parameters
250
- result, status = bosa.execute("google_drive", "upload_file", input_=params)
251
-
252
- # For downloads: Check response type
253
- file_result, status = bosa.execute("google_drive", "download_file", input_={"file_id": "123"})
254
- if isinstance(file_result, ConnectorFile):
255
- # Save to disk
256
- with open(file_result.filename or "downloaded_file", "wb") as f:
257
- f.write(file_result.file)
258
- ```
259
-
260
- ## Available Methods
261
-
262
- ### Connector Instance Methods
263
-
264
- The connector instance provides several methods for configuring and executing actions:
265
-
266
- - `connect(name)`: Create a connector instance to a service
267
- - `action(name)`: Specify the action to execute
268
- - `params(dict)`: Set request parameters (including pagination parameters like page and per_page). Note that params for each plugin and action could be different
269
- - `token(str)`: Set the BOSA user token
270
- - `headers(dict)`: Set custom request headers
271
- - `max_attempts(number)`: Set the maximum number of retry attempts (default: 1)
272
- Execution Methods:
273
-
274
- - `run()`: Execute and return ActionResponse for advanced data handling
275
- - `execute()`: Execute and return data and status for basic data handling. The data part of the return value can be a ConnectorFile object when the API returns a non-JSON response (such as a file download).
276
-
277
- ### Response Handling (ActionResponse)
278
-
279
- The ActionResponse class provides methods for handling the response and pagination:
280
-
281
- - `get_data()`: Get the current page data (returns the data field from the response). This can return a ConnectorFile object when the API returns a non-JSON response (such as a file download).
282
- - `get_meta()`: Get the metadata information from the response (e.g., pagination details, total count)
283
- - `get_status()`: Get the HTTP status code
284
- - `is_list()`: Check if response is a list
285
- - `has_next()`: Check if there is a next page
286
- - `has_prev()`: Check if there is a previous page
287
- - `next_page()`: Move to and execute next page
288
- - `prev_page()`: Move to and execute previous page
289
- - `get_all_items()`: Get all items from all pages (returns a list of objects containing data and meta for each page)
290
-
291
- ## Data Models
292
-
293
- The SDK uses the following data models:
294
-
295
- - `ActionResponseData`: Contains the response data structure with `data` (list, object, or ConnectorFile instance) and `meta` (metadata) fields
296
- - `InitialExecutorRequest`: Stores the initial request parameters used for pagination and subsequent requests
297
- - `ConnectorFile`: Represents a file in requests and responses with these properties:
298
- - `file`: Raw bytes content of the file
299
- - `filename`: Optional name of the file
300
- - `content_type`: Optional MIME type of the file
301
- - `headers`: Optional HTTP headers for the file
302
-
303
- ## Configuration Parameters
304
-
305
- - `api_base_url`: The base URL of your BOSA API endpoint (default: "https://api.bosa.id"). This parameter is extremely important as it determines the URL of the BOSA API you are connecting to, and it will be used to populate the available actions/endpoints and their parameters upon initialization.
306
- - `api_key`: Your BOSA API key for authentication. This is different from plugin-specific API keys, which are managed separately by the BOSA system.
307
-
308
- ## Execution Parameters
309
-
310
- - `connector`: The name of the connector to use. This parameter is used to determine the connector's available actions and their parameters.
311
- - `action`: The name of the action to execute. This parameter is automatically populated by the connector based on the available actions and their parameters. The list of available actions per connector can be found in https://api.bosa.id/docs and are populated through https://api.bosa.id/connectors.
312
- - `max_attempts`: The maximum number of attempts to make the API request. If the request fails, the connector will retry the request up to this number of times. The default value is 1 if not provided.
313
- - The retries are handled automatically by the connector, with exponential backoff.
314
- - The retries are only done for errors that are considered retryable (429 or 5xx).
315
- - `input_`: The input parameters for the action. This parameter is a dictionary that contains the parameters for the action. The connector will validate the input parameters against the action's schema.
316
- - To filter response fields, simply add the `response_fields` parameter to the input dictionary. This parameter is a list of field names that will be returned in the response. For nested fields, you can use dot notation, e.g. `user.login` will return the following:
317
- ```json
318
- {
319
- "user": {
320
- "login": "userlogin"
321
- }
322
- }
323
- ```
324
- - `token`: Optional BOSA User Token for authenticating requests. When provided, the connector will include this token in the request headers. This is required for user-specific actions or when working with third-party integrations.
325
-
326
- ## How It Works
327
-
328
- 1. **Initialization**: When you create a `BosaConnector` instance, and trigger an `execute()`, the connector will first populate and cache the available actions and their parameters. This is done automatically.
329
-
330
- 2. **Action Discovery**: The connector expects the BOSA API to expose an endpoint that lists all available actions and their parameters. This is handled automatically by BOSA's HTTP Interface.
331
-
332
- 3. **Execution**: When you call `execute()`, the connector:
333
- - Validates your input parameters against the action's schema
334
- - Handles authentication
335
- - Makes the API request
336
- - Returns the formatted response
337
-
338
- ## Compatibility
339
-
340
- While primarily tested with BOSA's HTTP Interface, this connector should theoretically work with any API that implements BOSA's Plugin Architecture, as long as it:
341
-
342
- 1. Exposes an endpoint listing available actions and their parameters
343
- 2. Follows BOSA's standard HTTP Interface specifications (through the Plugin Architecture)
344
- - All actions must be exposed as `POST` endpoints.
345
- 3. Implements the required authentication mechanisms
346
-
347
- ## Error Handling
348
-
349
- The connector includes built-in error handling for:
350
-
351
- - Invalid parameters
352
- - Authentication failures
353
- - Connection issues
354
- - API response errors
355
-
356
- ## User Authentication
357
-
358
- The BOSA Connector supports user-based authentication which allows for user-specific actions and third-party integrations:
359
-
360
- ```python
361
- # Step 1: Create a new BOSA user
362
- user_data = bosa.create_bosa_user("username")
363
- # Save the secret for later use
364
- user_secret = user_data.secret
365
-
366
- # Step 2: Authenticate the user and obtain their token
367
- token = bosa.authenticate_bosa_user("username", user_secret)
368
-
369
- # Step 3: Retrieve user information using the obtained token
370
- user_info = bosa.get_user_info(token.token)
371
- ```
372
-
373
- ### Important Notes
374
-
375
- ***🛡️ Best Practice:*** Since bearer tokens can have a long lifespan, it is highly recommended to **reuse existing tokens** whenever possible. While creating new tokens is functionally acceptable, be aware that older tokens may become dangling and can pose a security risk if they are exposed or misused.
376
-
377
- ***⚠️ Security Reminder:*** When you register a new BOSA user, you will receive a token that starts with **"sk-user-..."**. It is essential to keep this token safe, as it **cannot be recovered if lost**, and currently, there is **no option to reset** it.
378
-
379
-
380
- ## Integration Management
381
-
382
- The BOSA Connector provides methods to manage third-party integrations for authenticated users:
383
-
384
- ```python
385
- # Check if a user has an integration for a connector
386
- has_integration = bosa.user_has_integration("github", user_token)
387
-
388
- # Initiate the OAuth2 flow for a connector
389
- auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
390
- # Redirect the user to auth_url to complete authentication
391
-
392
- # Remove an integration
393
- remove_result = bosa.remove_integration("github", user_token)
394
- ```
395
-
396
- ## References
397
-
398
- Product Requirements Documents(PRD):
399
-
400
- - [BOSA Connector - Product Document](https://docs.google.com/document/d/1R6JIGWnKzNg2kRMRSiZ-wwPGe9pOR9rkkEI0Uz-Wtdw/edit?tab=t.y617gs6jfk15#heading=h.uss0d453lcbs)
401
-
402
- Architecture Documents:
403
-
404
- - [BOSA Connector - Architecture Document](https://docs.google.com/document/d/1HHUBAkbFAM8sM_Dtx6tmoatR1HeuM6VBfsWEjpgVCtg/edit?tab=t.0#heading=h.bj79ljx9eqg8)
405
-
406
- Design Documents:
407
-
408
- - [BOSA Connector - Design Document](https://docs.google.com/document/d/1PghW7uOJcEbT3WNSlZ0FI99o4y24ys0LCyAG8hg3T9o/edit?tab=t.0#heading=h.bj79ljx9eqg8)
409
-
410
- Implementation Documents:
411
-
412
- - [BOSA Connector - Implementation Document](https://docs.google.com/document/d/1a8BvggPu5a6PBStgUu2ILse075FjAAgoehUuvxxAajM/edit?tab=t.0#heading=h.bj79ljx9eqg8)
413
-
1
+ Metadata-Version: 2.2
2
+ Name: bosa-connectors-binary
3
+ Version: 0.1.6
4
+ Summary: BOSA Connectors
5
+ Author-email: Bosa Engineers <bosa-eng@gdplabs.id>
6
+ Requires-Python: <3.14,>=3.11
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: pydantic-settings<3.0.0,>=2.7.1
9
+ Requires-Dist: pydantic<3.0.0,>=2.9.2
10
+ Requires-Dist: requests<3.0.0,>=2.31.0
11
+ Requires-Dist: langchain-core<1.0.0,>=0.3.65
12
+ Requires-Dist: legacy-cgi<3.0.0,>=2.6.3
13
+ Requires-Dist: urllib3<3.0.0,>=2.5.0
14
+ Requires-Dist: python-magic-bin<0.5.0,>=0.4.14; sys_platform == "win32"
15
+ Requires-Dist: libmagic<2.0,>=1.0; sys_platform == "win32"
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest<9.0.0,>=8.1.1; extra == "dev"
18
+ Requires-Dist: pre-commit<4.0.0,>=3.6.2; extra == "dev"
19
+ Requires-Dist: pytest-cov<6.0.0,>=5.0.0; extra == "dev"
20
+ Requires-Dist: pytest-asyncio<1.0.0,>=0.23.6; extra == "dev"
21
+ Requires-Dist: pydocstyle<7.0.0,>=6.3.0; extra == "dev"
22
+ Requires-Dist: ruff<1.0.0,>=0.9.9; extra == "dev"
23
+ Requires-Dist: mypy<2.0.0,>=1.11.2; extra == "dev"
24
+
25
+ # BOSA API SDK (Bosa Connector)
26
+
27
+ A Python SDK for seamlessly connecting to APIs that implement BOSA's Plugin Architecture under HTTP Interface. This connector acts as a proxy, simplifying the integration with BOSA-compatible APIs.
28
+
29
+ ## Features
30
+
31
+ - Simple and intuitive API for connecting to BOSA-compatible services
32
+ - Automatic endpoint discovery and schema validation
33
+ - Built-in authentication support (BOSA API Key and User Token)
34
+ - User management and OAuth2 integration flow support
35
+ - Type-safe parameter validation
36
+ - Flexible parameter passing (dictionary or keyword arguments)
37
+ - Retry support for requests that fail (429 or 5xx)
38
+ - Response fields filtering based on action and output
39
+
40
+ ## Prerequisites
41
+ After the `bosa-api` ready, you can perform the following tasks:
42
+ - Ensure Bosa API is running. If you want to test locally, or you can use Staging or Production environments.
43
+ - Create Client
44
+ - You can send a `create-client` request to the `bosa-api` using Postman with the following header and body:
45
+ - Header
46
+ - `x-api-user`: KEY1
47
+ - Body
48
+ - `name`: "`{client name}`"
49
+ - Response :
50
+ ```json
51
+ {
52
+ "data": {
53
+ "id": "{client_id}",
54
+ "name": "admin",
55
+ "api_key": "{client_api_key}",
56
+ "is_active": true
57
+ },
58
+ "meta": null
59
+ }
60
+ ```
61
+ - Register the user, see the details [here](/python/bosa-connectors/README.md#user-authentication).
62
+
63
+
64
+ ## Installation
65
+
66
+ ### Prerequisites
67
+ - Python 3.11+ - [Install here](https://www.python.org/downloads/)
68
+ - Pip (if using Pip) - [Install here](https://pip.pypa.io/en/stable/installation/)
69
+ - Poetry 2.1.3+ (if using Poetry) - [Install here](https://python-poetry.org/docs/#installation)
70
+ - Git (if using Git) - [Install here](https://git-scm.com/downloads)
71
+ - For git installation:
72
+ - Access to the [GDP Labs SDK github repository](https://github.com/GDP-ADMIN/bosa-sdk)
73
+
74
+ ### 1. Installation from Pypi
75
+ Choose one of the following methods to install the package:
76
+
77
+ #### Using pip
78
+ ```bash
79
+ pip install bosa-connectors-binary
80
+ ```
81
+
82
+ #### Using Poetry
83
+ ```bash
84
+ poetry add bosa-connectors-binary
85
+ ```
86
+
87
+ ### 2. Development Installation (Git)
88
+ For development purposes, you can install directly from the Git repository:
89
+ ```bash
90
+ poetry add "git+ssh://git@github.com/GDP-ADMIN/bosa-sdk.git#subdirectory=python/bosa-connectors"
91
+ ```
92
+
93
+ ## Quick Start
94
+
95
+ Here's a simple example of how to use the BOSA Connector with API key authentication and user token.
96
+
97
+ ### Initialization
98
+
99
+ Before using the connector, you need to initialize it with your BOSA API base URL and API key.
100
+
101
+ ```python
102
+ from bosa_connectors.connector import BosaConnector
103
+
104
+ # Initialize the connector
105
+ bosa = BosaConnector(api_base_url="YOUR_BOSA_API_BASE_URL", api_key="YOUR_API_KEY")
106
+ ```
107
+
108
+ ### Authentication
109
+
110
+ After initializing the connector, you can authenticate with your BOSA API key.
111
+
112
+
113
+ ```python
114
+ # User token from authentication
115
+ user_token = "Enter your key (bearer token) here from authentication, or refer to User Authentication section below"
116
+
117
+ # Check if a user has an integration for a connector
118
+ has_integration = bosa.user_has_integration("github", user_token)
119
+
120
+ if not has_integration:
121
+ # Initiate the OAuth2 flow for a connector
122
+ auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
123
+ # Redirect the user to auth_url to complete authentication, we exit here.
124
+ print("Integration with GitHub not found.")
125
+ print(f"Please visit {auth_url} to complete authentication.")
126
+ exit()
127
+ ```
128
+
129
+ Alternatively, you can authenticate the user first and then use their token:
130
+
131
+ ```python
132
+ user = bosa.authenticate_bosa_user("username", "password")
133
+
134
+ # Get user token
135
+ user_token = user.token
136
+ ```
137
+
138
+ ### Basic Example (Direct Execution)
139
+
140
+ It is the basic way to execute actions, where you need to provide the connector name, action name, and user token. The response will contain the data and status:
141
+
142
+ ```python
143
+ # Prepare input parameters
144
+ params = {
145
+ "repo": "my-local-repo", # try to use your local repo for testing
146
+ "owner": "rexywjy",
147
+ }
148
+
149
+ # Execute the action with user token
150
+ data, status = bosa.execute("github", "list_collaborators", token=user_token, max_attempts=1, input_=params)
151
+ print(data)
152
+ print(status)
153
+ ```
154
+ More details about parameters and actions in bosa-api docs `{domain}/docs`
155
+
156
+ ### Alternative Approach (Fluent Interface)
157
+
158
+ For more complex scenarios or more control over the execution, you can use the fluent interface. We're recommending this approach if you:
159
+
160
+ - Need to execute multiple actions with different parameters
161
+ - Expecting list response
162
+ - Need to execute actions in a loop
163
+
164
+ ```python
165
+ # Prepare input parameters
166
+ params = {
167
+ "owner": "gdp-admin",
168
+ "author": "samuellusandi",
169
+ "per_page": 1,
170
+ "sort": "author_date",
171
+ "created_date_start": "2025-02-01",
172
+ "created_date_end": "2025-02-02"
173
+ }
174
+
175
+ # Create a connector instance to a service
176
+ github = bosa.connect('github')
177
+
178
+ # Execute actions with fluent interface
179
+ response = github.action('list_pull_requests')\
180
+ .params(params)\
181
+ .max_attempts(3)\
182
+ .token('user-token')\
183
+ .run() # Execute and return ActionResponse for advanced data handling
184
+
185
+ # Get initial data
186
+ initial_data = response.get_data()
187
+
188
+ # Iterate the following next pages
189
+ while response.has_next():
190
+ response = response.next_page()
191
+ data = response.get_data()
192
+ # Process data here
193
+ ...
194
+
195
+ # You can also navigate backwards
196
+ while response.has_prev():
197
+ response = response.prev_page()
198
+ data = response.get_data()
199
+ # Process data here
200
+ ...
201
+
202
+ # Execute multiple independent actions using the same connector instance
203
+ commits_response = github.action('list_commits')\
204
+ .params({
205
+ 'owner': 'GDP-ADMIN',
206
+ 'repo': 'bosa',
207
+ 'page': 1,
208
+ 'per_page': 10
209
+ })\
210
+ .token('user-token')\
211
+ .run()
212
+ ```
213
+
214
+ `run` method also available for direct execution from connector instance, without using fluent interface.
215
+
216
+ ```python
217
+ # Prepare input parameters
218
+ params = {
219
+ "owner": "gdp-admin",
220
+ "author": "samuellusandi",
221
+ "per_page": 1,
222
+ "sort": "author_date",
223
+ "created_date_start": "2025-02-01",
224
+ "created_date_end": "2025-02-02"
225
+ }
226
+
227
+ # Execute actions with run method
228
+ response = bosa.run('github', 'list_pull_requests', params)
229
+ print(response.get_data())
230
+ ```
231
+
232
+ ### Working with Files using ConnectorFile
233
+
234
+ When working with APIs that require file uploads or return file downloads, use the `ConnectorFile` model:
235
+
236
+ ```python
237
+ from bosa_connectors.models.file import ConnectorFile
238
+
239
+ # For uploads: Create a ConnectorFile object
240
+ with open("document.pdf", "rb") as f:
241
+ upload_file = ConnectorFile(
242
+ file=f.read(),
243
+ filename="document.pdf",
244
+ content_type="application/pdf"
245
+ )
246
+
247
+ params = {
248
+ "file": upload_file,
249
+ "name": "My Document"
250
+ }
251
+
252
+ # Include in your parameters
253
+ result, status = bosa.execute("google_drive", "upload_file", input_=params)
254
+
255
+ # For downloads: Check response type
256
+ file_result, status = bosa.execute("google_drive", "download_file", input_={"file_id": "123"})
257
+ if isinstance(file_result, ConnectorFile):
258
+ # Save to disk
259
+ with open(file_result.filename or "downloaded_file", "wb") as f:
260
+ f.write(file_result.file)
261
+ ```
262
+
263
+ ## Available Methods
264
+
265
+ ### Connector Instance Methods
266
+
267
+ The connector instance provides several methods for configuring and executing actions:
268
+
269
+ - `connect(name)`: Create a connector instance to a service
270
+ - `action(name)`: Specify the action to execute
271
+ - `params(dict)`: Set request parameters (including pagination parameters like page and per_page). Note that params for each plugin and action could be different
272
+ - `token(str)`: Set the BOSA user token
273
+ - `headers(dict)`: Set custom request headers
274
+ - `max_attempts(number)`: Set the maximum number of retry attempts (default: 1)
275
+ Execution Methods:
276
+
277
+ - `run()`: Execute and return ActionResponse for advanced data handling
278
+ - `execute()`: Execute and return data and status for basic data handling. The data part of the return value can be a ConnectorFile object when the API returns a non-JSON response (such as a file download).
279
+
280
+ ### Response Handling (ActionResponse)
281
+
282
+ The ActionResponse class provides methods for handling the response and pagination:
283
+
284
+ - `get_data()`: Get the current page data (returns the data field from the response). This can return a ConnectorFile object when the API returns a non-JSON response (such as a file download).
285
+ - `get_meta()`: Get the metadata information from the response (e.g., pagination details, total count)
286
+ - `get_status()`: Get the HTTP status code
287
+ - `is_list()`: Check if response is a list
288
+ - `has_next()`: Check if there is a next page
289
+ - `has_prev()`: Check if there is a previous page
290
+ - `next_page()`: Move to and execute next page
291
+ - `prev_page()`: Move to and execute previous page
292
+ - `get_all_items()`: Get all items from all pages (returns a list of objects containing data and meta for each page)
293
+
294
+ ## Data Models
295
+
296
+ The SDK uses the following data models:
297
+
298
+ - `ActionResponseData`: Contains the response data structure with `data` (list, object, or ConnectorFile instance) and `meta` (metadata) fields
299
+ - `InitialExecutorRequest`: Stores the initial request parameters used for pagination and subsequent requests
300
+ - `ConnectorFile`: Represents a file in requests and responses with these properties:
301
+ - `file`: Raw bytes content of the file
302
+ - `filename`: Optional name of the file
303
+ - `content_type`: Optional MIME type of the file
304
+ - `headers`: Optional HTTP headers for the file
305
+
306
+ ## Configuration Parameters
307
+
308
+ - `api_base_url`: The base URL of your BOSA API endpoint (default: "https://api.bosa.id"). This parameter is extremely important as it determines the URL of the BOSA API you are connecting to, and it will be used to populate the available actions/endpoints and their parameters upon initialization.
309
+ - `api_key`: Your BOSA API key for authentication. This is different from plugin-specific API keys, which are managed separately by the BOSA system.
310
+
311
+ ## Execution Parameters
312
+
313
+ - `connector`: The name of the connector to use. This parameter is used to determine the connector's available actions and their parameters.
314
+ - `action`: The name of the action to execute. This parameter is automatically populated by the connector based on the available actions and their parameters. The list of available actions per connector can be found in https://api.bosa.id/docs and are populated through https://api.bosa.id/connectors.
315
+ - `max_attempts`: The maximum number of attempts to make the API request. If the request fails, the connector will retry the request up to this number of times. The default value is 1 if not provided.
316
+ - The retries are handled automatically by the connector, with exponential backoff.
317
+ - The retries are only done for errors that are considered retryable (429 or 5xx).
318
+ - `input_`: The input parameters for the action. This parameter is a dictionary that contains the parameters for the action. The connector will validate the input parameters against the action's schema.
319
+ - To filter response fields, simply add the `response_fields` parameter to the input dictionary. This parameter is a list of field names that will be returned in the response. For nested fields, you can use dot notation, e.g. `user.login` will return the following:
320
+ ```json
321
+ {
322
+ "user": {
323
+ "login": "userlogin"
324
+ }
325
+ }
326
+ ```
327
+ - `token`: Optional BOSA User Token for authenticating requests. When provided, the connector will include this token in the request headers. This is required for user-specific actions or when working with third-party integrations.
328
+
329
+ ## How It Works
330
+
331
+ 1. **Initialization**: When you create a `BosaConnector` instance, and trigger an `execute()`, the connector will first populate and cache the available actions and their parameters. This is done automatically.
332
+
333
+ 2. **Action Discovery**: The connector expects the BOSA API to expose an endpoint that lists all available actions and their parameters. This is handled automatically by BOSA's HTTP Interface.
334
+
335
+ 3. **Execution**: When you call `execute()`, the connector:
336
+ - Validates your input parameters against the action's schema
337
+ - Handles authentication
338
+ - Makes the API request
339
+ - Returns the formatted response
340
+
341
+ ## Compatibility
342
+
343
+ While primarily tested with BOSA's HTTP Interface, this connector should theoretically work with any API that implements BOSA's Plugin Architecture, as long as it:
344
+
345
+ 1. Exposes an endpoint listing available actions and their parameters
346
+ 2. Follows BOSA's standard HTTP Interface specifications (through the Plugin Architecture)
347
+ - All actions must be exposed as `POST` endpoints.
348
+ 3. Implements the required authentication mechanisms
349
+
350
+ ## Error Handling
351
+
352
+ The connector includes built-in error handling for:
353
+
354
+ - Invalid parameters
355
+ - Authentication failures
356
+ - Connection issues
357
+ - API response errors
358
+
359
+ ## User Authentication
360
+
361
+ The BOSA Connector supports user-based authentication which allows for user-specific actions and third-party integrations:
362
+
363
+ ```python
364
+ # Step 1: Create a new BOSA user
365
+ user_data = bosa.create_bosa_user("username")
366
+ # Save the secret for later use
367
+ user_secret = user_data.secret
368
+
369
+ # Step 2: Authenticate the user and obtain their token
370
+ token = bosa.authenticate_bosa_user("username", user_secret)
371
+
372
+ # Step 3: Retrieve user information using the obtained token
373
+ user_info = bosa.get_user_info(token.token)
374
+ ```
375
+
376
+ ### ❗ Important Notes
377
+
378
+ ***🛡️ Best Practice:*** Since bearer tokens can have a long lifespan, it is highly recommended to **reuse existing tokens** whenever possible. While creating new tokens is functionally acceptable, be aware that older tokens may become dangling and can pose a security risk if they are exposed or misused.
379
+
380
+ ***⚠️ Security Reminder:*** When you register a new BOSA user, you will receive a token that starts with **"sk-user-..."**. It is essential to keep this token safe, as it **cannot be recovered if lost**, and currently, there is **no option to reset** it.
381
+
382
+
383
+ ## Integration Management
384
+
385
+ The BOSA Connector provides methods to manage third-party integrations for authenticated users:
386
+
387
+ ```python
388
+ # Check if a user has an integration for a connector
389
+ has_integration = bosa.user_has_integration("github", user_token)
390
+
391
+ # Initiate the OAuth2 flow for a connector
392
+ auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
393
+ # Redirect the user to auth_url to complete authentication
394
+
395
+ # Remove an integration
396
+ remove_result = bosa.remove_integration("github", user_token)
397
+ ```
398
+
399
+ ## References
400
+
401
+ Product Requirements Documents(PRD):
402
+
403
+ - [BOSA Connector - Product Document](https://docs.google.com/document/d/1R6JIGWnKzNg2kRMRSiZ-wwPGe9pOR9rkkEI0Uz-Wtdw/edit?tab=t.y617gs6jfk15#heading=h.uss0d453lcbs)
404
+
405
+ Architecture Documents:
406
+
407
+ - [BOSA Connector - Architecture Document](https://docs.google.com/document/d/1HHUBAkbFAM8sM_Dtx6tmoatR1HeuM6VBfsWEjpgVCtg/edit?tab=t.0#heading=h.bj79ljx9eqg8)
408
+
409
+ Design Documents:
410
+
411
+ - [BOSA Connector - Design Document](https://docs.google.com/document/d/1PghW7uOJcEbT3WNSlZ0FI99o4y24ys0LCyAG8hg3T9o/edit?tab=t.0#heading=h.bj79ljx9eqg8)
412
+
413
+ Implementation Documents:
414
+
415
+ - [BOSA Connector - Implementation Document](https://docs.google.com/document/d/1a8BvggPu5a6PBStgUu2ILse075FjAAgoehUuvxxAajM/edit?tab=t.0#heading=h.bj79ljx9eqg8)