github openfga/python-sdk v0.9.0

14 hours ago

0.9.0 (2024-12-19)

Added:

  • feat: add support for start_time parameter in ReadChanges endpoint (#156) - Note, this feature requires v1.8.0 of OpenFGA or newer
  • feat!: add support for BatchCheck API (#154) - Note, this feature requires v1.8.2 of OpenFGA or newer

Changed:

Warning

Usage of the existing batch_check should now use client_batch_check instead, additionally the existing
BatchCheckResponse has been renamed to ClientBatchCheckClientResponse.

Please see below for how to migrate your code, and #154 for more details on this change.

Migration

"I want to continue using client side batch check"

Given that this necessitates an upgrade of OpenFGA, it might not be feasible for everyone to switch to the new server based method, if you wish to delay the migration, rename the existing usage to the new method name as shown below.

- client.batch_check()
+ client.client_batch_check()

"I want to migrate to the new server based batch check"

If you wish to migrate to the new method, whilst the method name remains the same. You will need to alter the way you construct the checks passed.

  • Previously a list of ClientCheckRequest was constructed and passed directly to batch_check, now you should construct a list of ClientBatchCheckItem and pass a ClientBatchCheckRequest to batch_check with that list as the checks property
    • The correlation_id on a ClientBatchCheckItem is set for you if you do not provide it.
  • The result now contains a correlation_id property in addition to the error and request types and has removed the response property. Additionally, the error property is now of a CheckError type, rather than an Exception type.
checks = [
-  ClientCheckRequest(
+  ClientBatchCheckItem(
        user="user:1",
        relation="owner",
        object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
        contextual_tuples=[
            ClientTuple(
                user="user:1",
                relation="owner",
                object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
            )
        ]
    ),
-  ClientCheckRequest(
+  ClientBatchCheckItem(
        user="use:2",
        relation="owner",
        object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
    )
]

- result = fga_client.client_batch_check(checks)
+ result = fga_client.batch_check(ClientBatchCheckRequest(checks=checks))

# response.result = [{
#   allowed: true,
#   correlation_id: "de3630c2-f9be-4ee5-9441-cb1fbd82ce75", # generated by the SDK
#   tuple: {
#     user: "user:1",
#     relation: "viewer",
#     object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
#     contextual_tuples: [{
#       user: "user:1",
#       relation: "editor",
#       object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
#     }]
#   }
# }, {
#   allowed: false,
#   correlation_id: "6d7c7129-9607-480e-bfd0-17c16e46b9ec",
#   tuple: {
#     user="user:2",
#     relation="own",
#     object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
#   },
#   error: {
#     input_error: "validation_error",
#     message: "type 'doc' not found"
#   }
# }] 

Don't miss a new python-sdk release

NewReleases is sending notifications on new releases.