@@ -719,8 +719,9 @@ response = await fga_client.check(body, options)
719719
720720##### Batch Check
721721
722- Run a set of [ checks] ( #check ) . Batch Check will return ` allowed: false ` if it encounters an error, and will return the error in the body.
723- If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.
722+ Similar to [ check] ( #check ) , but instead of checking a single user-object relationship, accepts a list of relationships to check. Requires OpenFGA version 1.8.0 or greater.
723+
724+ [ API Documentation] ( https://openfga.dev/api/service#/Relationship%20Queries/BatchCheck )
724725
725726``` python
726727# from openfga_sdk import OpenFgaClient
@@ -824,6 +825,103 @@ response = await fga_client.batch_check(ClientBatchCheckRequest(checks=checks),
824825# ]
825826```
826827
828+ If you are using an OpenFGA version less than 1.8.0, you can use ` client_batch_check ` ,
829+ which calls ` check ` in parallel. It will return ` allowed: false ` if it encounters an error, and will return the error in the body.
830+ If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.
831+
832+ ``` python
833+ # from openfga_sdk import OpenFgaClient
834+ # from openfga_sdk.client import ClientCheckRequest
835+ # from openfga_sdk.client.models import ClientTuple
836+ # Initialize the fga_client
837+ # fga_client = OpenFgaClient(configuration)
838+
839+ options = {
840+ # You can rely on the model id set in the configuration or override it for this specific request
841+ " authorization_model_id" : " 01GXSA8YR785C4FYS3C0RTG7B1"
842+ }
843+ body = [ClientCheckRequest(
844+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
845+ relation = " viewer" ,
846+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
847+ contextual_tuples = [ # optional
848+ ClientTuple(
849+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
850+ relation = " editor" ,
851+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
852+ ),
853+ ],
854+ context = dict (
855+ ViewCount = 100
856+ )
857+ ), ClientCheckRequest(
858+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
859+ relation = " admin" ,
860+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
861+ contextual_tuples = [ # optional
862+ ClientTuple(
863+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
864+ relation = " editor" ,
865+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
866+ ),
867+ ]
868+ ), ClientCheckRequest(
869+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
870+ relation = " creator" ,
871+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
872+ ), ClientCheckRequest(
873+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
874+ relation = " deleter" ,
875+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
876+ )]
877+
878+ response = await fga_client.client_batch_check(body, options)
879+ # response.responses = [{
880+ # allowed: false,
881+ # request: {
882+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
883+ # relation: "viewer",
884+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
885+ # contextual_tuples: [{
886+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
887+ # relation: "editor",
888+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
889+ # }],
890+ # context=dict(
891+ # ViewCount=100
892+ # )
893+ # }
894+ # }, {
895+ # allowed: false,
896+ # request: {
897+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
898+ # relation: "admin",
899+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
900+ # contextual_tuples: [{
901+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
902+ # relation: "editor",
903+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
904+ # }]
905+ # }
906+ # }, {
907+ # allowed: false,
908+ # request: {
909+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
910+ # relation: "creator",
911+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
912+ # },
913+ # error: <FgaError ...>
914+ # }, {
915+ # allowed: true,
916+ # request: {
917+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
918+ # relation: "deleter",
919+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
920+ # }},
921+ # ]
922+ ```
923+
924+
827925#### Expand
828926
829927Expands the relationships in userset tree format.
0 commit comments