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