Connector Client
The ConnectorClient class provides a Python interface to interact with third-party connectors programmatically.
Overview
The Connector Client allows developers to:
Connect to third-party services (GitHub, Google Drive, Google Calendar, Google Mail, Chief Retrieval)
Disconnect from integrated services
Search connected services using natural language queries
Handle both streaming and non-streaming responses
Installation
pip install smart-search-sdkQuick Start
import asyncio
import os
from dotenv import load_dotenv
from smart_search_sdk.connector.client import ConnectorClient
from smart_search_sdk.connector.models import (
ConnectorRequest,
ConnectorConnectRequest,
AppName
)
load_dotenv()
async def main():
# Initialize the client
client = ConnectorClient(base_url=os.getenv("SMARTSEARCH_BASE_URL"))
# Authenticate
await client.authenticate(token=os.getenv("SMARTSEARCH_TOKEN"))
# Connect to GitHub
connect_request = ConnectorConnectRequest(
callback_url="https://your-app.com/callback"
)
response = await client.connect_connector(
app_name=AppName.GITHUB,
bosa_token=os.getenv("BOSA_TOKEN", ""),
request=connect_request
)
print(response)
asyncio.run(main())Class: ConnectorClient
Constructor
Parameters:
base_url(str): The base URL of the Smart Search API
Example:
Methods
Connect - Connect
Initiate integration with a third-party connector.
Signature
Parameters
app_name
AppName
Yes
The connector app to connect to
bosa_token
str | None
No
Optional BOSA token for authentication
request
ConnectorConnectRequest
Yes
Connection request containing callback URL
Returns
dict: Response containing connection status and optional setup URL
Response Structure
Examples
Connect to GitHub:
Connect with BOSA token:
Connect - Disconnect
Remove integration with a third-party connector.
Signature
Parameters
app_name
AppName
Yes
The connector app to disconnect from
bosa_token
str | None
No
Optional BOSA token for authentication
Returns
dict: Confirmation of disconnection
Response Structure
Examples
Disconnect from GitHub:
Connect - Search
Search a connected third-party service using natural language.
Signature
Parameters
app_name
AppName
Yes
-
The connector app to search
bosa_token
str | None
No
None
Optional BOSA token
request
ConnectorRequest
Yes
-
Search request with query
stream
bool
No
False
Enable streaming response
timeout
float
No
30.0
Request timeout in seconds
Returns
Non-streaming:
dictwith search resultsStreaming:
AsyncGeneratoryielding response chunks
Response Structure
Examples
Basic search:
Streaming search:
Search with timeout:
Sample queries by connector:
Google Drive (AppName.GOOGLE_DRIVE):
"Find all documents about Q2 financial reports"
"Show me all PDF files from last month"
"List documents shared with the team"
Google Mail (AppName.GOOGLE_MAIL):
"Find emails from john@example.com about project alpha"
"Show me emails with attachments from this week"
"Find emails about meeting schedule changes"
Google Calendar (AppName.GOOGLE_CALENDAR):
"List all my upcoming meetings today"
"Show me meetings with Alice next week"
"What meetings are scheduled in the conference room tomorrow?"
GitHub (AppName.GITHUB):
"Find open issues about authentication"
"Show me pull requests related to bug fixes"
"List repositories with recent commits"
Models
AppName Enum
Available connector apps:
ConnectorConnectRequest
Fields:
callback_url(str): OAuth callback URL for authentication
ConnectorRequest
Fields:
query(str): Natural language search query
Authentication
The client supports two authentication modes:
1. Default Credentials
Uses Smart Search's internal credentials:
2. BOSA Token
Uses provided BOSA token:
Error Handling
Complete Examples
Search Multiple Connectors
Setup OAuth Flow
Best Practices
Authentication: Always authenticate before making requests
Resource Management: Use async context managers when possible
Error Handling: Wrap requests in try-except blocks
Streaming for Large Results: Use streaming for better performance
Timeout Configuration: Set appropriate timeouts
Secure Tokens: Never hardcode BOSA tokens
Related Documentation
Last updated
