Skip to content

Commit ced4f57

Browse files
committed
feat: change to async python
1 parent 340864d commit ced4f57

180 files changed

Lines changed: 12070 additions & 20129 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ configuration = openfga_sdk.Configuration(
123123
)
124124

125125
# Enter a context with an instance of the API client
126-
with openfga_sdk.ApiClient(configuration) as api_client:
126+
async with openfga_sdk.ApiClient(configuration) as api_client:
127127
# Create an instance of the API class
128128
api_instance = open_fga_api.OpenFgaApi(api_client)
129129

@@ -144,7 +144,7 @@ configuration = openfga_sdk.Configuration(
144144
)
145145

146146
# Enter a context with an instance of the API client
147-
with openfga_sdk.ApiClient(configuration) as api_client:
147+
async with openfga_sdk.ApiClient(configuration) as api_client:
148148
# Create an instance of the API class
149149
api_instance = open_fga_api.OpenFgaApi(api_client)
150150

@@ -164,7 +164,7 @@ configuration = openfga_sdk.Configuration(
164164
configuration.store_id = 'YOUR_STORE_ID'
165165

166166
# Enter a context with an instance of the API client
167-
with openfga_sdk.ApiClient(configuration) as api_client:
167+
async with openfga_sdk.ApiClient(configuration) as api_client:
168168
# Create an instance of the API class
169169
api_instance = open_fga_api.OpenFgaApi(api_client)
170170

@@ -187,7 +187,7 @@ configuration = openfga_sdk.Configuration(
187187
)
188188

189189
# Enter a context with an instance of the API client
190-
with openfga_sdk.ApiClient(configuration) as api_client:
190+
async with openfga_sdk.ApiClient(configuration) as api_client:
191191
# Create an instance of the API class
192192
api_instance = open_fga_api.OpenFgaApi(api_client)
193193

@@ -213,13 +213,15 @@ configuration = openfga_sdk.Configuration(
213213
)
214214

215215
# Create an instance of the API class
216-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
216+
client = openfga_sdk.ApiClient(configuration)
217+
api_instance = open_fga_api.OpenFgaApi()
217218

218219
# Get all stores
219-
response = api_instance.list_stores()
220+
response = await api_instance.list_stores()
220221
# response = ListStoreResponse(...)
221222
# response.stores = [Store({"id": "01FQH7V8BEG3GPQW93KTRFR8JB", "name": "FGA Demo Store", "created_at": "2022-01-01T00:00:00.000Z", "updated_at": "2022-01-01T00:00:00.000Z"})]
222223

224+
await api_client.close()
223225
```
224226

225227
#### Create Store
@@ -233,14 +235,16 @@ configuration = openfga_sdk.Configuration(
233235
)
234236

235237
# Create an instance of the API class
236-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
238+
client = openfga_sdk.ApiClient(configuration)
239+
api_instance = open_fga_api.OpenFgaApi()
237240

238241
# Create a store
239242
body = CreateStoreRequest(
240243
name = "FGA Demo Store",
241244
)
242-
response = api_instance.create_store(body)
245+
response = await api_instance.create_store(body)
243246
# response.id = "01FQH7V8BEG3GPQW93KTRFR8JB"
247+
await api_client.close()
244248
```
245249

246250

@@ -258,11 +262,13 @@ configuration = openfga_sdk.Configuration(
258262
)
259263

260264
# Create an instance of the API class
261-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
265+
client = openfga_sdk.ApiClient(configuration)
266+
api_instance = open_fga_api.OpenFgaApi()
262267

263268
# Get a store
264-
response = api_instance.get_store()
269+
response = await api_instance.get_store()
265270
# response = Store({"id": "01FQH7V8BEG3GPQW93KTRFR8JB", "name": "FGA Demo Store", "created_at": "2022-01-01T00:00:00.000Z", "updated_at": "2022-01-01T00:00:00.000Z"})
271+
await api_client.close()
266272
```
267273

268274

@@ -280,10 +286,12 @@ configuration = openfga_sdk.Configuration(
280286
)
281287

282288
# Create an instance of the API class
283-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
289+
client = openfga_sdk.ApiClient(configuration)
290+
api_instance = open_fga_api.OpenFgaApi()
284291

285292
# Delete a store
286-
api_instance.delete_store()
293+
await api_instance.delete_store()
294+
await api_client.close()
287295
```
288296

289297
#### Write Authorization Model
@@ -304,7 +312,8 @@ configuration = openfga_sdk.Configuration(
304312
)
305313

306314
# Create an instance of the API class
307-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
315+
client = openfga_sdk.ApiClient(configuration)
316+
api_instance = open_fga_api.OpenFgaApi()
308317
type_definitions = TypeDefinitions(
309318
type_definitions=[
310319
TypeDefinition(
@@ -330,8 +339,9 @@ type_definitions = TypeDefinitions(
330339
)
331340

332341
# Create a new authorization model
333-
response = api_instance.write_authorization_model(type_definitions)
342+
response = await api_instance.write_authorization_model(type_definitions)
334343
# response.id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw"
344+
await api_client.close()
335345
```
336346

337347

@@ -347,12 +357,14 @@ configuration = openfga_sdk.Configuration(
347357
)
348358

349359
# Create an instance of the API class
350-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
360+
client = openfga_sdk.ApiClient(configuration)
361+
api_instance = open_fga_api.OpenFgaApi()
351362
id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw" # Assuming `1uHxCSuTP0VKPYSnkq1pbb1jeZw` is an id of an existing model
352363

353364
# Return a particular version of an authorization model
354-
response = api_instance.read_authorization_model(id)
365+
response = await api_instance.read_authorization_model(id)
355366
# response.authorization_model = AuthorizationModel(id='1uHxCSuTP0VKPYSnkq1pbb1jeZw', type_definitions=type_definitions[...])
367+
await api_client.close()
356368
```
357369

358370
#### Read Authorization Model IDs
@@ -367,11 +379,13 @@ configuration = openfga_sdk.Configuration(
367379
)
368380

369381
# Create an instance of the API class
370-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
382+
client = openfga_sdk.ApiClient(configuration)
383+
api_instance = open_fga_api.OpenFgaApi()
371384

372385
# Return all the authorization models for a particular store
373-
response = api_instance.read_authorization_models()
386+
response = await api_instance.read_authorization_models()
374387
# response.authorization_models = [AuthorizationModel(id='1uHxCSuTP0VKPYSnkq1pbb1jeZw', type_definitions=type_definitions[...], AuthorizationModel(id='GtQpMohWezFmIbyXxVEocOCxxgq', type_definitions=type_definitions[...])]
388+
await api_client.close()
375389
```
376390

377391

@@ -387,7 +401,8 @@ configuration = openfga_sdk.Configuration(
387401
)
388402

389403
# Create an instance of the API class
390-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
404+
client = openfga_sdk.ApiClient(configuration)
405+
api_instance = open_fga_api.OpenFgaApi()
391406
body = CheckRequest(
392407
tuple_key=TupleKey(
393408
user="81684243-9356-4421-8fbf-a4f8d36aa31b",
@@ -397,8 +412,9 @@ body = CheckRequest(
397412
)
398413

399414
# Check whether a user is authorized to access an object
400-
response = api_instance.check(body)
415+
response = await api_instance.check(body)
401416
# response.allowed = True
417+
await api_client.close()
402418
```
403419

404420

@@ -414,7 +430,8 @@ configuration = openfga_sdk.Configuration(
414430
)
415431

416432
# Create an instance of the API class
417-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
433+
client = openfga_sdk.ApiClient(configuration)
434+
api_instance = open_fga_api.OpenFgaApi()
418435
body = WriteRequest(
419436
writes=TupleKeys(
420437
tuple_keys=[
@@ -428,7 +445,8 @@ body = WriteRequest(
428445
)
429446

430447
# Add tuples from the store
431-
response = api_instance.write(body)
448+
response = await api_instance.write(body)
449+
await api_client.close()
432450
```
433451

434452
#### Delete Tuples
@@ -443,7 +461,8 @@ configuration = openfga_sdk.Configuration(
443461
)
444462

445463
# Create an instance of the API class
446-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
464+
client = openfga_sdk.ApiClient(configuration)
465+
api_instance = open_fga_api.OpenFgaApi()
447466
body = WriteRequest(
448467
deletes=TupleKeys(
449468
tuple_keys=[
@@ -457,7 +476,8 @@ body = WriteRequest(
457476
)
458477

459478
# Delete tuples from the store
460-
response = api_instance.write(body)
479+
response = await api_instance.write(body)
480+
await api_client.close()
461481
```
462482

463483
#### Expand
@@ -472,7 +492,8 @@ configuration = openfga_sdk.Configuration(
472492
)
473493

474494
# Create an instance of the API class
475-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
495+
client = openfga_sdk.ApiClient(configuration)
496+
api_instance = open_fga_api.OpenFgaApi()
476497
body = ExpandRequest(
477498
tuple_key=TupleKey(
478499
relation="admin",
@@ -481,8 +502,9 @@ body = ExpandRequest(
481502
)
482503

483504
# Expand all relationships in userset tree format, and following userset rewrite rules. Useful to reason about and debug a certain relationship
484-
response = api_instance.expand(body)
505+
response = await api_instance.expand(body)
485506
# response = ExpandResponse({"tree": UsersetTree({"root": Node({"name": "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6#admin", "leaf": Leaf({"users": Users({"users": ["anne", "beth"]})})})})})
507+
await api_client.close()
486508
```
487509

488510
#### Read Changes
@@ -497,7 +519,8 @@ configuration = openfga_sdk.Configuration(
497519
)
498520

499521
# Create an instance of the API class
500-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
522+
client = openfga_sdk.ApiClient(configuration)
523+
api_instance = open_fga_api.OpenFgaApi()
501524

502525
# Find if a relationship tuple stating that a certain user is an admin on a certain workspace
503526
body = ReadRequest(
@@ -532,8 +555,9 @@ body = ReadRequest(
532555
),
533556
)
534557

535-
response = api_instance.read(body)
558+
response = await api_instance.read(body)
536559
# response = ReadResponse({"tuples": [Tuple({"key": TupleKey({"user":"...","relation":"...","object":"..."}), "timestamp": datetime.fromisoformat("...") })]})
560+
await api_client.close()
537561
```
538562

539563
#### Read Changes (Watch)
@@ -549,15 +573,17 @@ configuration = openfga_sdk.Configuration(
549573

550574

551575
# Create an instance of the API class
552-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
576+
client = openfga_sdk.ApiClient(configuration)
577+
api_instance = open_fga_api.OpenFgaApi()
553578
type = "workspace"
554579
page_size = 25
555580
continuation_token = "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ=="
556581

557582
# Return a list of all the tuple changes
558-
response = api_instance.read_changes(type=type, page_size=page_size, continuation_token=continuation_token)
583+
response = await api_instance.read_changes(type=type, page_size=page_size, continuation_token=continuation_token)
559584
# response.continuation_token = ...
560585
# response.changes = [TupleChange(tuple_key=TupleKey(object="...",relation="...",user="..."),operation=TupleOperation("TUPLE_OPERATION_WRITE"),timestamp=datetime.fromisoformat("..."))]
586+
await api_client.close()
561587
```
562588

563589
#### List Objects
@@ -572,7 +598,8 @@ configuration = openfga_sdk.Configuration(
572598
)
573599

574600
# Create an instance of the API class
575-
api_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
601+
client = openfga_sdk.ApiClient(configuration)
602+
api_instance = open_fga_api.OpenFgaApi()
576603
body = ListObjectsRequest(
577604
authorization_model_id="01GAHCE4YVKPQEKZQHT2R89MQV",
578605
user="anne",
@@ -595,8 +622,9 @@ body = ListObjectsRequest(
595622
)
596623

597624
# ListObjects lists all of the object ids for objects of the provided type that the given user has a specific relation with.
598-
response = api_instance.list_objects(body)
625+
response = await api_instance.list_objects(body)
599626
# response.object_ids = ["roadmap"]
627+
await api_client.close()
600628
```
601629

602630

@@ -645,6 +673,7 @@ Class | Method | HTTP request | Description
645673
- [ListObjectsRequest](docs/ListObjectsRequest.md)
646674
- [ListObjectsResponse](docs/ListObjectsResponse.md)
647675
- [ListStoresResponse](docs/ListStoresResponse.md)
676+
- [Metadata](docs/Metadata.md)
648677
- [Node](docs/Node.md)
649678
- [Nodes](docs/Nodes.md)
650679
- [NotFoundErrorCode](docs/NotFoundErrorCode.md)
@@ -656,6 +685,8 @@ Class | Method | HTTP request | Description
656685
- [ReadChangesResponse](docs/ReadChangesResponse.md)
657686
- [ReadRequest](docs/ReadRequest.md)
658687
- [ReadResponse](docs/ReadResponse.md)
688+
- [RelationMetadata](docs/RelationMetadata.md)
689+
- [RelationReference](docs/RelationReference.md)
659690
- [Status](docs/Status.md)
660691
- [Store](docs/Store.md)
661692
- [Tuple](docs/Tuple.md)
@@ -665,7 +696,6 @@ Class | Method | HTTP request | Description
665696
- [TupleOperation](docs/TupleOperation.md)
666697
- [TupleToUserset](docs/TupleToUserset.md)
667698
- [TypeDefinition](docs/TypeDefinition.md)
668-
- [TypeDefinitions](docs/TypeDefinitions.md)
669699
- [Users](docs/Users.md)
670700
- [Userset](docs/Userset.md)
671701
- [UsersetTree](docs/UsersetTree.md)
@@ -674,6 +704,7 @@ Class | Method | HTTP request | Description
674704
- [Usersets](docs/Usersets.md)
675705
- [ValidationErrorMessageResponse](docs/ValidationErrorMessageResponse.md)
676706
- [WriteAssertionsRequest](docs/WriteAssertionsRequest.md)
707+
- [WriteAuthorizationModelRequest](docs/WriteAuthorizationModelRequest.md)
677708
- [WriteAuthorizationModelResponse](docs/WriteAuthorizationModelResponse.md)
678709
- [WriteRequest](docs/WriteRequest.md)
679710

@@ -697,4 +728,4 @@ All changes made to this repo will be overwritten on the next generation, so we
697728

698729
This project is licensed under the Apache-2.0 license. See the [LICENSE](https://github.com/openfga/python-sdk/blob/main/LICENSE) file for more info.
699730

700-
The code in this repo was auto generated by [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) from a template based on the [python template](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/python), licensed under the [Apache License 2.0](https://github.com/OpenAPITools/openapi-generator/blob/master/LICENSE).
731+
The code in this repo was auto generated by [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) from a template based on the [python legacy template](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/python-legacy), licensed under the [Apache License 2.0](https://github.com/OpenAPITools/openapi-generator/blob/master/LICENSE).

docs/Any.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**type** | **str** | | [optional]
8-
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
98

109
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1110

docs/Assertion.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
## Properties
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**expectation** | **bool** | |
87
**tuple_key** | [**TupleKey**](TupleKey.md) | | [optional]
9-
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
8+
**expectation** | **bool** | |
109

1110
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1211

docs/AuthorizationModel.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**id** | **str** | | [optional]
8-
**type_definitions** | [**[TypeDefinition]**](TypeDefinition.md) | | [optional]
9-
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
8+
**type_definitions** | [**list[TypeDefinition]**](TypeDefinition.md) | | [optional]
9+
**schema_version** | **str** | | [optional]
1010

1111
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1212

docs/CheckRequest.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Name | Type | Description | Notes
88
**contextual_tuples** | [**ContextualTupleKeys**](ContextualTupleKeys.md) | | [optional]
99
**authorization_model_id** | **str** | | [optional]
1010
**trace** | **bool** | Defaults to false. Making it true has performance implications. | [optional] [readonly]
11-
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
1211

1312
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1413

docs/CheckResponse.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**allowed** | **bool** | | [optional]
88
**resolution** | **str** | For internal use only. | [optional]
9-
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
109

1110
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1211

docs/Computed.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**userset** | **str** | | [optional]
8-
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
98

109
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1110

0 commit comments

Comments
 (0)