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