Skip to content

Add DiagramsAPI.download_converted_file for diagram convert job downl…#2510

Draft
xgkelly wants to merge 1 commit intomasterfrom
feature/diagram-download-converted-file
Draft

Add DiagramsAPI.download_converted_file for diagram convert job downl…#2510
xgkelly wants to merge 1 commit intomasterfrom
feature/diagram-download-converted-file

Conversation

@xgkelly
Copy link

@xgkelly xgkelly commented Mar 12, 2026

…oads

  • Add download_converted_file method to download PNG/SVG for a page of a convert job
  • Support file_id or file_external_id, page, and mime_type parameters
  • Add unit tests for the new method
  • Add diagram convert download to API client retryable endpoints
  • Add verification script for end-to-end testing

Made-with: Cursor

Description

Please describe the change you have made.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • The PR title follows the Conventional Commit spec.

…oads

- Add download_converted_file method to download PNG/SVG for a page of a convert job
- Support file_id or file_external_id, page, and mime_type parameters
- Add unit tests for the new method
- Add diagram convert download to API client retryable endpoints
- Add verification script for end-to-end testing

Made-with: Cursor
@xgkelly xgkelly requested review from a team as code owners March 12, 2026 15:27
@xgkelly xgkelly marked this pull request as draft March 12, 2026 15:27
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the SDK's capabilities for working with diagram conversion results by providing a dedicated method to download the converted output. This allows users to programmatically retrieve processed diagrams in various formats, streamlining workflows that involve visual assets from the Cognite Data Fusion platform. The addition of a verification script also aids in immediate testing and understanding of the new feature.

Highlights

  • New API Method: Introduced DiagramsAPI.download_converted_file to enable downloading converted diagram files (PNG or SVG) for a specific page of a completed convert job.
  • Flexible File Identification: The new download method supports identifying the target file using either its CDF file_id or file_external_id.
  • Unit Tests: Comprehensive unit tests were added for the download_converted_file method, covering different input parameters and error handling.
  • Retryable Endpoint: The new diagram convert download endpoint has been added to the API client's list of retryable endpoints, improving robustness.
  • Verification Script: A new verification script (verify_diagram_download.py) was added to facilitate end-to-end testing and demonstration of the new download functionality.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • cognite/client/_api/diagrams.py
    • Added download_converted_file method to DiagramsAPI for retrieving converted diagram content.
  • scripts/verify_diagram_download.py
    • Added a new script to verify the functionality of the download_converted_file endpoint.
  • tests/tests_unit/test_api/test_diagrams.py
    • Added TestDiagramDownloadConvertedFile class with unit tests for the new download method, including tests for file_id, file_external_id, and validation of input parameters.
  • tests/tests_unit/test_api_client.py
    • Included the new diagram convert download endpoint in the list of retryable API endpoints.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new download_converted_file method to the DiagramsAPI, enabling users to download converted diagram files. The changes are well-structured, including the core API implementation, unit tests, and a verification script. My review identifies a couple of opportunities to improve adherence to the repository's style guide by using more specific type hints, which will enhance type safety.

"""
if (file_id is None) == (file_external_id is None):
raise ValueError("Exactly one of file_id or file_external_id must be provided")
params: dict[str, Any] = {"page": page}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The type hint for params can be more specific. According to the style guide (line 43), Any should be avoided when possible. The dictionary values are either integers (page, file_id) or a string (file_external_id), so dict[str, int | str] is a more precise type hint.

Suggested change
params: dict[str, Any] = {"page": page}
params: dict[str, int | str] = {"page": page}
References
  1. The style guide requires using specific types instead of Any whenever possible. (link)

client = CogniteClient()

mime_type = "image/png" if args.format == "png" else "image/svg+xml"
kwargs: dict = {"job_id": args.job_id, "page": args.page, "mime_type": mime_type}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The kwargs dictionary is untyped (dict is equivalent to dict[Any, Any]). The style guide emphasizes strong typing and using specific types (lines 5, 42, 43). The keys are strings and the values are a mix of integers and strings. Please provide a more specific type hint like dict[str, int | str].

Suggested change
kwargs: dict = {"job_id": args.job_id, "page": args.page, "mime_type": mime_type}
kwargs: dict[str, int | str] = {"job_id": args.job_id, "page": args.page, "mime_type": mime_type}
References
  1. The style guide requires extensive use of type hints and avoiding Any when possible. (link)

@haakonvt
Copy link
Contributor

@xgkelly thanks for the PR! Please retarget it against the branch pysdk-release-v8 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants