File Service
The FileService handles file-related operations.
The FileService handles file-related operations and is accessed via the file property of an active PerseusClient instance.
Upload File
Uploads a file to the Perseus API. This is a higher-level function that encapsulates create_file and the upload to a presigned URL. If a file with the same content already exists, it will be returned without uploading.
async def upload_file(file_path: str) -> Filedef upload_file(file_path: str) -> FileParameters:
file_path(str): The local path to the file to upload.
Output:
A File object representing the uploaded or existing file, including its ID, name, status, and creation timestamp.
Create File
Creates a file record on the server and returns a presigned URL for uploading the file content.
async def create_file(name: str, source_hash: str) -> Dictdef create_file(name: str, source_hash: str) -> DictParameters:
name(str): The name of the file.source_hash(str): The SHA256 hash of the file's content.
Output:
A dictionary containing:
file: AFileobject representing the newly created file.upload_url: Astr(presigned URL) to which the file content should be uploaded.
Find Files
Finds and retrieves a list of files based on their IDs or source hashes.
async def find_files(ids: Optional[List[str]] = None, source_hashes: Optional[List[str]] = None) -> List[File]def find_files(ids: Optional[List[str]] = None, source_hashes: Optional[List[str]] = None) -> List[File]Parameters:
ids(Optional[List[str]]): A list of file IDs to search for.source_hashes(Optional[List[str]]): A list of SHA256 source hashes to search for.
Output:
A list of File objects matching the criteria. Returns an empty list if no files are found.
Find File
Finds and retrieves a single file by its ID.
async def find_file(id: str) -> Optional[File]def find_file(id: str) -> Optional[File]Parameters:
id(str): The ID of the file to find.
Output:
A File object if a file with the given ID is found, otherwise None.
Delete File
Deletes a file by its ID.
async def delete_file(file_id: str) -> Nonedef delete_file(file_id: str) -> NoneParameters:
file_id(str): The ID of the file to delete.
Output:
None.
Wait for File Upload
Waits for a file's status to become UPLOADED or FAILED. This is useful after getting a presigned URL and uploading the file.
async def wait_for_file_upload(file_id: str, polling_interval: float = 0.5, timeout: int = 3600) -> Filedef wait_for_file_upload(file_id: str, polling_interval: float = 0.5, timeout: int = 3600) -> FileParameters:
file_id(str): The ID of the file to wait for.polling_interval(float): The interval in seconds to poll for the file status. Defaults to0.5.timeout(int): The maximum time in seconds to wait. Defaults to3600.
Output:
The final File object once the upload is complete.