Python SDK for Thesis.io APIs.
Project description
Thesis.io Python SDK
A Python client for interacting with the Thesis.io API, enabling conversations, research, and space management.
Installation
pip install thesis_py
Quick Start
Initialize the Thesis client with your API key:
from thesis_py import Thesis
# Initialize client with API key
thesis = Thesis(api_key="your-api-key")
# Optional: specify custom base URL
thesis = Thesis(api_key="your-api-key", base_url="https://custom-endpoint.com")
API Features
Conversations
Create and manage AI-powered conversations with different research modes.
Create a New Conversation
from thesis_py.api_schema import CreateNewConversationIntegrationRequest, ResearchMode
# Create a conversation with deep research mode
response = thesis.create_conversation(
CreateNewConversationIntegrationRequest(
initial_user_msg="What's the new DeFi meta recently that I can ape in?",
research_mode=ResearchMode.DEEP_RESEARCH,
system_prompt="You are a DeFi gigachad who's always ahead of the new DeFi meta.",
space_id=123, # Optional: link to a specific space
space_section_id=456, # Optional: link to a specific section
)
)
print(f"Conversation ID: {response.conversation_id}")
Research Modes
ResearchMode.CHAT- Interactive chat modeResearchMode.DEEP_RESEARCH- Comprehensive research with citationsResearchMode.FOLLOW_UP- Follow-up research on existing topics
Get Conversation Details
# Retrieve conversation by ID
conversation = thesis.get_conversation_by_id("conv_abc123def456")
print(f"Status: {conversation.status}")
print(f"Events: {len(conversation.events) if conversation.events else 0}")
# Async version
conversation = await thesis.get_conversation_by_id_async("conv_abc123def456")
Join Existing Conversation (Streaming)
import asyncio
from thesis_py.api_schema import JoinConversationIntegrationRequest
async def join_conversation_example():
async for event in thesis.join_conversation(
JoinConversationIntegrationRequest(
conversation_id="conv_abc123def456",
user_prompt="Continue the research on recent DeFi trends",
research_mode=ResearchMode.CHAT,
)
):
# Process streaming events
print(f"Event: {event}")
# Run the async function
asyncio.run(join_conversation_example())
Spaces
Manage research spaces and their sections.
List Spaces
# Get all spaces with pagination
spaces = thesis.get_spaces(limit=10, offset=0)
print(f"Found {len(spaces.data)} spaces")
for space_item in spaces.data:
space = space_item.space
print(f"Space: {space.title} (ID: {space.id})")
Get Space Details
# Get detailed information about a space
space_detail = thesis.get_space_by_id("868")
space = space_detail.data
print(f"Title: {space.title}")
print(f"Description: {space.description}")
print(f"Members: {space.memberCount}")
print(f"Research Count: {space.totalResearch}")
Get Space Sections
# Get all sections within a space
sections = thesis.get_space_sections("868")
for section in sections.data:
print(f"Section: {section.name}")
print(f"Description: {section.description}")
print(f"Output Type: {section.outputType}")
Advanced Usage
Working with Events
Process conversation events and extract structured data:
from thesis_py.research.events import from_raw_events_to_pairs
from thesis_py.research.events.utils import get_pairs_from_events
# Get conversation and process events
conversation = thesis.get_conversation_by_id("conv_id")
pairs = from_raw_events_to_pairs(conversation.events[:2])
# For streaming events
async for event in thesis.join_conversation(request):
pairs = get_pairs_from_events([event])
print(pairs)
Environment Variables
Set your API key using environment variables:
export THESIS_API_KEY="your-api-key-here"
export THESIS_BASE_URL="https://app-be.thesis.io" # Optional
import os
from thesis_py import Thesis
# Will automatically use THESIS_API_KEY from environment
thesis = Thesis(api_key=os.environ["THESIS_API_KEY"])
Examples
Complete examples are available in the examples/ directory:
hello_world.py- Basic conversation creationget_conversation.py- Retrieve and process conversation eventsget_spaces.py- List and explore spacesjoin_conversation.py- Join conversations with streaming
Error Handling
import requests
from thesis_py import Thesis
try:
thesis = Thesis(api_key="your-api-key")
response = thesis.create_conversation(request)
except requests.HTTPError as e:
print(f"HTTP Error: {e.response.status_code}")
print(f"Response: {e.response.text}")
except ValueError as e:
print(f"Validation Error: {e}")
Data Models
The SDK uses Pydantic models for type safety and validation. Key models include:
ConversationCreateResponse- Response from conversation creationConversationDetailResponse- Detailed conversation informationSpaceListResponse- List of spaces with paginationSpaceDetailResponse- Detailed space informationCreateNewConversationIntegrationRequest- Request to create conversationsJoinConversationIntegrationRequest- Request to join conversations
Requirements
- Python 3.8+
httpxfor async HTTP requestsrequestsfor synchronous HTTP requestspydanticfor data validation and serialization
Project details
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 thesis_py-1.0.3.tar.gz.
File metadata
- Download URL: thesis_py-1.0.3.tar.gz
- Upload date:
- Size: 48.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
537491a042bdc0b2c0c0a4a8a9533ddf9d88e8de3c0f59e83a2ed3bdb025dc61
|
|
| MD5 |
cf78a6beb2129a93506dfe3649e3fa56
|
|
| BLAKE2b-256 |
033407ee62521d565a6447c01f298b76890d5636883540bbe6400966c7591a26
|
File details
Details for the file thesis_py-1.0.3-py3-none-any.whl.
File metadata
- Download URL: thesis_py-1.0.3-py3-none-any.whl
- Upload date:
- Size: 61.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26a72f1ebbb5d9e9e4baa73a889543cc17b0f167afc6994c3f02c548e754f1b0
|
|
| MD5 |
7322f46b30b7c571a2253458caafdece
|
|
| BLAKE2b-256 |
db7de137c56982213e7c867507dc46e0cd0c37d5fa6449b4ded89eee144be6ba
|