File Operations

Find File

The find_file function allows you to retrieve a single file by its unique ID.

Synchronous

find_file

def find_file(id: str) -> Optional[File]:

Finds a single file by its ID.

Arguments

NameTypeDescription
idstrThe unique ID of the file.

Returns

TypeDescription
Optional[File]A File object if found, otherwise None.

Example

import perseus_client

try:
    file = perseus_client.find_file("your_file_id")
    if file:
        print(f"File found: {file.name}")
    else:
        print("File not found.")
except Exception as e:
    print(f"An error occurred: {e}")

Asynchronous

find_file_async

async def find_file_async(id: str) -> Optional[File]:

Asynchronously finds a single file by its ID.

Arguments

NameTypeDescription
idstrThe unique ID of the file.

Returns

TypeDescription
Optional[File]A File object if found, otherwise None.

Example

import asyncio
import perseus_client

async def main():
    try:
        file = await perseus_client.find_file_async("your_file_id")
        if file:
            print(f"File found: {file.name}")
        else:
            print("File not found.")
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        await perseus_client.close_async()

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