Skip to content
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

feat: add streamed-list-objects endpoint #163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

evansims
Copy link
Member

@evansims evansims commented Jan 16, 2025

Description

This introduces support for OpenFGA's POST /stores/{store_id}/streamed-list-objects endpoint.

The pull request introduces:

  • Adds a new streamed_list_objects() method to the SDK client, simplifying the handling of the streaming endpoint for developers.
  • Adds a new stream() method to the async/sync REST clients, which supports handling of streaming/chunked HTTP network requests.
  • Adds a new build_request() method to the async/sync REST clients to handle the request-building steps shared by the request() and stream() methods.
  • Adds a new handle_response_exception() method to the async/sync REST clients to handle the HTTP response exception processing shared between the request() and stream() methods.
  • Adds a new _accumulate_json_lines() private method to the async/sync REST clients to help collect and reassemble partially delivered packets from streaming/chunked HTTP network requests. This method is used by stream().
  • Adds the OpenAPI-generated streamed_list_objects_response and stream_result_of_streamed_list_objects_response models.
  • Adds a new /example/streamed-list-objects example app, demonstrating usage through both the asynchronous and synchronous clients.
  • Adds a new section to the README to demonstrate usage.
  • Adds the pytest-asyncio dependency to simplify working with async method tests.
  • Adds the test/rest_test.py and test/sync/rest_test.py test suites to target all methods in the refactored classes. It includes tests for the new streaming APIs.

It changes:

  • Updates the async/sync API clients to use the streamlined REST client APIs.
  • Updates the async/sync API clients to support a _streaming parameter on appropriate methods, which helps direct the flow of
  • Updates the async/sync OAuth2 clients to use the streamlined REST client APIs.
  • Updates the request() method of the async/sync REST clients.
  • Refactors the async/sync REST clients to improve type-hinting.
  • Updates other test suites to accommodate the streamlined REST client APIs.

And removes:

  • Removes the GET(), HEAD(), OPTIONS(), POST(), PUT(), PATCH(), and DELETE() helper methods from the async/sync REST clients, to streamline the class and reduce redundant code.

Usage Example:

Using the async client:

# from openfga_sdk import OpenFgaClient
# from openfga_sdk.client.models import ClientListObjectsRequest

# Initialize the fga_client
# fga_client = OpenFgaClient(configuration)

results = []

documents = ClientListObjectsRequest(
    type="document",
    relation="writer",
    user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
)

async for response in fga_client.streamed_list_objects(request):
    results.append(response)

# results = ["document:...", ...]

You can also review the new /example/streamed-list-objects/asynchronous.py (or synchronous.py) app for a more detailed usage demo.

References

This code is generated using the SDK Generator; the pull request, including these changes, can be reviewed at its repository here: openfga/sdk-generator#469

The relevant issue for tracking this feature can be found her: openfga/sdk-generator#76

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@evansims evansims added the enhancement New feature or request label Jan 16, 2025
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 54.79452% with 198 lines in your changes missing coverage. Please review.

Project coverage is 69.56%. Comparing base (1d93d1b) to head (590f561).

Files with missing lines Patch % Lines
...stream_result_of_streamed_list_objects_response.py 34.92% 41 Missing ⚠️
...enfga_sdk/models/streamed_list_objects_response.py 32.72% 37 Missing ⚠️
openfga_sdk/api/open_fga_api.py 5.55% 34 Missing ⚠️
openfga_sdk/sync/open_fga_api.py 5.55% 34 Missing ⚠️
openfga_sdk/sync/rest.py 81.89% 21 Missing ⚠️
openfga_sdk/sync/client/client.py 18.18% 9 Missing ⚠️
openfga_sdk/client/client.py 20.00% 8 Missing ⚠️
openfga_sdk/rest.py 90.47% 8 Missing ⚠️
openfga_sdk/api_client.py 66.66% 2 Missing ⚠️
openfga_sdk/models/expand_request.py 77.77% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #163      +/-   ##
==========================================
+ Coverage   69.49%   69.56%   +0.07%     
==========================================
  Files         133      135       +2     
  Lines       10554    10839     +285     
==========================================
+ Hits         7334     7540     +206     
- Misses       3220     3299      +79     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants