Skip to content

Commit a9e55e8

Browse files
committed
add back example client_batch_check
1 parent eaa826d commit a9e55e8

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,99 @@ If you are using an OpenFGA version less than 1.8.0, you can use `client_batch_c
829829
which calls `check` in parallel. It will return `allowed: false` if it encounters an error, and will return the error in the body.
830830
If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.
831831

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+
832925
#### Expand
833926

834927
Expands the relationships in userset tree format.

0 commit comments

Comments
 (0)