SDK for Smart Search API backend
Project description
๐ Smart Search SDK ๐
A comprehensive Python SDK for interacting with Smart Search services, including web search, connector search, deep research, and authentication email management. Built with a clean, intuitive API design for rapid development of search applications.
๐ Overview
Smart Search SDK is a Python library that simplifies interaction with Smart Search services. It provides a clean, intuitive API for performing web searches, connector searches, deep research, and managing authentication emails, enabling rapid development of search applications.
๐ Requirements
Python 3.11.x or higher is required.
โจ Features
- ๐ Web Search: Search the web for documents, URLs, and extract content from web pages
- ๐ Connector Search: Search and manage third-party service connectors (GitHub, Google Drive, Google Mail, Google Calendar)
- ๐ฌ Deep Research: Conduct comprehensive research using various research types
- ๐ง Authentication Email Management: Retrieve and manage authentication emails
- ๐ Authentication Support: Built-in token-based authentication
- ๐ Simple API: Send requests and receive responses with minimal code
- ๐ฏ Type Safety: Comprehensive type hints for better development experience
- ๐ Flexible Response Handling: Choose between different response formats
- ๐ Comprehensive Documentation: Extensive documentation and examples
๐ฆ Installation
To install the package:
pip install smart-search-sdk
After installation, you can verify it works by trying to import it from any directory:
from smart_search_sdk.web.client import WebSearchClient
from smart_search_sdk.connector.client import ConnectorClient
from smart_search_sdk.search.client import SmartSearchSearchClient
from smart_search_sdk.deep_research.client import SmartSearchDeepResearchClient
๐ Quick Start
Creating a web search client with Smart Search SDK is incredibly simple:
import asyncio
from smart_search_sdk.web.client import WebSearchClient
from smart_search_sdk.web.models import GetWebSearchResultsRequest
async def main():
# Initialize the Web Search client
client = WebSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
# Perform a web search
request = GetWebSearchResultsRequest(
query="What is artificial intelligence?",
result_type="snippets",
size=5
)
response = client.search_web(request)
print(response)
asyncio.run(main())
Note: Make sure you have the correct API URL and token before running examples.
๐ฆ Available Clients
1. ๐ Web Search Client
search_web: Search the web for documents or pages relevant to the input querysearch_web_urls: Search the web for pages and return their URLsfetch_web_page: Fetch a single web page by URLget_web_page_snippets: Extract relevant text snippets from a web pageget_web_page_keypoints: Extract key points from a web page
from smart_search_sdk.web.client import WebSearchClient
from smart_search_sdk.web.models import GetWebSearchResultsRequest
client = WebSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
request = GetWebSearchResultsRequest(
query="Python programming tutorials",
result_type="snippets",
size=5
)
response = client.search_web(request)
2. ๐ Connector Client
search_connector: Search a connector for the specified appconnect_connector: Initiate integration with a third-party connectordisconnect_connector: Remove integration with a third-party connector
from smart_search_sdk.connector.client import ConnectorClient
from smart_search_sdk.connector.models import ConnectorRequest, AppName
client = ConnectorClient(base_url="your-api-url")
await client.authenticate(token="your-token")
request = ConnectorRequest(query="Find all Smart Search emails")
response = client.search_connector(
app_name=AppName.GOOGLE_CALENDAR,
gl_token="your-gl-token",
request=request
)
3. ๐ Smart Search Client
search: Perform a search operation using specified search profile names and querydeep_search: Perform deep research based on input data
from smart_search_sdk.search.client import SmartSearchSearchClient
from smart_search_sdk.search.models import SmartSearchKeyPointsRequest
client = SmartSearchSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
request = SmartSearchKeyPointsRequest(
query="artificial intelligence",
search_profile_names=["general", "github"],
size=5
)
response = client.search(request)
4. ๐ฌ Deep Research Client
deep_research: Perform comprehensive research using various research types
from smart_search_sdk.deep_research.client import SmartSearchDeepResearchClient
client = SmartSearchDeepResearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
response = client.deep_research(query="your research query")
๐ Environment Variables
Smart Search SDK uses os.getenv() to read environment variables. You are responsible for loading environment variables in your application before initializing the Smart Search clients. You can use libraries like python-dotenv, python-decouple, or set them directly in your shell.
Available environment variables:
SMARTSEARCH_BASE_URL: The base URL for the Smart Search APISMARTSEARCH_TOKEN: Your Smart Search authentication tokenGL_CONNECTORS_USER_TOKEN: Optional GL Connectors token for connector authentication
Example using python-dotenv:
First, install python-dotenv:
pip install python-dotenv
Create a .env file:
SMARTSEARCH_BASE_URL=https://your-api-endpoint.com/
SMARTSEARCH_TOKEN=your-authentication-token
GL_CONNECTORS_USER_TOKEN=your-gl-token
Load environment variables in your code:
from dotenv import load_dotenv
from smart_search_sdk.web.client import WebSearchClient
# Load environment variables from .env file
load_dotenv()
# Will automatically use environment variables
client = WebSearchClient()
await client.authenticate()
Example using shell export:
export SMARTSEARCH_BASE_URL="https://your-api-endpoint.com/"
export SMARTSEARCH_TOKEN="your-authentication-token"
export GL_CONNECTORS_USER_TOKEN="your-gl-token"
Then initialize the client without parameters:
from smart_search_sdk.web.client import WebSearchClient
# Will automatically use environment variables
client = WebSearchClient()
await client.authenticate()
๐ง Advanced Usage
๐ Web Search with Different Result Types
from smart_search_sdk.web.client import WebSearchClient
from smart_search_sdk.web.models import GetWebSearchResultsRequest
client = WebSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
# Search with snippets
snippets_request = GetWebSearchResultsRequest(
query="Python programming best practices",
result_type="snippets",
size=5
)
snippets_response = client.search_web(snippets_request)
# Search with keypoints
keypoints_request = GetWebSearchResultsRequest(
query="Machine learning algorithms",
result_type="keypoints",
size=3
)
keypoints_response = client.search_web(keypoints_request)
๐ Connector Management
from smart_search_sdk.connector.client import ConnectorClient
from smart_search_sdk.connector.models import ConnectorRequest, ConnectorConnectRequest, AppName
client = ConnectorClient(base_url="your-api-url")
await client.authenticate(token="your-token")
# Connect to a connector
connect_request = ConnectorConnectRequest(
callback_url="https://your-app.com/callback"
)
connect_response = client.connect_connector(
app_name=AppName.GOOGLE_CALENDAR,
gl_token="your-gl-token",
request=connect_request
)
# Search the connector
search_request = ConnectorRequest(query="Find meetings next week")
search_response = client.search_connector(
app_name=AppName.GOOGLE_CALENDAR,
gl_token="your-gl-token",
request=search_request
)
๐ Smart Search with Multiple Profiles
from smart_search_sdk.search.client import SmartSearchSearchClient
from smart_search_sdk.search.models import SmartSearchKeyPointsRequest
client = SmartSearchSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
# Search with multiple profiles
request = SmartSearchKeyPointsRequest(
query="artificial intelligence trends",
search_profile_names=["general", "github", "google_drive"],
size=10
)
response = client.search(request)
๐ API Reference
WebSearchClient
The client class for performing web search operations.
๐ง Initialization
client = WebSearchClient(base_url: str = "")
Parameters:
base_url: The base URL for the Smart Search API ๐ (or set SMARTSEARCH_BASE_URL env var)
Methods
๐ search_web
Search the web for documents or pages relevant to the input query.
response = client.search_web(request: GetWebSearchResultsRequest) -> dict
Parameters:
request: GetWebSearchResultsRequest containing query, result_type, and size ๐
Returns:
dict: Web search response data ๐
๐ search_web_urls
Search the web for pages and return their URLs.
response = client.search_web_urls(request: GetWebSearchUrlsRequest) -> dict
๐ fetch_web_page
Fetch a single web page by URL.
response = client.fetch_web_page(request: GetWebPageRequest) -> dict
ConnectorClient
The client class for managing third-party service connectors.
๐ง Initialization
client = ConnectorClient(base_url: str = "")
Methods
๐ search_connector
Search a connector for the specified app.
response = client.search_connector(
app_name: AppName,
gl_token: str,
request: ConnectorRequest
) -> dict
๐ connect_connector
Initiate integration with a third-party connector.
response = client.connect_connector(
app_name: AppName,
gl_token: str,
request: ConnectorConnectRequest
) -> dict
โ disconnect_connector
Remove integration with a third-party connector.
response = client.disconnect_connector(
app_name: AppName,
gl_token: str
) -> dict
SmartSearchSearchClient
The client class for performing smart search operations.
๐ง Initialization
client = SmartSearchSearchClient(base_url: str = "")
Methods
๐ search
Perform a search operation using specified search profile names and query.
response = client.search(request: SmartSearchKeyPointsRequest) -> dict
๐ฌ deep_search
Perform deep research based on input data.
response = client.deep_search(query: str) -> dict
๐ Authentication
The clients support token-based authentication with flexible configuration options. The authentication token can be provided either as a parameter during the authenticate method or through environment variables.
๐ Token Configuration
Option 1: Direct Parameter
client = WebSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
Option 2: Environment Variable
export SMARTSEARCH_TOKEN="your-token"
client = WebSearchClient(base_url="your-api-url")
await client.authenticate() # Automatically uses SMARTSEARCH_TOKEN environment variable
Option 3: Priority System
# Parameter takes priority over environment variable
client = WebSearchClient(base_url="your-api-url")
await client.authenticate(token="explicit-token") # Uses explicit token even if env var is set
๐ Authentication Headers
When a token is provided (via parameter or environment variable), it's automatically included in the Authorization header for all requests:
# Token is automatically used in requests ๐
client = WebSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
response = client.search_web(request)
โ ๏ธ Required Configuration
Authentication is required - you must provide it either:
- As the
tokenparameter when callingauthenticate(), OR - Set the
SMARTSEARCH_TOKENenvironment variable
If neither is provided, the client will raise an error:
client = WebSearchClient(base_url="your-api-url")
await client.authenticate() # Raises error if SMARTSEARCH_TOKEN is not set
๐ Examples
To see the SDK in action, we provide comprehensive example scripts:
๐ Available Examples
simple.py- Interactive CLI example with menu-driven interfaceweb_search.py- Non-interactive web search demonstrationsconnector_search.py- Non-interactive connector search demonstrations
๐ How to Run Examples
Navigate to the examples directory and run:
# Interactive example with full menu
python simple.py
# Web search demonstrations
python web_search.py
# Connector search demonstrations
python connector_search.py
๐ Prerequisites
Before running examples, set up your environment variables:
export SMARTSEARCH_BASE_URL="https://your-api-endpoint.com/"
export SMARTSEARCH_TOKEN="your-authentication-token"
export GL_CONNECTORS_USER_TOKEN="your-gl-token" # Optional, for connector operations
Or create a .env file in the examples directory:
SMARTSEARCH_BASE_URL=https://your-api-endpoint.com/
SMARTSEARCH_TOKEN=your-authentication-token
GL_CONNECTORS_USER_TOKEN=your-gl-token
๐ Documentation
๐ General Documentation
-
Deployment Documents:
๐ Onboarding & Features
- Smart Search Onboarding Guide
- Smart Search Features Roadmap
- Environment Information
- Swirl's Search Providers
๐ Deep Search Documentation
- Deep Search Product Requirements
- Deep Search Architecture
- Deep Search Design
- Deep Search Implementation
๐ API Reference
๐งญ Notes
- For the most up-to-date SDK usage, please refer to the inline docstrings or API Docs.
- Deprecated methods will be removed in future releasesโplease migrate to their updated alternatives.
โ ๏ธ Error Handling
The clients use httpx for HTTP requests and will raise appropriate exceptions for HTTP errors. Make sure to handle these exceptions in your code:
import asyncio
from smart_search_sdk.web.client import WebSearchClient
from smart_search_sdk.web.models import GetWebSearchResultsRequest
async def safe_web_search():
try:
client = WebSearchClient(base_url="your-api-url")
await client.authenticate(token="your-token")
request = GetWebSearchResultsRequest(
query="Python programming",
result_type="snippets",
size=5
)
response = client.search_web(request)
return response
except Exception as e:
print(f"Error occurred: {str(e)}")
return None
# Run the safe search
result = asyncio.run(safe_web_search())
๐งญ Notes
- For the most up-to-date SDK usage, please refer to the inline docstrings or API Docs.
- All clients inherit from
BaseSmartSearchClientwhich provides common authentication and HTTP request functionality. - The SDK supports both synchronous and asynchronous operations, with async being the recommended approach.
- Deprecated methods will be removed in future releasesโplease migrate to their updated alternatives.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smart_search_sdk-0.0.14-py3-none-any.whl.
File metadata
- Download URL: smart_search_sdk-0.0.14-py3-none-any.whl
- Upload date:
- Size: 53.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: poetry/2.1.1 CPython/3.12.0 Linux/5.10.0-32-cloud-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac5bb5f060c0a88ecb5deca463c886efcdbc863cb41b86ce51236956b793a964
|
|
| MD5 |
35fbc8f07cf8b18d9f682ba1a83a79e5
|
|
| BLAKE2b-256 |
cd6dcf293b08f77a83ac27714fcea69e645594756cbf06aec558acbe5bc370d5
|