File Operations

Find Files

The find_files function allows you to retrieve a list of files from the Perseus server based on specified criteria.

Synchronous

find_files

def find_files(
    ids: Optional[List[str]] = None,
    source_hashes: Optional[List[str]] = None,
) -> list[File]:

Finds files matching the provided IDs or source hashes.

Arguments

NameTypeDescriptionDefault
idsOptional[List[str]]A list of file IDs to retrieve.None
source_hashesOptional[List[str]]A list of source hashes to retrieve files by.None

Returns

TypeDescription
List[File]A list of File objects that match the query.

Example

import perseus_client

try:
    # Find by IDs
    files_by_id = perseus_client.find_files(ids=["file_id_1", "file_id_2"])
    print(f"Found {len(files_by_id)} files by ID.")

    # Find by source hashes
    files_by_hash = perseus_client.find_files(source_hashes=["hash1", "hash2"])
    print(f"Found {len(files_by_hash)} files by source hash.")

except Exception as e:
    print(f"An error occurred: {e}")

Asynchronous

find_files_async

async def find_files_async(
    ids: Optional[List[str]] = None,
    source_hashes: Optional[List[str]] = None,
) -> list[File]:

Asynchronously finds files matching the provided IDs or source hashes.

Arguments

NameTypeDescriptionDefault
idsOptional[List[str]]A list of file IDs to retrieve.None
source_hashesOptional[List[str]]A list of source hashes to retrieve files by.None

Returns

TypeDescription
List[File]A list of File objects that match the query.

Example

import asyncio
import perseus_client

async def main():
    try:
        # Find by IDs
        files_by_id = await perseus_client.find_files_async(ids=["file_id_1", "file_id_2"])
        print(f"Found {len(files_by_id)} files by ID.")

        # Find by source hashes
        files_by_hash = await perseus_client.find_files_async(source_hashes=["hash1", "hash2"])
        print(f"Found {len(files_by_hash)} files by source hash.")

    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        await perseus_client.close_async()

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