Skip to content

Commit

Permalink
feat: type hinting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
evansims committed Feb 3, 2025
1 parent 24d73b5 commit 9c85094
Show file tree
Hide file tree
Showing 151 changed files with 2,008 additions and 1,522 deletions.
2 changes: 0 additions & 2 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ openfga_sdk/telemetry/counters.py
openfga_sdk/telemetry/histograms.py
openfga_sdk/telemetry/metrics.py
openfga_sdk/telemetry/telemetry.py
openfga_sdk/telemetry/utilities.py
openfga_sdk/validation.py
pyproject.toml
requirements.txt
Expand All @@ -285,5 +284,4 @@ test/telemetry/counters_test.py
test/telemetry/histograms_test.py
test/telemetry/metrics_test.py
test/telemetry/telemetry_test.py
test/telemetry/utilities_test.py
test/test_open_fga_api.py
1 change: 1 addition & 0 deletions example/example1/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from dotenv import load_dotenv


sdk_path = os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
sys.path.insert(0, sdk_path)

Expand Down
1 change: 1 addition & 0 deletions example/example1/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ python-dateutil >= 2.8.2
urllib3 >= 2.1.0
yarl >= 1.9.4
python-dotenv >= 1, <2

1 change: 1 addition & 0 deletions example/example1/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from setuptools import find_packages, setup


NAME = "example1"
VERSION = "0.0.1"
REQUIRES = ["openfga-sdk >= 0.9.1"]
Expand Down
2 changes: 2 additions & 0 deletions example/opentelemetry/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import asyncio
import os
import sys

from operator import attrgetter
from random import randint
from typing import Any
Expand All @@ -29,6 +30,7 @@
)
from opentelemetry.sdk.resources import SERVICE_NAME, Resource


# For usage convenience of this example, we will import the OpenFGA SDK from the parent directory.
sdk_path = os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
sys.path.insert(0, sdk_path)
Expand Down
1 change: 1 addition & 0 deletions example/opentelemetry/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from setuptools import find_packages, setup


NAME = "openfga-opentelemetry-example"
VERSION = "0.0.1"
REQUIRES = [""]
Expand Down
2 changes: 2 additions & 0 deletions example/streamed-list-objects/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import json
import os
import sys

from operator import attrgetter
from typing import Any

from dotenv import load_dotenv


sdk_path = os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
sys.path.insert(0, sdk_path)

Expand Down
1 change: 1 addition & 0 deletions example/streamed-list-objects/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from setuptools import find_packages, setup


NAME = "openfga-streamed-list-objects-example"
VERSION = "0.0.1"
REQUIRES = [""]
Expand Down
2 changes: 2 additions & 0 deletions example/streamed-list-objects/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import json
import os
import sys

from operator import attrgetter
from typing import Any

from dotenv import load_dotenv


sdk_path = os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
sys.path.insert(0, sdk_path)

Expand Down
24 changes: 11 additions & 13 deletions openfga_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@

__version__ = "0.9.1"

from openfga_sdk.client.client import OpenFgaClient
from openfga_sdk.client.configuration import ClientConfiguration

from openfga_sdk.api.open_fga_api import OpenFgaApi

from openfga_sdk.api_client import ApiClient
from openfga_sdk.client.client import OpenFgaClient
from openfga_sdk.client.configuration import ClientConfiguration
from openfga_sdk.configuration import Configuration

from openfga_sdk.exceptions import OpenApiException
from openfga_sdk.exceptions import FgaValidationException
from openfga_sdk.exceptions import ApiValueError
from openfga_sdk.exceptions import ApiKeyError
from openfga_sdk.exceptions import ApiAttributeError
from openfga_sdk.exceptions import ApiException

from openfga_sdk.exceptions import (
ApiAttributeError,
ApiException,
ApiKeyError,
ApiValueError,
FgaValidationException,
OpenApiException,
)
from openfga_sdk.models.aborted_message_response import AbortedMessageResponse
from openfga_sdk.models.any import Any
from openfga_sdk.models.assertion import Assertion
Expand Down Expand Up @@ -137,7 +135,6 @@
from openfga_sdk.models.write_request import WriteRequest
from openfga_sdk.models.write_request_deletes import WriteRequestDeletes
from openfga_sdk.models.write_request_writes import WriteRequestWrites

from openfga_sdk.telemetry.configuration import (
TelemetryConfiguration,
TelemetryConfigurations,
Expand All @@ -146,6 +143,7 @@
TelemetryMetricsConfiguration,
)


__all__ = [
"OpenFgaClient",
"ClientConfiguration",
Expand Down
36 changes: 18 additions & 18 deletions openfga_sdk/api/open_fga_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async def batch_check_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "batch_check",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -375,7 +375,7 @@ async def check_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "check",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -543,7 +543,7 @@ async def create_store_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "create_store",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -692,7 +692,7 @@ async def delete_store_with_http_info(self, **kwargs):

response_types_map = {}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "delete_store",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -873,7 +873,7 @@ async def expand_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "expand",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -1030,7 +1030,7 @@ async def get_store_with_http_info(self, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "get_store",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -1212,7 +1212,7 @@ async def list_objects_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "list_objects",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -1378,7 +1378,7 @@ async def list_stores_with_http_info(self, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "list_stores",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -1559,7 +1559,7 @@ async def list_users_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "list_users",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -1740,7 +1740,7 @@ async def read_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "read",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -1917,7 +1917,7 @@ async def read_assertions_with_http_info(self, authorization_model_id, **kwargs)
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "read_assertions",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -2092,7 +2092,7 @@ async def read_authorization_model_with_http_info(self, id, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "read_authorization_model",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -2266,7 +2266,7 @@ async def read_authorization_models_with_http_info(self, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "read_authorization_models",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -2450,7 +2450,7 @@ async def read_changes_with_http_info(self, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "read_changes",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -2632,7 +2632,7 @@ async def streamed_list_objects_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "streamed_list_objects",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -2813,7 +2813,7 @@ async def write_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "write",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -3007,7 +3007,7 @@ async def write_assertions_with_http_info(

response_types_map = {}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "write_assertions",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down Expand Up @@ -3191,7 +3191,7 @@ async def write_authorization_model_with_http_info(self, body, **kwargs):
500: "InternalErrorMessageResponse",
}

telemetry_attributes: dict[TelemetryAttribute, str | int] = {
telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = {
TelemetryAttributes.fga_client_request_method: "write_authorization_model",
TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(),
TelemetryAttributes.fga_client_request_model_id: local_var_params.get(
Expand Down
13 changes: 9 additions & 4 deletions openfga_sdk/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import re
import time
import urllib

from multiprocessing.pool import ThreadPool

from dateutil.parser import parse
from dateutil.parser import parse # type: ignore[import-untyped]

import openfga_sdk.models
from openfga_sdk import rest, oauth2

from openfga_sdk import oauth2, rest
from openfga_sdk.configuration import Configuration
from openfga_sdk.exceptions import (
ApiException,
Expand All @@ -36,6 +38,7 @@
from openfga_sdk.telemetry import Telemetry
from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes


DEFAULT_USER_AGENT = "openfga-sdk python/0.9.1"


Expand Down Expand Up @@ -166,7 +169,8 @@ async def __call_api(
_request_auth=None,
_retry_params=None,
_oauth2_client=None,
_telemetry_attributes: dict[TelemetryAttribute, str | int] = None,
_telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float]
| None = None,
_streaming: bool = False,
):
self.configuration.is_valid()
Expand Down Expand Up @@ -511,7 +515,8 @@ async def call_api(
_request_auth=None,
_retry_params=None,
_oauth2_client=None,
_telemetry_attributes: dict[TelemetryAttribute, str | int] = None,
_telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float]
| None = None,
_streaming: bool = False,
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
Expand Down
1 change: 1 addition & 0 deletions openfga_sdk/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from openfga_sdk.client.configuration import ClientConfiguration
from openfga_sdk.client.models.check_request import ClientCheckRequest


__all__ = [
"OpenFgaClient",
"ClientConfiguration",
Expand Down
Loading

0 comments on commit 9c85094

Please sign in to comment.