@@ -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,82 @@ 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 the ` clientBatchCheck ` function,
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+ @@ - 748 ,7 + 750 ,7 @@
848+ context = dict (
849+ ViewCount = 100
850+ )
851+ ), ClientCheckRequest(
852+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
853+ relation = " admin" ,
854+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
855+ @@ - 759 ,20 + 761 ,21 @@
856+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
857+ ),
858+ ]
859+ ), ClientCheckRequest(
860+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
861+ relation = " creator" ,
862+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
863+ ), ClientCheckRequest(
864+ user = " user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
865+ relation = " deleter" ,
866+ object = " document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ,
867+ )]
868+
869+ response = await fga_client.batch_check(body, options)
870+ # response.responses = [{
871+ # allowed: false,
872+ # request: {
873+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
874+ # relation: "viewer",
875+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
876+ @@ - 787 ,7 + 790 ,8 @@
877+ # }
878+ # }, {
879+ # allowed: false,
880+ # request: {
881+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
882+ # relation: "admin",
883+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
884+ @@ - 799 ,35 + 803 ,40 @@
885+ # }
886+ # }, {
887+ # allowed: false,
888+ # request: {
889+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
890+ # relation: "creator",
891+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
892+ # },
893+ # error: <FgaError ...>
894+ # }, {
895+ # allowed: true,
896+ # request: {
897+ # user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
898+ # relation: "deleter",
899+ # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
900+ # }},
901+ # ]
902+ ```
903+
827904#### Expand
828905
829906Expands the relationships in userset tree format.
0 commit comments