bosa-connectors-binary 0.0.7.post1__cp312-cp312-manylinux_2_31_x86_64.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,5 @@
1
+ from .connector import BosaConnector as BosaConnector
2
+ from .module import BosaConnectorModule as BosaConnectorModule
3
+ from bosa_connectors.helpers.authenticator import BosaAuthenticator as BosaAuthenticator
4
+
5
+ __all__ = ['BosaAuthenticator', 'BosaConnector', 'BosaConnectorModule']
@@ -0,0 +1,80 @@
1
+ from bosa_connectors.action_response import ActionResponse as ActionResponse
2
+ from bosa_connectors.auth import BaseAuthenticator as BaseAuthenticator
3
+ from bosa_connectors.models.file import ConnectorFile as ConnectorFile
4
+ from bosa_connectors.module import BosaConnectorModule as BosaConnectorModule
5
+ from typing import Any
6
+
7
+ class ActionExecutor:
8
+ """Represents a specific action execution for a service.
9
+
10
+ Example:
11
+ # Direct execution with raw response
12
+ data, status = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .execute()
13
+
14
+ # Or with pagination support
15
+ response = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .run()
16
+
17
+ # Get data and handle pagination
18
+ data = response.get_data()
19
+ while response.has_next():
20
+ response = response.next_page()
21
+ data = response.get_data()
22
+ """
23
+ DEFAULT_MAX_ATTEMPTS: int
24
+ DEFAULT_TIMEOUT: int
25
+ def __init__(self, module: BosaConnectorModule, authenticator: BaseAuthenticator, action: str) -> None:
26
+ """Initialize the action executor.
27
+
28
+ Args:
29
+ module: The connector module to execute against
30
+ authenticator: The authenticator to use for requests
31
+ action: The action name to execute
32
+ """
33
+ def params(self, params: dict[str, Any]) -> ActionExecutor:
34
+ """Set additional parameters."""
35
+ def headers(self, headers: dict[str, str]) -> ActionExecutor:
36
+ """Set request headers."""
37
+ def max_attempts(self, attempts: int) -> ActionExecutor:
38
+ """Set maximum retry attempts."""
39
+ def token(self, token: str | None) -> ActionExecutor:
40
+ """Set the BOSA user token for this action."""
41
+ def timeout(self, timeout: int | None) -> ActionExecutor:
42
+ """Set the timeout for the request."""
43
+ def execute(self) -> tuple[dict[str, Any] | ConnectorFile, int]:
44
+ """Execute request and return raw response.
45
+
46
+ Returns:
47
+ Tuple of (response_data, status_code)
48
+ """
49
+ def run(self) -> ActionResponse:
50
+ """Execute request and return paginated response.
51
+
52
+ Returns an ActionResponse that supports pagination for list responses.
53
+ For single item responses, pagination methods will return the same item.
54
+
55
+ Returns:
56
+ ActionResponse with pagination support
57
+ """
58
+
59
+ class Action:
60
+ """Base class for plugins to prepare action execution.
61
+
62
+ Example:
63
+ # Create a GitHub connector
64
+ github = bosa.connect('github')
65
+
66
+ # Execute with raw response
67
+ data, status = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .execute()
68
+
69
+ # Or with pagination support
70
+ response = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .run()
71
+ """
72
+ def __init__(self, module: BosaConnectorModule, authenticator: BaseAuthenticator) -> None:
73
+ """Initialize the action builder.
74
+
75
+ Args:
76
+ module: The connector module to use
77
+ authenticator: The authenticator to use for requests
78
+ """
79
+ def action(self, action: str) -> ActionExecutor:
80
+ """Create a new action executor for a service."""
@@ -0,0 +1,86 @@
1
+ from bosa_connectors.models.action import ActionResponseData as ActionResponseData, InitialExecutorRequest as InitialExecutorRequest
2
+ from bosa_connectors.models.file import ConnectorFile as ConnectorFile
3
+ from typing import Any, Callable
4
+
5
+ class ActionResponse:
6
+ '''Represents the response from an action execution.
7
+
8
+ Currently supports 2 pagination modes:
9
+ 1. Page-based pagination: Using page numbers (page=1, page=2, etc.)
10
+ 2. Cursor-based pagination: Using cursor tokens for forwards and backwards navigation
11
+
12
+ The class automatically detects which pagination mode to use based on the response metadata:
13
+ - If "forwards_cursor" and "backwards_cursor" are present, cursor-based pagination is used
14
+ - Otherwise, it falls back to page-based pagination using "page" parameter
15
+
16
+ Common pagination attributes:
17
+ - total: Total number of items
18
+ - total_page: Total number of pages
19
+ - has_next: Whether there is a next page
20
+ - has_prev: Whether there is a previous page
21
+
22
+ Followed by optional attributes
23
+ Cursor-based pagination attributes:
24
+ - forwards_cursor: Cursor for next page
25
+ - backwards_cursor: Cursor for previous page
26
+
27
+ Page-based pagination attributes:
28
+ - page: Current page number
29
+ - limit: Number of items per page
30
+
31
+ If the response is ConnectorFile, it will not support pagination and will return the file directly.
32
+ '''
33
+ def __init__(self, response_data: dict[str, Any] | ConnectorFile | None, status: int, response_creator: Callable[..., 'ActionResponse'], initial_executor_request: dict[str, Any]) -> None:
34
+ '''Initialize response wrapper.
35
+
36
+ Args:
37
+ response_data: Response data which could be:
38
+ - List response: {"data": [...], "meta": {...}}
39
+ - Single item response: {"data": {...}, "meta": {...}}
40
+ status: HTTP status code
41
+ response_creator: Callable to create a new ActionResponse
42
+ initial_executor_request: Initial action request attributes as dict
43
+ '''
44
+ def get_data(self) -> list[dict[str, Any]] | dict[str, Any] | ConnectorFile:
45
+ """Get the current page data.
46
+
47
+ Returns:
48
+ List of objects for paginated responses, or
49
+ Single object for single item responses
50
+ """
51
+ def get_meta(self) -> dict[str, Any]:
52
+ """Get the meta data."""
53
+ def get_status(self) -> int:
54
+ """Get the HTTP status code."""
55
+ def is_list(self) -> bool:
56
+ """Check if the response data is a list."""
57
+ def has_next(self) -> bool:
58
+ """Check if there is a next page.
59
+
60
+ Returns False if this is a single item response.
61
+ """
62
+ def has_prev(self) -> bool:
63
+ """Check if there is a previous page.
64
+
65
+ Returns False if this is a single item response.
66
+ """
67
+ def next_page(self) -> ActionResponse:
68
+ """Move to the next page and get the response.
69
+
70
+ Supports both page-based and cursor-based navigation:
71
+ 1. If forwards_cursor is available, uses cursor-based navigation
72
+ 2. Otherwise, falls back to page-based navigation
73
+
74
+ Returns self if this is a single item response or there is no next page.
75
+ """
76
+ def prev_page(self) -> ActionResponse:
77
+ """Move to the previous page and get the response.
78
+
79
+ Supports both page-based and cursor-based navigation:
80
+ 1. If backwards_cursor is available, uses cursor-based navigation
81
+ 2. Otherwise, falls back to page-based navigation
82
+
83
+ Returns self if this is a single item data or there is no previous page.
84
+ """
85
+ def get_all_items(self) -> list[Any]:
86
+ """Get all items from all pages."""
@@ -0,0 +1,4 @@
1
+ from .api_key import ApiKeyAuthenticator as ApiKeyAuthenticator
2
+ from .base import BaseAuthenticator as BaseAuthenticator
3
+
4
+ __all__ = ['BaseAuthenticator', 'ApiKeyAuthenticator']
@@ -0,0 +1,19 @@
1
+ from _typeshed import Incomplete
2
+ from bosa_connectors.auth.base import BaseAuthenticator as BaseAuthenticator
3
+
4
+ class ApiKeyAuthenticator(BaseAuthenticator):
5
+ """Injects API Key Headers to BOSA API for Authentication."""
6
+ API_KEY_HEADER: str
7
+ api_key: Incomplete
8
+ def __init__(self, api_key: str) -> None:
9
+ """Initializes the ApiKeyAuthenticator with the provided API key.
10
+
11
+ Args:
12
+ api_key (str): The API key for authentication.
13
+ """
14
+ def authenticate(self):
15
+ """Authenticates the request.
16
+
17
+ Raises:
18
+ AuthenticationError: If authentication fails.
19
+ """
@@ -0,0 +1,12 @@
1
+ import abc
2
+ from abc import ABC, abstractmethod
3
+
4
+ class BaseAuthenticator(ABC, metaclass=abc.ABCMeta):
5
+ """Base authenticator for BOSA API."""
6
+ @abstractmethod
7
+ def authenticate(self):
8
+ """Authenticates the request.
9
+
10
+ Raises:
11
+ AuthenticationError: If authentication fails.
12
+ """
@@ -0,0 +1,161 @@
1
+ from _typeshed import Incomplete
2
+ from bosa_connectors.action import Action as Action
3
+ from bosa_connectors.action_response import ActionResponse as ActionResponse
4
+ from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
5
+ from bosa_connectors.helpers.authenticator import BosaAuthenticator as BosaAuthenticator
6
+ from bosa_connectors.helpers.integrations import BosaIntegrationHelper as BosaIntegrationHelper
7
+ from bosa_connectors.models.file import ConnectorFile as ConnectorFile
8
+ from bosa_connectors.models.result import ActionResult as ActionResult
9
+ from bosa_connectors.models.token import BosaToken as BosaToken
10
+ from bosa_connectors.models.user import BosaUser as BosaUser, CreateUserResponse as CreateUserResponse
11
+ from bosa_connectors.module import BosaConnectorError as BosaConnectorError, BosaConnectorModule as BosaConnectorModule
12
+ from typing import Any
13
+
14
+ class BosaConnector:
15
+ """Main connector class that manages all BOSA connector modules."""
16
+ DEFAULT_TIMEOUT: int
17
+ DEFAULT_MAX_ATTEMPTS: int
18
+ OAUTH2_FLOW_ENDPOINT: str
19
+ INTEGRATION_CHECK_ENDPOINT: str
20
+ api_base_url: Incomplete
21
+ auth_scheme: Incomplete
22
+ bosa_authenticator: Incomplete
23
+ bosa_integration_helper: Incomplete
24
+ def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
25
+ """Initialization."""
26
+ def get_available_modules(self) -> list[str]:
27
+ """Scan and cache all available connector modules.
28
+
29
+ Returns:
30
+ List of available modules
31
+ """
32
+ def create_bosa_user(self, identifier: str) -> CreateUserResponse:
33
+ """Create a BOSA User in the scope of BOSA API.
34
+
35
+ Args:
36
+ identifier: BOSA Username
37
+
38
+ Returns:
39
+ BOSA User Data with the secret
40
+ """
41
+ def authenticate_bosa_user(self, identifier: str, secret: str) -> BosaToken:
42
+ """Triggers the authentication of the BOSA User in the scope of BOSA API.
43
+
44
+ Args:
45
+ identifier: BOSA Username
46
+ secret: BOSA Password
47
+
48
+ Returns:
49
+ BOSA User Token
50
+ """
51
+ def initiate_connector_auth(self, app_name: str, token: str, callback_uri: str) -> str:
52
+ """Triggers the OAuth2 flow for a connector for this API Key and User Token.
53
+
54
+ Args:
55
+ app_name: The name of the app/connector to use
56
+ token: The BOSA User Token
57
+ callback_uri: The callback URL to be used for the integration
58
+
59
+ Returns:
60
+ The redirect URL to be used for the integration
61
+ """
62
+ def get_user_info(self, token: str) -> BosaUser:
63
+ """Gets the user information for a given token.
64
+
65
+ Args:
66
+ token: The BOSA User Token
67
+
68
+ Returns:
69
+ BOSA User
70
+ """
71
+ def user_has_integration(self, app_name: str, token: str) -> bool:
72
+ """Checks whether or not a user has an integration for a given app in this client.
73
+
74
+ Args:
75
+ app_name: The name of the app/connector to use
76
+ token: The BOSA User Token
77
+
78
+ Returns:
79
+ True if the user has an integration for the given app
80
+ """
81
+ def remove_integration(self, app_name: str, token: str) -> ActionResult:
82
+ """Removes a 3rd party integration for a user against a certain client.
83
+
84
+ Args:
85
+ app_name: The name of the app/connector to use
86
+ token: The BOSA User Token
87
+
88
+ Returns:
89
+ Result that contains an error message (if any), and the success status.
90
+ """
91
+ def get_connector(self, app_name: str) -> BosaConnectorModule:
92
+ """Get or create an instance of a connector module.
93
+
94
+ Args:
95
+ app_name: The name of the app/connector to use
96
+
97
+ Returns:
98
+ BosaConnectorModule: The connector module
99
+ """
100
+ def refresh_connector(self, app_name: str) -> None:
101
+ """Refresh the connector module."""
102
+ def connect(self, app_name: str) -> Action:
103
+ """Connect to a specific module and prepare for action execution.
104
+
105
+ Creates an Action instance for the specified connector..
106
+
107
+ Example:
108
+ # Create action builders for different connectors
109
+ github = bosa.connect('github')
110
+ gdrive = bosa.connect('google_drive') # This is just an example
111
+
112
+ Args:
113
+ app_name: The name of the app/connector to use (eg: 'github', 'google_drive', etc)
114
+
115
+ Returns:
116
+ Action: A new Action instance for the specified connector
117
+ """
118
+ def execute(self, app_name: str, action: str, *, max_attempts: int = ..., input_: dict[str, Any] = None, token: str | None = None, headers: dict[str, str] | None = None, timeout: int | None = ..., **kwargs) -> tuple[dict[str, Any] | ConnectorFile, int]:
119
+ """Execute an action on a specific module and return raw response.
120
+
121
+ The method supports both ways of passing parameters:
122
+ 1. As a dictionary: execute(app_name, action, params_dict)
123
+ 2. As keyword arguments: execute(app_name, action, param1=value1, param2=value2)
124
+
125
+ Args:
126
+ app_name: The name of the app/connector to use
127
+ action: The action to execute
128
+ input_: Optional input data for the action
129
+ token: The BOSA User Token
130
+ headers: Optional headers to include in the request
131
+ max_attempts: The number of times the request can be retried for. Default is 0 (does not retry). Note that
132
+ the backoff factor is 2^(N - 1) with the basic value being 1 second (1, 2, 4, 8, 16, 32, ...).
133
+ Maximum number of retries is 10 with a maximum of 64 seconds per retry.
134
+ timeout: Optional timeout for the request in seconds. Default is 30 seconds.
135
+ **kwargs: Optional keyword arguments
136
+
137
+ Returns:
138
+ Tuple of (response, status_code) where response is the API response and status_code is the HTTP status code
139
+ """
140
+ def run(self, app_name: str, action: str, *, max_attempts: int = ..., input_: dict[str, Any] = None, token: str | None = None, headers: dict[str, str] | None = None, timeout: int | None = ..., **kwargs) -> ActionResponse:
141
+ """Execute an action on a specific module and return paginated response.
142
+
143
+ The method supports both ways of passing parameters:
144
+ 1. As a dictionary: execute(app_name, action, input_dict)
145
+ 2. As keyword arguments: execute(app_name, action, param1=value1, param2=value2)
146
+
147
+ Args:
148
+ app_name: The name of the app/connector to use
149
+ action: The action to execute
150
+ input_: Optional input data for the action
151
+ token: The BOSA User Token
152
+ headers: Optional headers to include in the request
153
+ max_attempts: The number of times the request can be retried for. Default is 0 (does not retry). Note that
154
+ the backoff factor is 2^(N - 1) with the basic value being 1 second (1, 2, 4, 8, 16, 32, ...).
155
+ Maximum number of retries is 10 with a maximum of 64 seconds per retry.
156
+ timeout: Optional timeout for the request in seconds. Default is 30 seconds.
157
+ **kwargs: Optional keyword arguments
158
+
159
+ Returns:
160
+ ActionResponse: Response wrapper with pagination support
161
+ """
File without changes
@@ -0,0 +1,45 @@
1
+ from _typeshed import Incomplete
2
+ from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
3
+ from bosa_connectors.models.token import BosaToken as BosaToken
4
+ from bosa_connectors.models.user import BosaUser as BosaUser, CreateUserResponse as CreateUserResponse
5
+
6
+ class BosaAuthenticator:
7
+ """Authenticator for BOSA API."""
8
+ DEFAULT_TIMEOUT: int
9
+ api_base_url: Incomplete
10
+ auth_scheme: Incomplete
11
+ def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
12
+ '''Initialize the BosaAuthenticator with the provided API key.
13
+
14
+ Args:
15
+ api_base_url (str): The base URL for the BOSA API. Defaults to "https://api.bosa.id".
16
+ api_key (str): The API key for authentication. Defaults to "bosa".
17
+ '''
18
+ def register(self, identifier: str) -> CreateUserResponse:
19
+ """Register a BOSA User in the scope of BOSA API.
20
+
21
+ Args:
22
+ identifier: BOSA Username
23
+
24
+ Returns:
25
+ BOSA User Data with the secret
26
+ """
27
+ def authenticate(self, identifier: str, secret: str) -> BosaToken:
28
+ """Authenticate a BOSA User in the scope of BOSA API.
29
+
30
+ Args:
31
+ identifier: BOSA Username
32
+ secret: BOSA Password
33
+
34
+ Returns:
35
+ BOSA User Token
36
+ """
37
+ def get_user(self, token: str) -> BosaUser:
38
+ """Get the current user from BOSA API.
39
+
40
+ Args:
41
+ token: The BOSA User Token
42
+
43
+ Returns:
44
+ BOSA User
45
+ """
@@ -0,0 +1,49 @@
1
+ from _typeshed import Incomplete
2
+ from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
3
+ from bosa_connectors.models.result import ActionResult as ActionResult
4
+
5
+ class BosaIntegrationHelper:
6
+ """Helper class for BOSA API integrations."""
7
+ OAUTH2_FLOW_ENDPOINT: str
8
+ INTEGRATION_CHECK_ENDPOINT: str
9
+ DEFAULT_TIMEOUT: int
10
+ api_base_url: Incomplete
11
+ auth_scheme: Incomplete
12
+ def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
13
+ '''Initializes the BosaIntegrationHelper with the provided API key.
14
+
15
+ Args:
16
+ api_base_url (str): The base URL for the BOSA API. Defaults to "https://api.bosa.id".
17
+ api_key (str): The API key for authentication. Defaults to "bosa".
18
+ '''
19
+ def user_has_integration(self, app_name: str, token: str) -> bool:
20
+ """Checks whether or not a user has an integration for a given app in this client.
21
+
22
+ Args:
23
+ app_name: The name of the app/connector to use
24
+ token: The BOSA User Token
25
+
26
+ Returns:
27
+ True if the user has an integration for the given app
28
+ """
29
+ def initiate_integration(self, app_name: str, token: str, callback_uri: str) -> str:
30
+ """Initiates a 3rd party integration for a user against a certain client.
31
+
32
+ Args:
33
+ app_name: The name of the app/connector to use
34
+ token: The BOSA User Token
35
+ callback_uri: The callback URL to be used for the integration
36
+
37
+ Returns:
38
+ The integration URL
39
+ """
40
+ def remove_integration(self, app_name: str, token: str) -> ActionResult:
41
+ """Removes a 3rd party integration for a user against a certain client.
42
+
43
+ Args:
44
+ app_name: The name of the app/connector to use
45
+ token: The BOSA User Token
46
+
47
+ Returns:
48
+ Result that contains an error message (if any), and the success status.
49
+ """
File without changes
@@ -0,0 +1,16 @@
1
+ from bosa_connectors.models.file import ConnectorFile as ConnectorFile
2
+ from pydantic import BaseModel
3
+ from typing import Any
4
+
5
+ class ActionResponseData(BaseModel):
6
+ """Response data model with data and meta information."""
7
+ data: list[Any] | dict[str, Any] | ConnectorFile
8
+ meta: dict[str, Any] | None
9
+
10
+ class InitialExecutorRequest(BaseModel):
11
+ """Initial executor request model."""
12
+ params: dict[str, Any]
13
+ headers: dict[str, str] | None
14
+ max_attempts: int | None
15
+ token: str | None
16
+ timeout: int | None
@@ -0,0 +1,8 @@
1
+ from pydantic import BaseModel
2
+
3
+ class ConnectorFile(BaseModel):
4
+ """Model for a file in a BOSA Connector request or response."""
5
+ file: bytes
6
+ filename: str | None
7
+ content_type: str | None
8
+ headers: dict[str, str] | None
@@ -0,0 +1,6 @@
1
+ from pydantic import BaseModel
2
+
3
+ class ActionResult(BaseModel):
4
+ """Model for an action result."""
5
+ success: bool
6
+ message: str
@@ -0,0 +1,10 @@
1
+ from pydantic import BaseModel
2
+
3
+ class BosaToken(BaseModel):
4
+ """Model for a BOSA Token."""
5
+ token: str
6
+ token_type: str
7
+ expires_at: str
8
+ is_revoked: bool
9
+ user_id: str
10
+ client_id: str
@@ -0,0 +1,27 @@
1
+ from pydantic import BaseModel
2
+ from uuid import UUID
3
+
4
+ class ThirdPartyIntegrationAuthBasic(BaseModel):
5
+ """Basic model for a third party integration authentication."""
6
+ id: UUID
7
+ client_id: UUID
8
+ user_id: UUID
9
+ connector: str
10
+ user_identifier: str
11
+
12
+ class BosaUser(BaseModel):
13
+ """Model for a BOSA User."""
14
+ id: UUID
15
+ client_id: UUID
16
+ identifier: str
17
+ secret_preview: str
18
+ is_active: bool
19
+ integrations: list[ThirdPartyIntegrationAuthBasic]
20
+
21
+ class CreateUserResponse(BaseModel):
22
+ """Model for a BOSA User creation response."""
23
+ id: UUID
24
+ identifier: str
25
+ secret: str
26
+ secret_preview: str
27
+ is_active: bool
@@ -0,0 +1,76 @@
1
+ from _typeshed import Incomplete
2
+ from bosa_connectors.auth import BaseAuthenticator as BaseAuthenticator
3
+ from bosa_connectors.models.file import ConnectorFile as ConnectorFile
4
+ from pydantic import BaseModel as BaseModel
5
+ from typing import Any
6
+
7
+ class BosaConnectorError(Exception):
8
+ """Base exception for BOSA connector errors."""
9
+
10
+ class BosaConnectorModule:
11
+ """Base class for all BOSA connector modules."""
12
+ app_name: str
13
+ DEFAULT_TIMEOUT: int
14
+ MAX_RETRY: int
15
+ MAX_BACKOFF_SECONDS: int
16
+ INFO_PATH: str
17
+ EXCLUDED_ENDPOINTS: Incomplete
18
+ @staticmethod
19
+ def is_retryable_error(status_code: int) -> bool:
20
+ """Check if the status code indicates a retryable error (429 or 5xx).
21
+
22
+ Args:
23
+ status_code: HTTP status code to check
24
+
25
+ Returns:
26
+ bool: True if the error is retryable
27
+ """
28
+ api_base_url: Incomplete
29
+ info_path: Incomplete
30
+ def __init__(self, app_name: str, api_base_url: str = 'https://api.bosa.id', info_path: str = ...) -> None:
31
+ """Initialize a new connector module.
32
+
33
+ This constructor should only be called by BosaConnector.
34
+ """
35
+ def get_actions(self) -> list[tuple[str, str, str]]:
36
+ """Return list of available actions for this module."""
37
+ def get_action_parameters(self, action: str):
38
+ """Get flattened parameter information for an action.
39
+
40
+ Args:
41
+ action: The action endpoint
42
+
43
+ Returns:
44
+ List of parameter info dicts with name, type, and required fields.
45
+ Nested objects are flattened using dot notation, e.g.:
46
+ object.attr1, object.attr2, object.attr3.attr21
47
+ """
48
+ def validate_request(self, action: str, params: dict[str, Any]) -> tuple[dict[str, Any] | None, dict[str, str]]:
49
+ """Validate and clean request parameters.
50
+
51
+ Args:
52
+ action: The action endpoint
53
+ params: Dict of parameter values
54
+
55
+ Returns:
56
+ Tuple of (cleaned_params, error_details) where error_details is empty if validation passed
57
+ """
58
+ def execute(self, action: str, max_attempts: int, input_: dict = None, token: str | None = None, authenticator: BaseAuthenticator | None = None, headers: dict[str, str] | None = None, timeout: int | None = ...) -> tuple[dict[str, Any] | ConnectorFile, int]:
59
+ """Execute an action with validated parameters and return typed response.
60
+
61
+ Args:
62
+ action: The action to execute
63
+ max_attempts: Maximum number of attempts for failed requests (429 or 5xx errors). Must be at least 1.
64
+ Will be capped at MAX_RETRY (10) to prevent excessive retries.
65
+ input_: Optional dictionary of parameters
66
+ token: Optional BOSA User Token. If not provided, will use the default token
67
+ authenticator: Optional authenticator to use for the request
68
+ headers: Optional headers to include in the request
69
+
70
+ The method supports both ways of passing parameters:
71
+ 1. As a dictionary: execute(action, params_dict)
72
+ 2. As keyword arguments: execute(action, param1=value1, param2=value2)
73
+
74
+ Raises:
75
+ ValueError: If action is invalid, parameters are invalid, or max_attempts is less than 1
76
+ """
@@ -0,0 +1 @@
1
+ *
bosa_connectors.pyi ADDED
@@ -0,0 +1,26 @@
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 connector import BosaConnector
7
+
8
+
9
+ __name__ = ...
10
+
11
+
12
+
13
+ # Modules used internally, to allow implicit dependencies to be seen:
14
+ import os
15
+ import typing
16
+ import bosa_connectors.auth.BaseAuthenticator
17
+ import abc
18
+ import logging
19
+ import requests
20
+ import requests.exceptions
21
+ import bosa_connectors.auth.ApiKeyAuthenticator
22
+ import pydantic
23
+ import uuid
24
+ import cgi
25
+ import random
26
+ import time
@@ -0,0 +1,362 @@
1
+ Metadata-Version: 2.1
2
+ Name: bosa-connectors-binary
3
+ Version: 0.0.7.post1
4
+ Summary: BOSA Connectors
5
+ Author: Bosa Engineers
6
+ Author-email: bosa-eng@gdplabs.id
7
+ Requires-Python: >=3.11
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: pydantic (>=2.9.2,<3.0.0)
15
+ Requires-Dist: requests (>=2.31.0,<3.0.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # BOSA API SDK (Bosa Connector)
19
+
20
+ 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.
21
+
22
+ ## Features
23
+
24
+ - Simple and intuitive API for connecting to BOSA-compatible services
25
+ - Automatic endpoint discovery and schema validation
26
+ - Built-in authentication support (BOSA API Key and User Token)
27
+ - User management and OAuth2 integration flow support
28
+ - Type-safe parameter validation
29
+ - Flexible parameter passing (dictionary or keyword arguments)
30
+ - Retry support for requests that fail (429 or 5xx)
31
+ - Response fields filtering based on action and output
32
+
33
+ ## Installation
34
+
35
+ To install the BOSA Connectors, you need to specify the following in your `pyproject.toml` file:
36
+
37
+ ```toml
38
+ [tool.poetry.dependencies]
39
+ bosa-connectors = { git = "ssh://git@github.com/GDP-ADMIN/bosa.git", branch = "bosa-python-connectors-0.0.3", subdirectory = "python/bosa-connectors" }
40
+ ```
41
+
42
+ ## Quick Start
43
+
44
+ Here's a simple example of how to use the BOSA Connector with API key authentication and user token.
45
+
46
+ ### Initialization
47
+
48
+ Before using the connector, you need to initialize it with your BOSA API base URL and API key.
49
+
50
+ ```python
51
+ from bosa_connectors.connector import BosaConnector
52
+
53
+ # Initialize the connector
54
+ bosa = BosaConnector(api_base_url="YOUR_BOSA_API_BASE_URL", api_key="YOUR_API_KEY")
55
+ ```
56
+
57
+ ### Authentication
58
+
59
+ After initializing the connector, you can authenticate with your BOSA API key.
60
+
61
+ ```python
62
+ # User token from authentication
63
+ user_token = "Enter your key here from authentication, or refer to User Authentication section below"
64
+
65
+ # Check if a user has an integration for a connector
66
+ has_integration = bosa.user_has_integration("github", user_token)
67
+
68
+ if not has_integration:
69
+ # Initiate the OAuth2 flow for a connector
70
+ auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
71
+ # Redirect the user to auth_url to complete authentication, we exit here.
72
+ print("Integration with GitHub not found.")
73
+ print(f"Please visit {auth_url} to complete authentication.")
74
+ exit()
75
+ ```
76
+
77
+ Alternatively, you can authenticate the user first and then use their token:
78
+
79
+ ```python
80
+ user = bosa.authenticate_bosa_user("username", "password")
81
+
82
+ # Get user token
83
+ user_token = user.token
84
+ ```
85
+
86
+ ### Basic Example (Direct Execution)
87
+
88
+ 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:
89
+
90
+ ```python
91
+ # Prepare input parameters
92
+ params = {
93
+ "owner": "gdp-admin",
94
+ "author": "samuellusandi",
95
+ "per_page": 1,
96
+ "sort": "author_date",
97
+ "created_date_start": "2025-02-01",
98
+ "created_date_end": "2025-02-02"
99
+ }
100
+
101
+ # Execute the action with user token
102
+ data, status = bosa.execute("github", "search_commits", token=user_token, max_attempts=1, input_=params)
103
+
104
+ # Print the result
105
+ print(data)
106
+ print(status)
107
+ ```
108
+
109
+ ### Alternative Approach (Fluent Interface)
110
+
111
+ For more complex scenarios or more control over the execution, you can use the fluent interface. We're recommending this approach if you:
112
+
113
+ - Need to execute multiple actions with different parameters
114
+ - Expecting list response
115
+ - Need to execute actions in a loop
116
+
117
+ ```python
118
+ # Prepare input parameters
119
+ params = {
120
+ "owner": "gdp-admin",
121
+ "author": "samuellusandi",
122
+ "per_page": 1,
123
+ "sort": "author_date",
124
+ "created_date_start": "2025-02-01",
125
+ "created_date_end": "2025-02-02"
126
+ }
127
+
128
+ # Create a connector instance to a service
129
+ github = bosa.connect('github')
130
+
131
+ # Execute actions with fluent interface
132
+ response = github.action('list_pull_requests')\
133
+ .params(params)\
134
+ .max_attempts(3)\
135
+ .token('user-token')\
136
+ .run() # Execute and return ActionResponse for advanced data handling
137
+
138
+ # Get initial data
139
+ initial_data = response.get_data()
140
+
141
+ # Iterate the following next pages
142
+ while response.has_next():
143
+ response = response.next_page()
144
+ data = response.get_data()
145
+ # Process data here
146
+ ...
147
+
148
+ # You can also navigate backwards
149
+ while response.has_prev():
150
+ response = response.prev_page()
151
+ data = response.get_data()
152
+ # Process data here
153
+ ...
154
+
155
+ # Execute multiple independent actions using the same connector instance
156
+ commits_response = github.action('list_commits')\
157
+ .params({
158
+ 'owner': 'GDP-ADMIN',
159
+ 'repo': 'bosa',
160
+ 'page': 1,
161
+ 'per_page': 10
162
+ })\
163
+ .token('user-token')\
164
+ .run()
165
+ ```
166
+
167
+ `run` method also available for direct execution from connector instance, without using fluent interface.
168
+
169
+ ```python
170
+ # Prepare input parameters
171
+ params = {
172
+ "owner": "gdp-admin",
173
+ "author": "samuellusandi",
174
+ "per_page": 1,
175
+ "sort": "author_date",
176
+ "created_date_start": "2025-02-01",
177
+ "created_date_end": "2025-02-02"
178
+ }
179
+
180
+ # Execute actions with run method
181
+ response = bosa.run('github', 'list_pull_requests', params)
182
+ print(response.get_data())
183
+ ```
184
+
185
+ ### Working with Files using ConnectorFile
186
+
187
+ When working with APIs that require file uploads or return file downloads, use the `ConnectorFile` model:
188
+
189
+ ```python
190
+ from bosa_connectors.models.file import ConnectorFile
191
+
192
+ # For uploads: Create a ConnectorFile object
193
+ with open("document.pdf", "rb") as f:
194
+ upload_file = ConnectorFile(
195
+ file=f.read(),
196
+ filename="document.pdf",
197
+ content_type="application/pdf"
198
+ )
199
+
200
+ params = {
201
+ "file": upload_file,
202
+ "name": "My Document"
203
+ }
204
+
205
+ # Include in your parameters
206
+ result, status = bosa.execute("google_drive", "upload_file", input_=params)
207
+
208
+ # For downloads: Check response type
209
+ file_result, status = bosa.execute("google_drive", "download_file", input_={"file_id": "123"})
210
+ if isinstance(file_result, ConnectorFile):
211
+ # Save to disk
212
+ with open(file_result.filename or "downloaded_file", "wb") as f:
213
+ f.write(file_result.file)
214
+ ```
215
+
216
+ ## Available Methods
217
+
218
+ ### Connector Instance Methods
219
+
220
+ The connector instance provides several methods for configuring and executing actions:
221
+
222
+ - `connect(name)`: Create a connector instance to a service
223
+ - `action(name)`: Specify the action to execute
224
+ - `params(dict)`: Set request parameters (including pagination parameters like page and per_page). Note that params for each plugin and action could be different
225
+ - `token(str)`: Set the BOSA user token
226
+ - `headers(dict)`: Set custom request headers
227
+ - `max_attempts(number)`: Set the maximum number of retry attempts (default: 1)
228
+ Execution Methods:
229
+
230
+ - `run()`: Execute and return ActionResponse for advanced data handling
231
+ - `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).
232
+
233
+ ### Response Handling (ActionResponse)
234
+
235
+ The ActionResponse class provides methods for handling the response and pagination:
236
+
237
+ - `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).
238
+ - `get_meta()`: Get the metadata information from the response (e.g., pagination details, total count)
239
+ - `get_status()`: Get the HTTP status code
240
+ - `is_list()`: Check if response is a list
241
+ - `has_next()`: Check if there is a next page
242
+ - `has_prev()`: Check if there is a previous page
243
+ - `next_page()`: Move to and execute next page
244
+ - `prev_page()`: Move to and execute previous page
245
+ - `get_all_items()`: Get all items from all pages (returns a list of objects containing data and meta for each page)
246
+
247
+ ## Data Models
248
+
249
+ The SDK uses the following data models:
250
+
251
+ - `ActionResponseData`: Contains the response data structure with `data` (list, object, or ConnectorFile instance) and `meta` (metadata) fields
252
+ - `InitialExecutorRequest`: Stores the initial request parameters used for pagination and subsequent requests
253
+ - `ConnectorFile`: Represents a file in requests and responses with these properties:
254
+ - `file`: Raw bytes content of the file
255
+ - `filename`: Optional name of the file
256
+ - `content_type`: Optional MIME type of the file
257
+ - `headers`: Optional HTTP headers for the file
258
+
259
+ ## Configuration Parameters
260
+
261
+ - `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.
262
+ - `api_key`: Your BOSA API key for authentication. This is different from plugin-specific API keys, which are managed separately by the BOSA system.
263
+
264
+ ## Execution Parameters
265
+
266
+ - `connector`: The name of the connector to use. This parameter is used to determine the connector's available actions and their parameters.
267
+ - `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.
268
+ - `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.
269
+ - The retries are handled automatically by the connector, with exponential backoff.
270
+ - The retries are only done for errors that are considered retryable (429 or 5xx).
271
+ - `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.
272
+ - 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:
273
+ ```json
274
+ {
275
+ "user": {
276
+ "login": "userlogin"
277
+ }
278
+ }
279
+ ```
280
+ - `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.
281
+
282
+ ## How It Works
283
+
284
+ 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.
285
+
286
+ 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.
287
+
288
+ 3. **Execution**: When you call `execute()`, the connector:
289
+ - Validates your input parameters against the action's schema
290
+ - Handles authentication
291
+ - Makes the API request
292
+ - Returns the formatted response
293
+
294
+ ## Compatibility
295
+
296
+ 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:
297
+
298
+ 1. Exposes an endpoint listing available actions and their parameters
299
+ 2. Follows BOSA's standard HTTP Interface specifications (through the Plugin Architecture)
300
+ - All actions must be exposed as `POST` endpoints.
301
+ 3. Implements the required authentication mechanisms
302
+
303
+ ## Error Handling
304
+
305
+ The connector includes built-in error handling for:
306
+
307
+ - Invalid parameters
308
+ - Authentication failures
309
+ - Connection issues
310
+ - API response errors
311
+
312
+ ## User Authentication
313
+
314
+ The BOSA Connector supports user-based authentication which allows for user-specific actions and third-party integrations:
315
+
316
+ ```python
317
+ # Create a new BOSA user
318
+ user_data = bosa.create_bosa_user("username")
319
+ # Save the secret for later use
320
+ user_secret = user_data.secret
321
+
322
+ # Authenticate a user and get their token
323
+ token = bosa.authenticate_bosa_user("username", user_secret)
324
+
325
+ # Get user information
326
+ user_info = bosa.get_user_info(token.token)
327
+ ```
328
+
329
+ ## Integration Management
330
+
331
+ The BOSA Connector provides methods to manage third-party integrations for authenticated users:
332
+
333
+ ```python
334
+ # Check if a user has an integration for a connector
335
+ has_integration = bosa.user_has_integration("github", user_token)
336
+
337
+ # Initiate the OAuth2 flow for a connector
338
+ auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
339
+ # Redirect the user to auth_url to complete authentication
340
+
341
+ # Remove an integration
342
+ remove_result = bosa.remove_integration("github", user_token)
343
+ ```
344
+
345
+ ## References
346
+
347
+ Product Requirements Documents(PRD):
348
+
349
+ - [BOSA Connector - Product Document](https://docs.google.com/document/d/1R6JIGWnKzNg2kRMRSiZ-wwPGe9pOR9rkkEI0Uz-Wtdw/edit?tab=t.y617gs6jfk15#heading=h.uss0d453lcbs)
350
+
351
+ Architecture Documents:
352
+
353
+ - [BOSA Connector - Architecture Document](https://docs.google.com/document/d/1HHUBAkbFAM8sM_Dtx6tmoatR1HeuM6VBfsWEjpgVCtg/edit?tab=t.0#heading=h.bj79ljx9eqg8)
354
+
355
+ Design Documents:
356
+
357
+ - [BOSA Connector - Design Document](https://docs.google.com/document/d/1PghW7uOJcEbT3WNSlZ0FI99o4y24ys0LCyAG8hg3T9o/edit?tab=t.0#heading=h.bj79ljx9eqg8)
358
+
359
+ Implementation Documents:
360
+
361
+ - [BOSA Connector - Implementation Document](https://docs.google.com/document/d/1a8BvggPu5a6PBStgUu2ILse075FjAAgoehUuvxxAajM/edit?tab=t.0#heading=h.bj79ljx9eqg8)
362
+
@@ -0,0 +1,23 @@
1
+ bosa_connectors/__init__.pyi,sha256=dke2VapQq8neoGW57C-GdrtQCt5-9V51qG33R3C2I0E,279
2
+ bosa_connectors/action.pyi,sha256=zGqRYx9bD7H0V4cMKwF83OLlwuVaDd_Oi4LG7gp7Lfc,3358
3
+ bosa_connectors/action_response.pyi,sha256=8Dj8YZsgvS6hGS-wyb-4VUxZzNLZqisCouYe3V9_DKY,3674
4
+ bosa_connectors/auth/__init__.pyi,sha256=gpzI0J6hSddF7xEZ7j5M1Lcy-MaICCTj5dJFhcaqxXc,177
5
+ bosa_connectors/auth/api_key.pyi,sha256=uFKPef2dqRaQ-2N-3J1kYU3Oh-PsDuh4q2_3jB2KSNY,630
6
+ bosa_connectors/auth/base.pyi,sha256=hjN2euyXyAuFGsxClgIFz_pOy-Q9jV3-vUcinZ-3J-Q,317
7
+ bosa_connectors/connector.pyi,sha256=CARDA0JaXJkwbvHmqfAHq4VMhaQhPxgW6eH7ZmPxi20,7279
8
+ bosa_connectors/helpers/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ bosa_connectors/helpers/authenticator.pyi,sha256=QwsQ1a0U4Ah2Wg4xnco9Rf2jIsF7EYPvhSyUxxPpStk,1521
10
+ bosa_connectors/helpers/integrations.pyi,sha256=v2PkmsotlT8eo3RAB7hiIC30BN3MN5BO8UjeCRoDu6Q,1961
11
+ bosa_connectors/models/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ bosa_connectors/models/action.pyi,sha256=Ru4n0xZflIp8Pjoqq-9eJoaDCacrWIA0OvMXmFwOZ7w,531
13
+ bosa_connectors/models/file.pyi,sha256=PBZZkodDAeW1oysX5R5pJ9-d8yd5eKWVccAh1oYcjXM,237
14
+ bosa_connectors/models/result.pyi,sha256=ISmHBFlkyVzyAxeQXwVVEqNXd4SZQI4YV1vd8i8S-NM,136
15
+ bosa_connectors/models/token.pyi,sha256=NN7VfzoudeojK5oWVUmCi4Qo02RUjbveKzDpbh1RrGU,206
16
+ bosa_connectors/models/user.pyi,sha256=KsVrc0MYB1z6fikCv1qSrjnP8ISWChxr9Fx0T0nbsKw,661
17
+ bosa_connectors/module.pyi,sha256=O72bNcKGdfDL5yZzkUOth4BXTDjyUg4YAhYn2TiEgKs,3277
18
+ bosa_connectors.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
19
+ bosa_connectors.cpython-312-x86_64-linux-gnu.so,sha256=02iqwhH44PM-pDrW3sFZeETW3mPDEW_WiQ_f4E7ZZdg,1348488
20
+ bosa_connectors.pyi,sha256=GpJC_3rac6Hzg8IhYq8D-OVxsnF2zP9XMrf34YtWOK0,549
21
+ bosa_connectors_binary-0.0.7.post1.dist-info/METADATA,sha256=5pWs9HLFBL1Z8o7UNlV_zae-5AZPhra_9cV069DeYFg,13813
22
+ bosa_connectors_binary-0.0.7.post1.dist-info/WHEEL,sha256=mNY4pwQL4AOAoPmLYEQs2SSpMIbATFeiJFktRD5iKkY,110
23
+ bosa_connectors_binary-0.0.7.post1.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: cp312-cp312-manylinux_2_31_x86_64