Chunkr AI’s SDK supports both synchronous and asynchronous usage patterns.
The same client class Chunkr can be used for both patterns, making it flexible for different application needs.
All methods exists in both synchronous and asynchronous versions.
For simple scripts or applications that don’t require asynchronous operations, you can use the synchronous pattern:
Copy
Ask AI
from chunkr_ai import Chunkr# Initialize clientchunkr = Chunkr()try: # Upload a file and wait for processing task = chunkr.upload("document.pdf") print(task.task_id) # Alternatively, create task without waiting - you will get back a task object without chunks task = chunkr.create_task("document.pdf") # Poll the task when ready - this will wait for the task to complete and return a task object with chunks task.poll() print(task.output.chunks)finally: # Clean up when done chunkr.close()
For applications that benefit from asynchronous operations (like web servers or background tasks), you can use the async pattern:
Copy
Ask AI
from chunkr_ai import Chunkrimport asyncioasync def process_document(): # Initialize client chunkr = Chunkr() try: # Upload a file and wait for processing task = await chunkr.upload("document.pdf") print(task.task_id) # Alternatively, create task without waiting - you will get back a task object without chunks task = await chunkr.create_task("document.pdf") # Poll the task when ready - this will wait for the task to complete and return a task object with chunks await task.poll() print(task.output.chunks) finally: # Clean up when done chunkr.close()