-
Notifications
You must be signed in to change notification settings - Fork 63
feat(python-sdk): api executor for calling arbitrary endpoints #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SoulPancake
wants to merge
1
commit into
main
Choose a base branch
from
feat/python-sdk/apiexecutor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+607
−287
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,53 @@ | ||
| --- clients/fga-python-sdk/openfga_sdk/api/open_fga_api.py 2022-09-13 14:15:46.000000000 -0400 | ||
| +++ open_fga_api.py 2022-09-13 14:14:01.000000000 -0400 | ||
| @@ -229,8 +236,10 @@ | ||
| --- clients/fga-python-sdk/openfga_sdk/api/open_fga_api.py | ||
| +++ open_fga_api.py | ||
| @@ -501,13 +501,15 @@ | ||
| local_var_params=local_var_params, | ||
| ) | ||
|
|
||
| - async def create_store(self, **kwargs): | ||
| + async def create_store(self, body, **kwargs): | ||
| """Create a store | ||
|
|
||
| Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. | ||
|
|
||
| - >>> thread = await api.create_store() | ||
| - | ||
| + >>> thread = await api.create_store(body) | ||
|
|
||
| + | ||
| + :param body: (required) | ||
| + :type body: CreateStoreRequest | ||
| :param async_req: Whether to execute the request asynchronously. | ||
| @@ -216,15 +218,17 @@ | ||
| :type async_req: bool, optional | ||
| :param _preload_content: if False, the urllib3.HTTPResponse object will | ||
| @@ -524,15 +526,17 @@ | ||
| :rtype: CreateStoreResponse | ||
| """ | ||
| kwargs["_return_http_data_only"] = True | ||
| - return await self.create_store_with_http_info(**kwargs) | ||
| + return await self.create_store_with_http_info(body, **kwargs) | ||
|
|
||
| - | ||
| - async def create_store_with_http_info(self, **kwargs): | ||
| + return await self.create_store_with_http_info(body, **kwargs) | ||
| + | ||
| + async def create_store_with_http_info(self, body, **kwargs): | ||
| """Create a store | ||
|
|
||
| Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. | ||
|
|
||
| - >>> thread = api.create_store_with_http_info() | ||
| - | ||
| + >>> thread = api.create_store_with_http_info(body) | ||
|
|
||
| + | ||
| + :param body: (required) | ||
| + :type body: CreateStoreRequest | ||
| :param async_req: Whether to execute the request asynchronously. | ||
| :type async_req: bool, optional | ||
| :param _return_http_data_only: response data without head status code | ||
| @@ -253,6 +257,8 @@ | ||
| @@ -561,7 +565,7 @@ | ||
| local_var_params = locals() | ||
|
|
||
| all_params = [ | ||
|
|
||
| - | ||
| + 'body' | ||
| + | ||
| ] | ||
| all_params.extend( | ||
| [ | ||
| @@ -368,3 +370,3 @@ | ||
| return await (self.api_client.call_api( | ||
| - '/stores'.replace('{store_id}', store_id), 'POST', | ||
| + '/stores', 'POST', | ||
| path_params, | ||
| @@ -1192,3 +1194,3 @@ | ||
| return await (self.api_client.call_api( | ||
| - '/stores'.replace('{store_id}', store_id), 'GET', | ||
| + '/stores', 'GET', | ||
| path_params, |
78 changes: 78 additions & 0 deletions
78
config/clients/python/template/README_calling_other_endpoints.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| In certain cases you may want to call other APIs not yet wrapped by the SDK. You can do so by using the `execute_api_request` method available on the `{{appShortName}}Client`. It allows you to make raw HTTP calls to any OpenFGA endpoint by specifying the HTTP method, path, body, query parameters, and path parameters, while still honoring the client configuration (authentication, telemetry, retries, and error handling). | ||
|
|
||
| For streaming endpoints, use `execute_streamed_api_request` instead. | ||
|
|
||
| This is useful when: | ||
| - You want to call a new endpoint that is not yet supported by the SDK | ||
| - You are using an earlier version of the SDK that doesn't yet support a particular endpoint | ||
| - You have a custom endpoint deployed that extends the OpenFGA API | ||
|
|
||
| #### Example: Calling a Custom Endpoint with POST | ||
|
|
||
| ```python | ||
| # Call a custom endpoint using path parameters | ||
| response = await fga_client.execute_api_request( | ||
| operation_name="CustomEndpoint", # For telemetry/logging | ||
| method="POST", | ||
| path="/stores/{store_id}/custom-endpoint", | ||
| path_params={"store_id": FGA_STORE_ID}, | ||
| body={ | ||
| "user": "user:bob", | ||
| "action": "custom_action", | ||
| "resource": "resource:123", | ||
| }, | ||
| query_params={ | ||
| "page_size": 20, | ||
| }, | ||
| ) | ||
|
|
||
| # Access the response data | ||
| if response.status == 200: | ||
| result = response.json() | ||
| print(f"Response: {result}") | ||
| ``` | ||
|
|
||
| #### Example: Calling an existing endpoint with GET | ||
|
|
||
| ```python | ||
| # Get a list of stores with query parameters | ||
| stores_response = await fga_client.execute_api_request( | ||
| operation_name="ListStores", | ||
| method="GET", | ||
| path="/stores", | ||
| query_params={ | ||
| "page_size": 10, | ||
| "continuation_token": "eyJwayI6...", | ||
| }, | ||
| ) | ||
|
|
||
| stores = stores_response.json() | ||
| print("Stores:", stores) | ||
| ``` | ||
|
|
||
| #### Example: Using Path Parameters | ||
|
|
||
| Path parameters are specified in the path using `{param_name}` syntax and are replaced with URL-encoded values from the `path_params` dictionary. If `{store_id}` is present in the path and not provided in `path_params`, it will be automatically replaced with the configured store_id: | ||
|
|
||
| ```python | ||
| # Using explicit path parameters | ||
| response = await fga_client.execute_api_request( | ||
| operation_name="GetAuthorizationModel", | ||
| method="GET", | ||
| path="/stores/{store_id}/authorization-models/{model_id}", | ||
| path_params={ | ||
| "store_id": "your-store-id", | ||
| "model_id": "your-model-id", | ||
| }, | ||
| ) | ||
|
|
||
| # Using automatic store_id substitution | ||
| response = await fga_client.execute_api_request( | ||
| operation_name="GetAuthorizationModel", | ||
| method="GET", | ||
| path="/stores/{store_id}/authorization-models/{model_id}", | ||
| path_params={ | ||
| "model_id": "your-model-id", | ||
| }, | ||
| ) | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.