Official Python SDK for Suada's Business Analyst API
Project description
Suada Python SDK
The official Python SDK for Suada's Business Analyst API. This SDK allows you to easily integrate Suada's powerful business analysis capabilities into your applications and LangChain agents.
Installation
pip install suada
Usage
Basic Usage
from suada import Suada, SuadaConfig, ChatPayload
# Initialize the client
suada = Suada(
config=SuadaConfig(
api_key="your-api-key"
)
)
# Send a chat message
response = suada.chat(
payload=ChatPayload(
message="What's our revenue trend?",
external_user_identifier="user-123" # Optional when passthrough_mode is False
)
)
print(response)
Integration with LangChain
from suada import Suada, SuadaConfig
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.chat_models import ChatOpenAI
from langchain.prompts import PromptTemplate
# Initialize Suada
suada = Suada(
config=SuadaConfig(
api_key="your-api-key"
)
)
# Create Suada tool
suada_tool = suada.create_tool(
name="business_analyst",
description="Use this tool to get business insights and analysis",
external_user_identifier="user-123", # Required when passthrough_mode is True
passthrough_mode=True # Optional, defaults to False
)
# Create OpenAI agent with Suada tool
model = ChatOpenAI(temperature=0)
tools = [suada_tool]
prompt = PromptTemplate.from_template(
"""You are a helpful assistant that uses Suada's business analyst capabilities.
Current conversation:
{chat_history}
Human: {input}
Assistant: Let me help you with that."""
)
agent = create_openai_functions_agent(
llm=model,
tools=tools,
prompt=prompt
)
executor = AgentExecutor.from_agent_and_tools(
agent=agent,
tools=tools,
verbose=True
)
# Use the agent
result = executor.invoke({
"input": "What's our revenue trend for the last quarter?",
"chat_history": []
})
print(result["output"])
Passthrough Mode and User Identification
The SDK supports two modes of operation:
-
Standard Mode (
passthrough_mode=False, default): In this mode, Suada's AI analyzes the query and provides structured business insights. Theexternal_user_identifieris optional. -
Passthrough Mode (
passthrough_mode=True): In this mode, messages are passed directly to the LLM. When using passthrough mode,external_user_identifieris required for proper user tracking.
# Standard mode - external_user_identifier is optional
response_standard = suada.chat(
payload=ChatPayload(
message="What's our revenue trend?",
passthrough_mode=False # This is the default
)
)
# Passthrough mode - external_user_identifier is required
response_passthrough = suada.chat(
payload=ChatPayload(
message="What's our revenue trend?",
external_user_identifier="user-123",
passthrough_mode=True
)
)
Response Format
The SDK formats responses from Suada's API into a structured string format that can be easily parsed by LangChain agents. The response includes the following sections:
<metrics>: Key performance metrics<insights>: Business insights<recommendations>: Action recommendations<risks>: Potential risks<reasoning>: Analysis reasoning<response>: Main response text
Example response:
<metrics>
revenue: $1.2M
growth_rate: 15%
</metrics>
<insights>
Strong growth in enterprise segment
New product adoption exceeding expectations
</insights>
<recommendations>
Increase focus on enterprise sales
Expand product feature set
</recommendations>
<risks>
Market competition intensifying
Supply chain constraints
</risks>
<reasoning>
Analysis shows positive growth trajectory with some areas requiring attention
</reasoning>
<response>
Your revenue has shown strong growth, particularly in the enterprise segment...
</response>
Configuration
The SDK accepts the following configuration options:
from suada import SuadaConfig
config = SuadaConfig(
api_key="your-api-key",
base_url="https://suada.ai/api/public/" # Optional, defaults to https://suada.ai/api/public/
)
Type Safety
The SDK uses Pydantic models for type safety and validation:
from suada import ChatPayload, ChatMessage
# All fields are properly typed and validated
payload = ChatPayload(
message="What's our revenue?",
external_user_identifier="user-123", # Required only when passthrough_mode is True
passthrough_mode=True,
chat_history=[
ChatMessage(
role="user",
content="Previous message"
)
]
)
Error Handling
The SDK throws descriptive exceptions when API calls fail:
from suada import Suada, SuadaConfig, ChatPayload
suada = Suada(config=SuadaConfig(api_key="your-api-key"))
try:
response = suada.chat(
payload=ChatPayload(
message="What's our revenue?",
external_user_identifier="user-123"
)
)
except Exception as e:
print(f"Error: {str(e)}")
Development
To set up the development environment:
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run type checking
mypy suada
# Run code formatting
black suada
isort suada
License
MIT
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 Distribution
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 suada-1.3.0rc1.tar.gz.
File metadata
- Download URL: suada-1.3.0rc1.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3327259cb942edd46506f0056f4c4e9a139b9ba88b135728065cb406a694843
|
|
| MD5 |
5881d72a9901cb3bd137b89e878366a1
|
|
| BLAKE2b-256 |
c6ebcd596541f219484cbb41a225838ab13c485fb91c924de6ee06ff9b7dd40f
|
File details
Details for the file suada-1.3.0rc1-py3-none-any.whl.
File metadata
- Download URL: suada-1.3.0rc1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f193824abc772b774d2c467f656621ac4eb0ccb228b07754062b9f2c6b2687b
|
|
| MD5 |
fd0c1528446ea13670260c16fccc50a7
|
|
| BLAKE2b-256 |
e0cfd1a6a2ef8bde90c8c5c0c2c7e4ccd136623f66d011475e894774f50006a7
|