bosa-connectors-binary 0.1.0__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,413 @@
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: 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.31.0,<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
+
@@ -0,0 +1,6 @@
1
+ bosa_connectors.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
2
+ bosa_connectors.cp313-win_amd64.pyd,sha256=iH6f1xAT7IXsHtxCI3E-Hj0RUnaFruFvF8PBoQY1JKE,849408
3
+ bosa_connectors.pyi,sha256=klto3AY3o5l8lA5NKYApY68UZ8FyQR07O37aQafpJZA,676
4
+ bosa_connectors_binary-0.1.0.dist-info/METADATA,sha256=vHyJnxX-jPtX1z1fNLr6KmLxTvrUFw-giXPNlCG0PxA,16083
5
+ bosa_connectors_binary-0.1.0.dist-info/WHEEL,sha256=RBxSuTKD__NDRUBZC1I4b5R6FamU3rQfymmsTgmeb3A,98
6
+ bosa_connectors_binary-0.1.0.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: cp313-cp313-win_amd64