File Operations

Upload File

The upload_file function allows you to upload a file to the Perseus server.

Synchronous

upload_file

def upload_file(file_path: str) -> File:

Uploads a file and returns a File object.

Arguments

NameTypeDescription
file_pathstrThe local path to the file to upload.

Returns

TypeDescription
FileA File object representing the uploaded file.

Example

import perseus_client

try:
    file = perseus_client.upload_file("./path/to/your/file.txt")
    print(f"File uploaded successfully with ID: {file.id}")
except Exception as e:
    print(f"An error occurred: {e}")

Asynchronous

upload_file_async

async def upload_file_async(file_path: str) -> File:

Asynchronously uploads a file and returns a File object.

Arguments

NameTypeDescription
file_pathstrThe local path to the file to upload.

Returns

TypeDescription
FileA File object representing the uploaded file.

Example

import asyncio
import perseus_client

async def main():
    try:
        file = await perseus_client.upload_file_async("./path/to/your/file.txt")
        print(f"File uploaded successfully with ID: {file.id}")
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        await perseus_client.close_async()

if __name__ == "__main__":
    asyncio.run(main())