The Chunkr AI SDK provides two main methods for uploading files:
upload()
: Upload and wait for complete processing
create_task()
: Upload and get an immediate task response
Complete Processing with upload()
The upload()
method handles the entire process - it uploads your file and waits for processing to complete:
from chunkr_ai import Chunkr
chunkr = Chunkr()
# Upload and wait for complete processing
task = chunkr.upload("path/to/your/file")
# All processing is done - you can access results immediately
print(task.task_id)
print(task.status) # Will be "completed"
print(task.output) # Contains processed results
Instant Response with create_task()
If you want to start processing but don’t want to wait for completion, use create_task()
:
# Create task without waiting
task = chunkr.create_task("path/to/your/file")
# Task is created but processing may not be complete
print(task.task_id)
print(task.status) # Might be "Starting"
print(task.output) # Might be None if processing isn't finished
Checking Task Status with poll()
When using create_task()
, you can check the status later using poll()
:
# Create task immediately
task = chunkr.create_task("path/to/your/file")
# ... do other work ...
# Check status when needed
result = task.poll()
print(result.status)
print(result.output) # Now contains processed results if status is "Succeeded"
For async applications, remember to use await
:
# Create task immediately
task = await chunkr.create_task("path/to/your/file")
# ... do other work ...
# Check status when needed
result = await task.poll()
Supported File Types
We support PDFs, Office files (Word, Excel, PowerPoint), and images. You can upload them in several ways:
# From a file path
task = chunkr.upload("path/to/your/file")
# From an opened file
with open("path/to/your/file", "rb") as f:
task = chunkr.upload(f)
# From a URL
task = chunkr.upload("https://example.com/document.pdf")
# From a base64 string
task = chunkr.upload("JVBERi0...")
# From a PIL Image
from PIL import Image
img = Image.open("path/to/your/photo.jpg")
task = chunkr.upload(img)