Skip to content

Conversation

@gmazoyer
Copy link
Contributor

@gmazoyer gmazoyer commented Feb 2, 2026

This change adds support to create, update and retrieve nodes which schemas implement CoreFileObject.

The proposed user exposed API follows these key points:

  • node.set_file(content, name) to set file content for upload (supports bytes, Path, or BinaryIO)
  • node.download_file(dest) to download a file to memory or stream to disk

Being able to stream a file to disk or from a disk is important in order to support large files and to avoid them being loaded completely into memory (which would be problematic for +1GB files in general).

The choice of using set_file is to prevent a collision with a potential attribute or relationship called file in the schema. That is also the reason why the file GraphQL parameter is outside the data one instead of inside it.

Here we introduce a couple of components to try to make our code SOLID (it's not much for now, but it's honest work):

  • FileHandler / FileHandlerSync dedicated classes for file I/O operations
  • MultipartBuilder GraphQL Multipart Request Spec payload building

It sure won't make our code SOLID but it won't add to the burden for now.

So given the user who loaded a schema, using our SDK will look like:

Upload a file when creating a node

from pathlib import Path
from infrahub_sdk import InfrahubClientSync

client = InfrahubClientSync()

contract = client.create(
    kind="NetworkCircuitContract", contract_start="2026-01-01", contract_end="2026-12-31"
)

# Set file content (will be streamed from disk)
contract.set_file(content=Path("/tmp/contract.pdf"))

# Save as usual
contract.save()

Download a file from a node

from pathlib import Path

contract = client.get(kind="NetworkCircuitContract", id="abc123")

# Download to memory (suitable for small files)
content = contract.download_file()

# Or stream directly to disk (suitable for large files)
bytes_written = contract.download_file(dest=Path("/tmp/downloaded.pdf"))

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 2, 2026

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: a41ccf8
Status: ✅  Deploy successful!
Preview URL: https://d34a7fc2.infrahub-sdk-python.pages.dev
Branch Preview URL: https://gma-20260202-ihs193.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 64 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/client.py 75.00% 22 Missing and 8 partials ⚠️
infrahub_sdk/file_handler.py 79.68% 20 Missing and 6 partials ⚠️
infrahub_sdk/node/node.py 89.74% 4 Missing and 4 partials ⚠️
@@                 Coverage Diff                  @@
##           infrahub-develop     #792      +/-   ##
====================================================
+ Coverage             80.36%   80.44%   +0.08%     
====================================================
  Files                   115      117       +2     
  Lines                  9865    10192     +327     
  Branches               1504     1543      +39     
====================================================
+ Hits                   7928     8199     +271     
- Misses                 1415     1457      +42     
- Partials                522      536      +14     
Flag Coverage Δ
integration-tests 40.20% <5.96%> (-1.22%) ⬇️
python-3.10 51.77% <57.38%> (+0.39%) ⬆️
python-3.11 51.77% <57.38%> (+0.41%) ⬆️
python-3.12 51.79% <57.38%> (+0.41%) ⬆️
python-3.13 51.79% <57.38%> (+0.41%) ⬆️
python-3.14 53.47% <60.51%> (+0.44%) ⬆️
python-filler-3.12 24.02% <23.29%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/graphql/__init__.py 100.00% <100.00%> (ø)
infrahub_sdk/graphql/constants.py 100.00% <100.00%> (ø)
infrahub_sdk/graphql/multipart.py 100.00% <100.00%> (ø)
infrahub_sdk/graphql/renderers.py 92.94% <100.00%> (+0.08%) ⬆️
infrahub_sdk/node/constants.py 100.00% <100.00%> (ø)
infrahub_sdk/node/node.py 85.60% <89.74%> (+0.25%) ⬆️
infrahub_sdk/file_handler.py 79.68% <79.68%> (ø)
infrahub_sdk/client.py 72.62% <75.00%> (+0.62%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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