Skip to content

chore: 🐝 Update SDK - Generate #236

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

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
17 changes: 8 additions & 9 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
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
sources:
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:
Expand Down
6 changes: 0 additions & 6 deletions _test_unstructured_client/unit/test_custom_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down
2 changes: 1 addition & 1 deletion codeSamples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
6 changes: 6 additions & 0 deletions overlay_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/unstructured_client/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 17 additions & 3 deletions src/unstructured_client/sdkconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@
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
async_client: AsyncHttpClient
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__
Expand All @@ -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