File Operations
Wait for File Upload
The wait_for_file_upload function polls the status of a file upload until it is completed or fails.
Synchronous
wait_for_file_upload
def wait_for_file_upload(
file_id: str,
polling_interval: float = 0.5,
timeout: int = 3600,
) -> File:Waits for a file upload to complete.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
file_id | str | The ID of the file to wait for. | - |
polling_interval | float | The interval in seconds between status checks. | 0.5 |
timeout | int | The maximum time in seconds to wait. | 3600 |
Returns
| Type | Description |
|---|---|
File | The completed File object with its final status. |
Example
import perseus_client
# Assume you have just uploaded a file and have its ID
file_id = "your_uploaded_file_id"
try:
print("Waiting for file upload to complete...")
file = perseus_client.wait_for_file_upload(file_id)
print(f"File processing finished with status: {file.status.value}")
except Exception as e:
print(f"An error occurred: {e}")Asynchronous
wait_for_file_upload_async
async def wait_for_file_upload_async(
file_id: str,
polling_interval: float = 0.5,
timeout: int = 3600,
) -> File:Asynchronously waits for a file upload to complete.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
file_id | str | The ID of the file to wait for. | - |
polling_interval | float | The interval in seconds between status checks. | 0.5 |
timeout | int | The maximum time in seconds to wait. | 3600 |
Returns
| Type | Description |
|---|---|
File | The completed File object with its final status. |
Example
import asyncio
import perseus_client
# Assume you have just uploaded a file and have its ID
file_id = "your_uploaded_file_id"
async def main():
try:
print("Waiting for file upload to complete...")
file = await perseus_client.wait_for_file_upload_async(file_id)
print(f"File processing finished with status: {file.status.value}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
await perseus_client.close_async()
if __name__ == "__main__":
asyncio.run(main())