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