Skip to main content

Python client for the Dewey API

Project description

Dewey

dewey

CI

Python client for the Dewey API. No third-party dependencies — uses only the Python standard library. See the full API reference for details on all endpoints and types.

Installation

pip install dewey

Quick start

from dewey import DeweyClient

client = DeweyClient(api_key="dwy_live_...")

# Create a collection
col = client.collections.create("My Docs")

# Upload a document
from pathlib import Path
doc = client.documents.upload(col.id, Path("report.pdf"))

# Query
results = client.retrieval.query(col.id, "What is the refund policy?")
for r in results:
    print(r.score, r.chunk.content[:100])

# Research (SSE streaming)
for event in client.research.stream(col.id, "Summarise key findings"):
    if event.type == "chunk":
        print(event.content, end="", flush=True)
    elif event.type == "done":
        print("\nSources:", event.sources)

Constructor

DeweyClient(api_key: str, base_url: str = "https://api.meetdewey.com/v1")

Resources

client.collections

Method Description
create(name, *, visibility, chunk_size, chunk_overlap, embedding_model) Create a collection
list() List collections
get(collection_id) Get by ID
update(collection_id, *, name, visibility, ...) Update
delete(collection_id) Delete

update() accepts: name, visibility, chunk_size, chunk_overlap, description, enable_summarization, enable_captioning, llm_model, instructions. llm_model and instructions accept None to clear the field; omit them entirely to leave unchanged.

# Set research instructions for a collection
client.collections.update(
    collection_id,
    instructions="All figures are in USD unless stated otherwise.",
)

# Clear instructions
client.collections.update(collection_id, instructions=None)

client.documents

Method Description
upload(collection_id, file, *, filename, content_type, ...) Multipart upload
upload_many(collection_id, files, *, concurrency, on_progress) Bulk upload via presigned S3 URLs
request_upload_url(collection_id, filename, content_type, file_size_bytes, content_hash) Presigned URL
confirm(collection_id, document_id) Confirm presigned upload
list(collection_id) List documents
get(collection_id, document_id) Get document
get_markdown(collection_id, document_id) Get Markdown string
retry(collection_id, document_id) Retry failed document
delete(collection_id, document_id) Delete document

upload() accepts a pathlib.Path, bytes, or any binary file-like object.

upload_many() is the recommended approach for large datasets. Each file is uploaded directly to S3 (bypassing the API server), so there are no payload-size limits. Files that match an existing document's hash are deduplicated automatically.

from pathlib import Path

docs = client.documents.upload_many(
    collection_id,
    list(Path("./reports").glob("**/*.pdf")),
    concurrency=10,
    on_progress=lambda doc, n, total: print(f"{n}/{total} {doc.filename}"),
)

Pass UploadManyItem instances when you need a custom filename or content type:

from dewey.resources.documents import UploadManyItem
from io import BytesIO

items = [
    UploadManyItem(file=BytesIO(data), filename="custom-name.pdf", content_type="application/pdf"),
]
docs = client.documents.upload_many(collection_id, items)

client.sections

Method Description
list(collection_id, document_id) List sections
get(section_id) Get section with content
get_chunks(section_id) Get chunks
scan(collection_id, query, *, top_k) Full-text section scan

client.retrieval

Method Description
query(collection_id, q, *, limit) Hybrid search

client.research

Method Description
stream(collection_id, q, *, depth, model) SSE research → Generator[ResearchEvent]

depth options: "quick", "balanced" (default), "deep", "exhaustive".

client.provider_keys

Method Description
create(project_id, provider, key, name) Add provider key
list(project_id) List keys
delete(project_id, key_id) Delete key

Error handling

from dewey import DeweyClient, DeweyError

client = DeweyClient(api_key="dwy_live_...")

try:
    client.collections.get("unknown-id")
except DeweyError as e:
    print(e.status, e.message)  # e.g. 404 "Collection not found"

Presigned upload flow

For single files or when you need manual control, use the low-level presigned URL flow. For bulk ingestion, prefer upload_many() which handles this automatically with concurrency.

import hashlib
import urllib.request
from pathlib import Path

data = Path("file.pdf").read_bytes()
content_hash = hashlib.sha256(data).hexdigest()

# 1. Request a presigned URL
resp = client.documents.request_upload_url(
    collection_id,
    filename="file.pdf",
    content_type="application/pdf",
    file_size_bytes=len(data),
    content_hash=content_hash,
)

# 2. PUT bytes directly to S3 (no auth header needed)
req = urllib.request.Request(resp.uploadUrl, data=data, method="PUT")
req.add_header("Content-Type", "application/pdf")
urllib.request.urlopen(req)

# 3. Confirm to trigger ingestion
doc = client.documents.confirm(collection_id, resp.documentId)

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

meetdewey-1.1.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

meetdewey-1.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file meetdewey-1.1.0.tar.gz.

File metadata

  • Download URL: meetdewey-1.1.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for meetdewey-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5b15a04c56dccb03b2dbd858eede087b203095f58cabf0ab7322633f56e587e4
MD5 d11a1015455bd0cf2a439b23034aecad
BLAKE2b-256 5c2cf7424f0fe9a5f05201814b98ef77bc252eefa186bd42b4961f8d9f0a0d93

See more details on using hashes here.

File details

Details for the file meetdewey-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: meetdewey-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for meetdewey-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4cf0191a242d17e5b8e0827edbb68a51d610f61e1cde6c66b895f7807350b50
MD5 453305d05e6bda17889398050f3544dd
BLAKE2b-256 136641d626933e9e3d6a13bcbda07df9b1a1c0ada4e6f988b72ebd5ef72af686

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