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