From 51003d9cb1df50250d333662c95929445643199d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 5 Jan 2026 16:25:51 +0100 Subject: [PATCH 1/2] added helper methods to download project files --- ayon_api/__init__.py | 4 ++ ayon_api/_api.py | 74 +++++++++++++++++++++++++++++++++++ ayon_api/_api_helpers/base.py | 22 +++++++++++ ayon_api/server_api.py | 70 +++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+) diff --git a/ayon_api/__init__.py b/ayon_api/__init__.py index 8d3ef554c..c43bfcdb1 100644 --- a/ayon_api/__init__.py +++ b/ayon_api/__init__.py @@ -70,6 +70,8 @@ delete, download_file_to_stream, download_file, + download_project_file, + download_project_file_to_stream, upload_file_from_stream, upload_file, upload_reviewable, @@ -349,6 +351,8 @@ "delete", "download_file_to_stream", "download_file", + "download_project_file", + "download_project_file_to_stream", "upload_file_from_stream", "upload_file", "upload_reviewable", diff --git a/ayon_api/_api.py b/ayon_api/_api.py index c13198cbb..d92f0af8b 100644 --- a/ayon_api/_api.py +++ b/ayon_api/_api.py @@ -992,6 +992,80 @@ def download_file( ) +def download_project_file( + project_name: str, + file_id: str, + filepath: str, + *, + chunk_size: Optional[int] = None, + progress: Optional[TransferProgress] = None, +) -> TransferProgress: + """Download project file to filepath. + + Project files are usually binary files, such as images, videos, + or other media files that can be accessed via api endpoint + '{server url}/api/projects/{project_name}/files/{file_id}'. + + Args: + project_name (str): Project name. + file_id (str): File id. + filepath (str): Path where file will be downloaded. + chunk_size (Optional[int]): Size of chunks that are received + in single loop. + progress (Optional[TransferProgress]): Object that gives ability + to track download progress. + + Returns: + TransferProgress: Progress object. + + """ + con = get_server_api_connection() + return con.download_project_file( + project_name=project_name, + file_id=file_id, + filepath=filepath, + chunk_size=chunk_size, + progress=progress, + ) + + +def download_project_file_to_stream( + project_name: str, + file_id: str, + stream: StreamType, + *, + chunk_size: Optional[int] = None, + progress: Optional[TransferProgress] = None, +) -> TransferProgress: + """Download project file to a stream. + + Project files are usually binary files, such as images, videos, + or other media files that can be accessed via api endpoint + '{server url}/api/projects/{project_name}/files/{file_id}'. + + Args: + project_name (str): Project name. + file_id (str): File id. + stream (StreamType): Stream where output will be stored. + chunk_size (Optional[int]): Size of chunks that are received + in single loop. + progress (Optional[TransferProgress]): Object that gives ability + to track download progress. + + Returns: + TransferProgress: Progress object. + + """ + con = get_server_api_connection() + return con.download_project_file_to_stream( + project_name=project_name, + file_id=file_id, + stream=stream, + chunk_size=chunk_size, + progress=progress, + ) + + def upload_file_from_stream( endpoint: str, stream: StreamType, diff --git a/ayon_api/_api_helpers/base.py b/ayon_api/_api_helpers/base.py index bf209a0a1..f39604ee7 100644 --- a/ayon_api/_api_helpers/base.py +++ b/ayon_api/_api_helpers/base.py @@ -108,6 +108,28 @@ def download_file( ) -> TransferProgress: raise NotImplementedError() + def download_project_file( + self, + project_name: str, + file_id: str, + filepath: str, + *, + chunk_size: Optional[int] = None, + progress: Optional[TransferProgress] = None, + ) -> TransferProgress: + raise NotImplementedError() + + def download_project_file_to_stream( + self, + project_name: str, + file_id: str, + stream: StreamType, + *, + chunk_size: Optional[int] = None, + progress: Optional[TransferProgress] = None, + ) -> TransferProgress: + raise NotImplementedError() + def get_rest_entity_by_id( self, project_name: str, diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index e79256bc3..06bfb83d1 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -1496,6 +1496,76 @@ def download_file( return progress + def download_project_file( + self, + project_name: str, + file_id: str, + filepath: str, + *, + chunk_size: Optional[int] = None, + progress: Optional[TransferProgress] = None, + ) -> TransferProgress: + """Download project file to filepath. + + Project files are usually binary files, such as images, videos, + or other media files that can be accessed via api endpoint + '{server url}/api/projects/{project_name}/files/{file_id}'. + + Args: + project_name (str): Project name. + file_id (str): File id. + filepath (str): Path where file will be downloaded. + chunk_size (Optional[int]): Size of chunks that are received + in single loop. + progress (Optional[TransferProgress]): Object that gives ability + to track download progress. + + Returns: + TransferProgress: Progress object. + + """ + return self.download_file( + f"api/projects/{project_name}/files/{file_id}", + filepath, + chunk_size=chunk_size, + progress=progress, + ) + + def download_project_file_to_stream( + self, + project_name: str, + file_id: str, + stream: StreamType, + *, + chunk_size: Optional[int] = None, + progress: Optional[TransferProgress] = None, + ) -> TransferProgress: + """Download project file to a stream. + + Project files are usually binary files, such as images, videos, + or other media files that can be accessed via api endpoint + '{server url}/api/projects/{project_name}/files/{file_id}'. + + Args: + project_name (str): Project name. + file_id (str): File id. + stream (StreamType): Stream where output will be stored. + chunk_size (Optional[int]): Size of chunks that are received + in single loop. + progress (Optional[TransferProgress]): Object that gives ability + to track download progress. + + Returns: + TransferProgress: Progress object. + + """ + return self.download_file_to_stream( + f"api/projects/{project_name}/files/{file_id}", + stream, + chunk_size=chunk_size, + progress=progress, + ) + @staticmethod def _upload_chunks_iter( file_stream: StreamType, From d2481e110288890c0995211f4c52e991cdd9d9c6 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 6 Jan 2026 09:16:16 +0100 Subject: [PATCH 2/2] remove methods from base --- ayon_api/_api_helpers/base.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/ayon_api/_api_helpers/base.py b/ayon_api/_api_helpers/base.py index f39604ee7..bf209a0a1 100644 --- a/ayon_api/_api_helpers/base.py +++ b/ayon_api/_api_helpers/base.py @@ -108,28 +108,6 @@ def download_file( ) -> TransferProgress: raise NotImplementedError() - def download_project_file( - self, - project_name: str, - file_id: str, - filepath: str, - *, - chunk_size: Optional[int] = None, - progress: Optional[TransferProgress] = None, - ) -> TransferProgress: - raise NotImplementedError() - - def download_project_file_to_stream( - self, - project_name: str, - file_id: str, - stream: StreamType, - *, - chunk_size: Optional[int] = None, - progress: Optional[TransferProgress] = None, - ) -> TransferProgress: - raise NotImplementedError() - def get_rest_entity_by_id( self, project_name: str,