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