diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 7905f94a..2b826dce 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: 8b5fa338-9106-4734-abf0-e30d67044a90 management: - docChecksum: 83f88cfa4bd77e1d3065b11a97119361 + docChecksum: de9f013dc09f5ad50eaa7dd5716106ca docVersion: 1.0.78 speakeasyVersion: 1.490.0 generationVersion: 2.512.0 @@ -24,6 +24,7 @@ features: globalSecurity: 3.0.3 globalSecurityCallbacks: 1.0.0 globalSecurityFlattening: 1.0.0 + globalServerURLs: 3.1.0 methodServerURLs: 3.1.1 multipartFileContentType: 1.0.0 nameOverrides: 3.0.1 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index b0d3c49b..053b17c9 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,21 +1,20 @@ -speakeasyVersion: 1.505.0 +speakeasyVersion: 1.508.1 sources: my-source: sourceNamespace: my-source - sourceRevisionDigest: sha256:8cba0cf748e247efccefbb5d1839dbeb6e2e3210bb2c90f7b75b9034c22ae24a - sourceBlobDigest: sha256:69fef8ed681f1d68013e71f67927821d64fc1045d3956ace3775fe62ed76b8bb + sourceRevisionDigest: sha256:7c3885b2b10e35c3ce714ade8cf040b7af2d30c631aa9469af14c647e4eebd4c + sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817 tags: - latest - - speakeasy-sdk-regen-1740605410 - - 1.0.68 + - 1.0.78 targets: unstructured-python: source: my-source sourceNamespace: my-source - sourceRevisionDigest: sha256:8cba0cf748e247efccefbb5d1839dbeb6e2e3210bb2c90f7b75b9034c22ae24a - sourceBlobDigest: sha256:69fef8ed681f1d68013e71f67927821d64fc1045d3956ace3775fe62ed76b8bb + sourceRevisionDigest: sha256:7c3885b2b10e35c3ce714ade8cf040b7af2d30c631aa9469af14c647e4eebd4c + sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817 codeSamplesNamespace: my-source-code-samples - codeSamplesRevisionDigest: sha256:d7a20fe1c8d687f377099cdb412c6d0dd733dd982ec4662052df0894da211da2 + codeSamplesRevisionDigest: sha256:5f12b0195d8ed16e87269dc286ef0b48ba59a6c95b2ad935f85ec95e417394ae workflow: workflowVersion: 1.0.0 speakeasyVersion: latest @@ -23,7 +22,7 @@ workflow: my-source: inputs: - location: https://platform.unstructuredapp.io/openapi.json - - location: https://api.unstructured.io/general/openapi.json + - location: https://api.unstructuredapp.io/general/openapi.json overlays: - location: ./overlay_client.yaml registry: diff --git a/_test_unstructured_client/unit/test_custom_hooks.py b/_test_unstructured_client/unit/test_custom_hooks.py index 724a2d5f..954e8a5c 100644 --- a/_test_unstructured_client/unit/test_custom_hooks.py +++ b/_test_unstructured_client/unit/test_custom_hooks.py @@ -211,12 +211,6 @@ def test_unit_clean_server_url_fixes_malformed_localhost_url(server_url: str): assert client.general.sdk_configuration.server_url == "http://localhost:8000" - -def test_unit_clean_server_url_returns_None_given_no_server_url(): - client = UnstructuredClient(api_key_auth=FAKE_KEY) - assert client.general.sdk_configuration.server_url == None - - @pytest.mark.parametrize( "server_url", [ diff --git a/codeSamples.yaml b/codeSamples.yaml index 37e062dc..1723532b 100644 --- a/codeSamples.yaml +++ b/codeSamples.yaml @@ -122,4 +122,4 @@ actions: "x-codeSamples": - "lang": "python" "label": "partition" - "source": "from unstructured_client import UnstructuredClient\n\n\nwith UnstructuredClient(\n server_url=\"https://api.example.com\",\n) as uc_client:\n\n res = uc_client.general.partition(request={\n \"partition_parameters\": {\n \"files\": {\n \"file_name\": \"example.file\",\n \"content\": open(\"example.file\", \"rb\"),\n },\n \"split_pdf_page_range\": [\n 1,\n 10,\n ],\n },\n })\n\n assert res.elements is not None\n\n # Handle response\n print(res.elements)" + "source": "from unstructured_client import UnstructuredClient\nfrom unstructured_client.models import shared\n\n\nwith UnstructuredClient(\n server_url=\"https://api.example.com\",\n) as uc_client:\n\n res = uc_client.general.partition(request={\n \"partition_parameters\": {\n \"files\": {\n \"file_name\": \"example.file\",\n \"content\": open(\"example.file\", \"rb\"),\n },\n \"vlm_model_provider\": shared.PartitionParametersStrategy.OPENAI,\n \"vlm_model\": shared.PartitionParametersSchemasStrategy.GPT_4O,\n \"split_pdf_page_range\": [\n 1,\n 10,\n ],\n },\n })\n\n assert res.elements is not None\n\n # Handle response\n print(res.elements)" diff --git a/overlay_client.yaml b/overlay_client.yaml index d075c70b..a595bd68 100644 --- a/overlay_client.yaml +++ b/overlay_client.yaml @@ -3,6 +3,12 @@ info: title: Overlay openapi.json to add client-specific features version: 0.0.0 actions: + - target: $ + update: + servers: + - url: "https://platform.unstructuredapp.io/" + description: "Unstructured Platform API" + x-speakeasy-server-id: "platform-api" - target: $["components"]["schemas"]["partition_parameters"]["properties"] update: "split_pdf_page": diff --git a/src/unstructured_client/_hooks/custom/clean_server_url_hook.py b/src/unstructured_client/_hooks/custom/clean_server_url_hook.py index 13906bd3..3d0e0438 100644 --- a/src/unstructured_client/_hooks/custom/clean_server_url_hook.py +++ b/src/unstructured_client/_hooks/custom/clean_server_url_hook.py @@ -44,6 +44,12 @@ def choose_server_url(endpoint_url: str | None, client_url: str, default_endpoin Default endpoint URL as defined in the spec """ + # If the client doesn't get a server_url, it sets a default of platform + # This is not always the correct default - we need to make sure default_endpoint_url is used + # So, only use the client url if it has been set to something else + if client_url == "https://platform.unstructuredapp.io": + client_url = "" + url = endpoint_url if endpoint_url is not None else (client_url or default_endpoint_url) return clean_server_url(url) diff --git a/src/unstructured_client/sdk.py b/src/unstructured_client/sdk.py index e21b56e2..70af1973 100644 --- a/src/unstructured_client/sdk.py +++ b/src/unstructured_client/sdk.py @@ -31,6 +31,7 @@ def __init__( api_key_auth: Optional[ Union[Optional[str], Callable[[], Optional[str]]] ] = None, + server: Optional[str] = None, server_url: Optional[str] = None, url_params: Optional[Dict[str, str]] = None, client: Optional[HttpClient] = None, @@ -42,6 +43,7 @@ def __init__( r"""Instantiates the SDK configuring it with the provided parameters. :param api_key_auth: The api_key_auth required for authentication + :param server: The server by name to use for all methods :param server_url: The server URL to use for all methods :param url_params: Parameters to optionally template the server URL with :param client: The HTTP client to use for all synchronous methods @@ -84,6 +86,7 @@ def __init__( async_client=async_client, security=security, server_url=server_url, + server=server, retry_config=retry_config, timeout_ms=timeout_ms, debug_logger=debug_logger, diff --git a/src/unstructured_client/sdkconfiguration.py b/src/unstructured_client/sdkconfiguration.py index 5850fb5d..9451aab1 100644 --- a/src/unstructured_client/sdkconfiguration.py +++ b/src/unstructured_client/sdkconfiguration.py @@ -16,6 +16,14 @@ from unstructured_client.types import OptionalNullable, UNSET +SERVER_PLATFORM_API = "platform-api" +r"""Unstructured Platform API""" +SERVERS = { + SERVER_PLATFORM_API: "https://platform.unstructuredapp.io/", +} +"""Contains the list of servers available to the SDK""" + + @dataclass class SDKConfiguration: client: HttpClient @@ -23,6 +31,7 @@ class SDKConfiguration: debug_logger: Logger security: Optional[Union[shared.Security, Callable[[], shared.Security]]] = None server_url: Optional[str] = "" + server: Optional[str] = "" language: str = "python" openapi_doc_version: str = __openapi_doc_version__ sdk_version: str = __version__ @@ -35,10 +44,15 @@ def __post_init__(self): self._hooks = SDKHooks() def get_server_details(self) -> Tuple[str, Dict[str, str]]: - if self.server_url is None: - return "", {} + if self.server_url is not None and self.server_url: + return remove_suffix(self.server_url, "/"), {} + if not self.server: + self.server = SERVER_PLATFORM_API + + if self.server not in SERVERS: + raise ValueError(f'Invalid server "{self.server}"') - return remove_suffix(self.server_url, "/"), {} + return SERVERS[self.server], {} def get_hooks(self) -> SDKHooks: return self._hooks