Skip to main content

BOSA Connectors

Project description

BOSA API SDK (Bosa Connector)

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.

Features

  • Simple and intuitive API for connecting to BOSA-compatible services
  • Automatic endpoint discovery and schema validation
  • Built-in authentication support (BOSA API Key and User Token)
  • User management and OAuth2 integration flow support
  • Type-safe parameter validation
  • Flexible parameter passing (dictionary or keyword arguments)
  • Retry support for requests that fail (429 or 5xx)
  • Response fields filtering based on action and output

Installation

Prerequisites

1. Installation from Pypi

Choose one of the following methods to install the package:

Using pip

pip install bosa-connectors-binary

Using Poetry

poetry add bosa-connectors-binary

2. Development Installation (Git)

For development purposes, you can install directly from the Git repository:

poetry add "git+ssh://git@github.com/GDP-ADMIN/bosa-sdk.git#subdirectory=python/bosa-connectors"

Quick Start

Here's a simple example of how to use the BOSA Connector with API key authentication and user token.

Initialization

Before using the connector, you need to initialize it with your BOSA API base URL and API key.

from bosa_connectors.connector import BosaConnector

# Initialize the connector
bosa = BosaConnector(api_base_url="YOUR_BOSA_API_BASE_URL", api_key="YOUR_API_KEY")

Authentication

After initializing the connector, you can authenticate with your BOSA API key.

# User token from authentication
user_token = "Enter your key here from authentication, or refer to User Authentication section below"

# Check if a user has an integration for a connector
has_integration = bosa.user_has_integration("github", user_token)

if not has_integration:
    # Initiate the OAuth2 flow for a connector
    auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
    # Redirect the user to auth_url to complete authentication, we exit here.
    print("Integration with GitHub not found.")
    print(f"Please visit {auth_url} to complete authentication.")
    exit()

Alternatively, you can authenticate the user first and then use their token:

user = bosa.authenticate_bosa_user("username", "password")

# Get user token
user_token = user.token

Basic Example (Direct Execution)

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:

# Prepare input parameters
params = {
    "owner": "gdp-admin",
    "author": "samuellusandi",
    "per_page": 1,
    "sort": "author_date",
    "created_date_start": "2025-02-01",
    "created_date_end": "2025-02-02"
}

# Execute the action with user token
data, status = bosa.execute("github", "search_commits", token=user_token, max_attempts=1, input_=params)

# Print the result
print(data)
print(status)

Alternative Approach (Fluent Interface)

For more complex scenarios or more control over the execution, you can use the fluent interface. We're recommending this approach if you:

  • Need to execute multiple actions with different parameters
  • Expecting list response
  • Need to execute actions in a loop
# Prepare input parameters
params = {
    "owner": "gdp-admin",
    "author": "samuellusandi",
    "per_page": 1,
    "sort": "author_date",
    "created_date_start": "2025-02-01",
    "created_date_end": "2025-02-02"
}

# Create a connector instance to a service
github = bosa.connect('github')

# Execute actions with fluent interface
response = github.action('list_pull_requests')\
    .params(params)\
    .max_attempts(3)\
    .token('user-token')\
    .run()  # Execute and return ActionResponse for advanced data handling

# Get initial data
initial_data = response.get_data()

# Iterate the following next pages
while response.has_next():
    response = response.next_page()
    data = response.get_data()
    # Process data here
    ...

# You can also navigate backwards
while response.has_prev():
    response = response.prev_page()
    data = response.get_data()
    # Process data here
    ...

# Execute multiple independent actions using the same connector instance
commits_response = github.action('list_commits')\
    .params({
        'owner': 'GDP-ADMIN',
        'repo': 'bosa',
        'page': 1,
        'per_page': 10
    })\
    .token('user-token')\
    .run()

run method also available for direct execution from connector instance, without using fluent interface.

# Prepare input parameters
params = {
    "owner": "gdp-admin",
    "author": "samuellusandi",
    "per_page": 1,
    "sort": "author_date",
    "created_date_start": "2025-02-01",
    "created_date_end": "2025-02-02"
}

# Execute actions with run method
response = bosa.run('github', 'list_pull_requests', params)
print(response.get_data())

Working with Files using ConnectorFile

When working with APIs that require file uploads or return file downloads, use the ConnectorFile model:

from bosa_connectors.models.file import ConnectorFile

# For uploads: Create a ConnectorFile object
with open("document.pdf", "rb") as f:
    upload_file = ConnectorFile(
        file=f.read(),
        filename="document.pdf",
        content_type="application/pdf"
    )

params = {
  "file": upload_file,
  "name": "My Document"
}

# Include in your parameters
result, status = bosa.execute("google_drive", "upload_file", input_=params)

# For downloads: Check response type
file_result, status = bosa.execute("google_drive", "download_file", input_={"file_id": "123"})
if isinstance(file_result, ConnectorFile):
    # Save to disk
    with open(file_result.filename or "downloaded_file", "wb") as f:
        f.write(file_result.file)

Available Methods

Connector Instance Methods

The connector instance provides several methods for configuring and executing actions:

  • connect(name): Create a connector instance to a service

  • action(name): Specify the action to execute

  • params(dict): Set request parameters (including pagination parameters like page and per_page). Note that params for each plugin and action could be different

  • token(str): Set the BOSA user token

  • headers(dict): Set custom request headers

  • max_attempts(number): Set the maximum number of retry attempts (default: 1) Execution Methods:

  • run(): Execute and return ActionResponse for advanced data handling

  • 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).

Response Handling (ActionResponse)

The ActionResponse class provides methods for handling the response and pagination:

  • 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).
  • get_meta(): Get the metadata information from the response (e.g., pagination details, total count)
  • get_status(): Get the HTTP status code
  • is_list(): Check if response is a list
  • has_next(): Check if there is a next page
  • has_prev(): Check if there is a previous page
  • next_page(): Move to and execute next page
  • prev_page(): Move to and execute previous page
  • get_all_items(): Get all items from all pages (returns a list of objects containing data and meta for each page)

Data Models

The SDK uses the following data models:

  • ActionResponseData: Contains the response data structure with data (list, object, or ConnectorFile instance) and meta (metadata) fields
  • InitialExecutorRequest: Stores the initial request parameters used for pagination and subsequent requests
  • ConnectorFile: Represents a file in requests and responses with these properties:
    • file: Raw bytes content of the file
    • filename: Optional name of the file
    • content_type: Optional MIME type of the file
    • headers: Optional HTTP headers for the file

Configuration Parameters

  • 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.
  • api_key: Your BOSA API key for authentication. This is different from plugin-specific API keys, which are managed separately by the BOSA system.

Execution Parameters

  • connector: The name of the connector to use. This parameter is used to determine the connector's available actions and their parameters.
  • 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.
  • 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.
    • The retries are handled automatically by the connector, with exponential backoff.
    • The retries are only done for errors that are considered retryable (429 or 5xx).
  • 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.
    • 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:
    {
      "user": {
        "login": "userlogin"
      }
    }
    
  • 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.

How It Works

  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.

  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.

  3. Execution: When you call execute(), the connector:

    • Validates your input parameters against the action's schema
    • Handles authentication
    • Makes the API request
    • Returns the formatted response

Compatibility

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:

  1. Exposes an endpoint listing available actions and their parameters
  2. Follows BOSA's standard HTTP Interface specifications (through the Plugin Architecture)
    • All actions must be exposed as POST endpoints.
  3. Implements the required authentication mechanisms

Error Handling

The connector includes built-in error handling for:

  • Invalid parameters
  • Authentication failures
  • Connection issues
  • API response errors

User Authentication

The BOSA Connector supports user-based authentication which allows for user-specific actions and third-party integrations:

# Create a new BOSA user
user_data = bosa.create_bosa_user("username")
# Save the secret for later use
user_secret = user_data.secret

# Authenticate a user and get their token
token = bosa.authenticate_bosa_user("username", user_secret)

# Get user information
user_info = bosa.get_user_info(token.token)

Integration Management

The BOSA Connector provides methods to manage third-party integrations for authenticated users:

# Check if a user has an integration for a connector
has_integration = bosa.user_has_integration("github", user_token)

# Initiate the OAuth2 flow for a connector
auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
# Redirect the user to auth_url to complete authentication

# Remove an integration
remove_result = bosa.remove_integration("github", user_token)

References

Product Requirements Documents(PRD):

Architecture Documents:

Design Documents:

Implementation Documents:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bosa_connectors_binary-0.0.10-cp312-cp312-win_amd64.whl (346.2 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_connectors_binary-0.0.10-cp312-cp312-manylinux_2_31_x86_64.whl (525.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_connectors_binary-0.0.10-cp312-cp312-macosx_14_0_arm64.whl (316.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

bosa_connectors_binary-0.0.10-cp312-cp312-macosx_13_0_x86_64.whl (355.1 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

bosa_connectors_binary-0.0.10-cp311-cp311-win_amd64.whl (347.2 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_connectors_binary-0.0.10-cp311-cp311-manylinux_2_31_x86_64.whl (475.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_connectors_binary-0.0.10-cp311-cp311-macosx_14_0_arm64.whl (312.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

bosa_connectors_binary-0.0.10-cp311-cp311-macosx_13_0_x86_64.whl (348.0 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

File details

Details for the file bosa_connectors_binary-0.0.10-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a4f65a405ec57fa0ac2a4721cf19f6cbc0a4734ace7d7041d37b4644ab66a2c9
MD5 aad1ff06b5e6caa009358bdddba55250
BLAKE2b-256 9c159615a8f409dc269af752f6e886795b0f118af95c6f8c68dc36c85238d52b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_connectors_binary-0.0.10-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_connectors_binary-0.0.10-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 dd38b5a86ff841ed3773589212a49126141de9b91dfcbf417272602b1926a563
MD5 af6ad770c84171c47bf773b97eb0dad6
BLAKE2b-256 96a1f7a3ee600ec98f5bdeea43941dd640a180eb74c6798f7176eed1d1cdc069

See more details on using hashes here.

File details

Details for the file bosa_connectors_binary-0.0.10-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 187c7d3ae61c1d1c2e32435e2be45ca6569d40eaff644bcb460ec648d887f66f
MD5 8e69468fba886da90dbf95f78ec07202
BLAKE2b-256 29e1716f55966e5160fff89a8265185a038e52f6a8161186886fb2d775ae3c76

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_connectors_binary-0.0.10-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_connectors_binary-0.0.10-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 75c3645eea8e018d58a122b6e2ca1337e7377e2d653aa657398a6e24d99cfc1a
MD5 b628f696e5744a96ab5558dab0d844db
BLAKE2b-256 f440f8d27a262c8263fe0b86eb655120a8fe3c8dc818345d31d00888593e6036

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_connectors_binary-0.0.10-cp312-cp312-macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_connectors_binary-0.0.10-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 90add70070a9b3e16316d2a9b580b8795cfb37dda17ee8c5f4d93431683eb622
MD5 1a4768656044948edf8d2d801a78ecb0
BLAKE2b-256 e39c7882656b749bb55ad70a32c3da54f71a0060f176a3bfad186530bfdb09a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_connectors_binary-0.0.10-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_connectors_binary-0.0.10-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 9d794393bf98926a7d77051810047f4d0e6513bf67d761c2a9c051998b4174b2
MD5 1b412d3fac9c4326ae4d73cbb7d0bd0d
BLAKE2b-256 a2e42f6844856ee6ce5b9d467dd7353b1feb533b3942cf72658d42382b99110d

See more details on using hashes here.

File details

Details for the file bosa_connectors_binary-0.0.10-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ee181d46d52bf1f018ad7d78afb5bf2fdb966234a9b13d278b9405ed5b0b43c5
MD5 145eb469570b7ff23011afd9d7a85c1a
BLAKE2b-256 56ddc3091f814836f0f2f65cf1194a4fc7530c18dae014eaa91d01728e228d2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_connectors_binary-0.0.10-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_connectors_binary-0.0.10-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_connectors_binary-0.0.10-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 fbf67559423cbf6093f3d48ee04e23a7f94bfbea44fd3a42ba9d6340f3ce1d88
MD5 fb5d785fe1f509f9b9a97ae941e31a81
BLAKE2b-256 8d48114ed8c4ef4f4665867970f2a41fbc629cab6fb0df63c5c368a03bf4bdac

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_connectors_binary-0.0.10-cp311-cp311-macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page