Skip to main content

Python SDK for Agent Office API - AI-powered document editing

Project description

Agent Office Python SDK

Python SDK for the Agent Office API - AI-powered document editing for agentic workflows.

Installation

pip install agent-office

Quick Start

from agent_office import AgentOffice
from uuid import uuid4

# Initialize the client
client = AgentOffice(api_key="sk_ao_your_api_key")  # Get your key from https://agentoffice.dev

# Upload a document
doc = client.documents.create(
    file="document.docx",
    return_markdown=True
)
print(f"Uploaded: {doc.doc_id}")

# Edit the document
edit = client.edit(
    doc_id=doc.doc_id,
    edit_uid=str(uuid4()),
    edit_instructions="Change the title to 'My New Title'",
    tracked_changes=False
)
print(f"Edit applied: {edit.edit_applied}")

# Download the edited document
result = client.documents.download(doc_id=doc.doc_id)
print(f"Download URL: {result.download_url}")

# You can then download the file using requests
import requests
response = requests.get(result.download_url)
with open(f"edited_{doc.name}", "wb") as f:
    f.write(response.content)

Features

  • 📝 Upload and convert documents (DOCX, PDF, etc.)
  • ✏️ AI-powered document editing
  • 📖 Read document content as Markdown
  • 💾 Download edited documents
  • 🔄 Track changes support

API Reference

Client Initialization

client = AgentOffice(
    api_key="sk_ao_your_api_key",  # Required: Your API key
    base_url="https://api.agentoffice.dev",  # Optional: API base URL
    timeout=60  # Optional: Request timeout in seconds
)

Documents

Create Document

doc = client.documents.create(
    file="path/to/document.docx",  # File path or file-like object
    return_markdown=True,  # Return markdown content
    ttl_seconds=3600  # Time to live in seconds (300-21600)
)

Create Document from URL

doc = client.documents.create_from_url(
    file_url="https://example.com/document.docx",
    ttl_seconds=3600
)

List Documents

docs = client.documents.list()
for doc in docs.documents:
    print(f"{doc.name}: {doc.doc_id}")

Download Document

result = client.documents.download(
    doc_id="doc-id",
    expires_in=3600  # Presigned URL expiration in seconds
)
print(result.download_url)

Check Document Exists

result = client.documents.exists(doc_id="doc-id")
if result.exists:
    print(f"Document exists: {result.document.name}")

Edit Document

edit = client.edit(
    doc_id="doc-id",
    edit_uid=str(uuid4()),  # Unique identifier for the edit
    edit_instructions="Change the title to 'My New Title'",  # Natural language instructions
    lookup_text="Section 1",  # Optional: Text to locate edit position
    tracked_changes=False,  # Enable track changes
    use_large_model=False  # Use larger AI model
)

Read Document

result = client.read(doc_id="doc-id")
print(result.markdown)

Error Handling

The SDK provides specific exception types for different error conditions:

from agent_office import (
    AgentOffice,
    AgentOfficeError,
    AuthenticationError,
    NotFoundError,
    ValidationError,
    RateLimitError,
    ServerError,
)

client = AgentOffice(api_key="sk_ao_your_api_key")

try:
    doc = client.documents.create("document.docx")
except AuthenticationError:
    print("Invalid API key")
except NotFoundError:
    print("Document not found")
except ValidationError as e:
    print(f"Validation error: {e.message}")
except RateLimitError:
    print("Rate limit exceeded")
except ServerError:
    print("Server error")
except AgentOfficeError as e:
    print(f"General error: {e.message}")

Development

Install from source

git clone https://github.com/agentoffice/python-sdk.git
cd python-sdk
pip install -e .

Install development dependencies

pip install -e ".[dev]"

License

MIT

Support

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

agent_office-0.0.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_office-0.0.4-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file agent_office-0.0.4.tar.gz.

File metadata

  • Download URL: agent_office-0.0.4.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for agent_office-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ff6009f8915837919e01e42b64ddbd5d5e3b9c724d6dd2280a1c6e8681042149
MD5 2f01b1d2dfdd8fb5bdb026375ec8ac5e
BLAKE2b-256 ba38f48ac98f50a9528fcc0a3c926000f26fbb5b7920a1783684d262a3c38d3d

See more details on using hashes here.

File details

Details for the file agent_office-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: agent_office-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for agent_office-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cc567027a2b7d161df038b3a0a1674e69da71055c5854004cc1e69b06879ef7c
MD5 90a2a385ec5ffb28b320aed8a3a1e987
BLAKE2b-256 c80d34030685b5fdbbc706cf9998fb06e59057aef25b807c829a3efeb113ae8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page