Python SDK
Complete Python SDK for Archivus API.
Installation
pip install archivus-python
Quick Start
from archivus import ArchivusClient
# Initialize client
client = ArchivusClient(
api_key="YOUR_API_KEY",
tenant="your-tenant"
)
# List documents
documents = client.documents.list(limit=10)
# Upload document
document = client.documents.upload(
"contract.pdf",
folder_id="folder_xyz",
enable_ai=True
)
# Search documents
results = client.search.search(
query="contracts expiring soon",
mode="semantic"
)
# Chat with document
session = client.chat.create_session(document.id, "Analysis")
response = client.chat.ask(session.id, "What are the key terms?")
print(response.content)
Client Initialization
API Key Authentication
from archivus import ArchivusClient
client = ArchivusClient(
api_key="ak_live_YOUR_API_KEY",
tenant="your-tenant"
)
JWT Token Authentication
from archivus import ArchivusClient
client = ArchivusClient(
jwt_token="YOUR_JWT_TOKEN",
tenant="your-tenant"
)
Documents
List Documents
# Basic list
documents = client.documents.list()
# With filters
documents = client.documents.list(
folder_id="folder_xyz",
tag_id="tag_legal",
limit=20,
page=1
)
Get Document
document = client.documents.get("doc_abc123")
Upload Document
# Single upload
document = client.documents.upload(
"contract.pdf",
folder_id="folder_xyz",
enable_ai=True,
tags=["contract", "legal"]
)
# Batch upload
results = client.documents.upload_batch(
["doc1.pdf", "doc2.pdf", "doc3.pdf"],
folder_id="folder_xyz"
)
Update Document
document = client.documents.update(
"doc_abc123",
filename="Updated Name.pdf",
tags=["updated", "important"]
)
Delete Document
client.documents.delete("doc_abc123")
Download Document
file_content = client.documents.download("doc_abc123")
with open("downloaded.pdf", "wb") as f:
f.write(file_content)
Search
Basic Search
# Semantic search
results = client.search.search(
query="contracts expiring soon",
mode="semantic",
limit=20
)
# Keyword search
results = client.search.search(
query="contract",
mode="text"
)
Enhanced Search
results = client.search.enhanced_search(
query="Find all contracts expiring in Q4",
filters={
"tags": ["contract"],
"date_range": {
"start": "2025-10-01",
"end": "2025-12-31"
}
},
min_score=0.7
)
Hybrid Search
results = client.search.hybrid_search(
query="contract renewal",
semantic_weight=0.7,
text_weight=0.3
)
Chat
Create Session
# Single document
session = client.chat.create_session(
document_id="doc_abc123",
name="Contract Analysis"
)
# Multiple documents
session = client.chat.create_session(
document_ids=["doc_abc123", "doc_def456"],
name="Multi-Doc Analysis"
)
Ask Question
response = client.chat.ask(
session.id,
"What are the key terms of this contract?"
)
print(response.content)
print(f"Confidence: {response.confidence}")
print(f"Sources: {response.sources}")
RAG Query
response = client.chat.ask_rag(
session.id,
"Find all contracts expiring in Q4 2025"
)
Get History
history = client.chat.get_history(session.id, limit=50)
for message in history.messages:
print(f"{message.role}: {message.content}")
Folders
List Folders
folders = client.folders.list()
Create Folder
folder = client.folders.create(
name="Contracts",
parent_id=None,
color="#3B82F6",
icon="folder"
)
Update Folder
folder = client.folders.update(
"folder_abc123",
name="Updated Name",
color="#EF4444"
)
Delete Folder
client.folders.delete("folder_abc123", force=True)
Workspaces
Create Workspace
workspace = client.workspaces.create(
name="Legal Team",
description="Legal documents and contracts"
)
Add Member
client.workspaces.add_member(
workspace.id,
user_id="user_xyz789",
role="member",
permission="edit"
)
List Members
members = client.workspaces.list_members(workspace.id)
Error Handling
from archivus import ArchivusError, RateLimitError
try:
document = client.documents.get("doc_abc123")
except ArchivusError as e:
if e.code == "NOT_FOUND":
print("Document not found")
elif e.code == "RATE_LIMIT_EXCEEDED":
print(f"Rate limit exceeded. Reset at: {e.reset_at}")
else:
print(f"Error: {e.message}")
Rate Limiting
The SDK automatically handles rate limits:
# SDK automatically waits when rate limited
documents = client.documents.list() # May wait if rate limited
You can also check rate limit status:
# Check remaining requests
remaining = client.rate_limit.remaining
limit = client.rate_limit.limit
reset_at = client.rate_limit.reset_at
if remaining < 10:
print(f"Approaching rate limit. Reset at: {reset_at}")
Advanced Usage
Custom Headers
client = ArchivusClient(
api_key="YOUR_API_KEY",
tenant="your-tenant",
headers={
"X-Custom-Header": "value"
}
)
Retry Configuration
client = ArchivusClient(
api_key="YOUR_API_KEY",
tenant="your-tenant",
max_retries=3,
retry_delay=1.0
)
Async Support
import asyncio
from archivus.async_client import AsyncArchivusClient
async def main():
client = AsyncArchivusClient(
api_key="YOUR_API_KEY",
tenant="your-tenant"
)
documents = await client.documents.list()
print(documents)
asyncio.run(main())
Complete Example
from archivus import ArchivusClient
def main():
# Initialize client
client = ArchivusClient(
api_key="YOUR_API_KEY",
tenant="your-tenant"
)
# Upload document
print("Uploading document...")
document = client.documents.upload(
"contract.pdf",
folder_id="folder_legal",
enable_ai=True
)
# Wait for processing
print("Waiting for processing...")
document = client.documents.wait_for_processing(document.id)
# Search for similar documents
print("Searching for similar documents...")
results = client.search.search(
query="contracts similar to this one",
mode="semantic"
)
# Chat with document
print("Analyzing document...")
session = client.chat.create_session(document.id, "Analysis")
response = client.chat.ask(
session.id,
"What are the key terms and risks?"
)
print(f"\nAnalysis: {response.content}")
print(f"Confidence: {response.confidence:.2f}")
if __name__ == "__main__":
main()
API Reference
Documents
list(**filters)- List documentsget(id)- Get documentupload(file_path, **options)- Upload documentupload_batch(file_paths, **options)- Batch uploadupdate(id, **updates)- Update documentdelete(id)- Delete documentdownload(id)- Download documentwait_for_processing(id, timeout=300)- Wait for processing
Search
search(query, **options)- Basic searchenhanced_search(query, filters=None)- Enhanced searchhybrid_search(query, **options)- Hybrid search
Chat
create_session(document_ids, name=None)- Create sessionask(session_id, message)- Ask questionask_rag(session_id, message)- RAG queryget_history(session_id, limit=50)- Get historydelete_session(session_id)- Delete session
Folders
list(**filters)- List foldersget(id)- Get foldercreate(name, **options)- Create folderupdate(id, **updates)- Update folderdelete(id, force=False)- Delete folder
Workspaces
list()- List workspacesget(id)- Get workspacecreate(name, **options)- Create workspaceadd_member(workspace_id, user_id, **options)- Add memberlist_members(workspace_id)- List membersremove_member(workspace_id, user_id)- Remove member
Next Steps
- JavaScript SDK - JavaScript/TypeScript SDK
- API Reference - Complete API documentation
- Examples - Code examples
Questions? Check the FAQ or contact support@ubiship.com