Skip to content

Commit 9c4bee5

Browse files
authored
Merge branch 'main' into austin/cleanup-warning-logs
2 parents 89dc9b7 + c469bb6 commit 9c4bee5

File tree

8 files changed

+43
-20
lines changed

8 files changed

+43
-20
lines changed

.speakeasy/gen.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
lockVersion: 2.0.0
22
id: 8b5fa338-9106-4734-abf0-e30d67044a90
33
management:
4-
docChecksum: 83f88cfa4bd77e1d3065b11a97119361
4+
docChecksum: de9f013dc09f5ad50eaa7dd5716106ca
55
docVersion: 1.0.78
66
speakeasyVersion: 1.490.0
77
generationVersion: 2.512.0
@@ -24,6 +24,7 @@ features:
2424
globalSecurity: 3.0.3
2525
globalSecurityCallbacks: 1.0.0
2626
globalSecurityFlattening: 1.0.0
27+
globalServerURLs: 3.1.0
2728
methodServerURLs: 3.1.1
2829
multipartFileContentType: 1.0.0
2930
nameOverrides: 3.0.1

.speakeasy/workflow.lock

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
speakeasyVersion: 1.505.0
1+
speakeasyVersion: 1.508.1
22
sources:
33
my-source:
44
sourceNamespace: my-source
5-
sourceRevisionDigest: sha256:8cba0cf748e247efccefbb5d1839dbeb6e2e3210bb2c90f7b75b9034c22ae24a
6-
sourceBlobDigest: sha256:69fef8ed681f1d68013e71f67927821d64fc1045d3956ace3775fe62ed76b8bb
5+
sourceRevisionDigest: sha256:7c3885b2b10e35c3ce714ade8cf040b7af2d30c631aa9469af14c647e4eebd4c
6+
sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817
77
tags:
88
- latest
9-
- speakeasy-sdk-regen-1740605410
10-
- 1.0.68
9+
- 1.0.78
1110
targets:
1211
unstructured-python:
1312
source: my-source
1413
sourceNamespace: my-source
15-
sourceRevisionDigest: sha256:8cba0cf748e247efccefbb5d1839dbeb6e2e3210bb2c90f7b75b9034c22ae24a
16-
sourceBlobDigest: sha256:69fef8ed681f1d68013e71f67927821d64fc1045d3956ace3775fe62ed76b8bb
14+
sourceRevisionDigest: sha256:7c3885b2b10e35c3ce714ade8cf040b7af2d30c631aa9469af14c647e4eebd4c
15+
sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817
1716
codeSamplesNamespace: my-source-code-samples
18-
codeSamplesRevisionDigest: sha256:d7a20fe1c8d687f377099cdb412c6d0dd733dd982ec4662052df0894da211da2
17+
codeSamplesRevisionDigest: sha256:5f12b0195d8ed16e87269dc286ef0b48ba59a6c95b2ad935f85ec95e417394ae
1918
workflow:
2019
workflowVersion: 1.0.0
2120
speakeasyVersion: latest
2221
sources:
2322
my-source:
2423
inputs:
2524
- location: https://platform.unstructuredapp.io/openapi.json
26-
- location: https://api.unstructured.io/general/openapi.json
25+
- location: https://api.unstructuredapp.io/general/openapi.json
2726
overlays:
2827
- location: ./overlay_client.yaml
2928
registry:

_test_unstructured_client/unit/test_custom_hooks.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ def test_unit_clean_server_url_fixes_malformed_localhost_url(server_url: str):
211211
assert client.general.sdk_configuration.server_url == "http://localhost:8000"
212212

213213

214-
215-
def test_unit_clean_server_url_returns_None_given_no_server_url():
216-
client = UnstructuredClient(api_key_auth=FAKE_KEY)
217-
assert client.general.sdk_configuration.server_url == None
218-
219-
220214
@pytest.mark.parametrize(
221215
"server_url",
222216
[

codeSamples.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ actions:
122122
"x-codeSamples":
123123
- "lang": "python"
124124
"label": "partition"
125-
"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)"
125+
"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)"

overlay_client.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ info:
33
title: Overlay openapi.json to add client-specific features
44
version: 0.0.0
55
actions:
6+
- target: $
7+
update:
8+
servers:
9+
- url: "https://platform.unstructuredapp.io/"
10+
description: "Unstructured Platform API"
11+
x-speakeasy-server-id: "platform-api"
612
- target: $["components"]["schemas"]["partition_parameters"]["properties"]
713
update:
814
"split_pdf_page":

src/unstructured_client/_hooks/custom/clean_server_url_hook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def choose_server_url(endpoint_url: str | None, client_url: str, default_endpoin
4444
Default endpoint URL as defined in the spec
4545
"""
4646

47+
# If the client doesn't get a server_url, it sets a default of platform
48+
# This is not always the correct default - we need to make sure default_endpoint_url is used
49+
# So, only use the client url if it has been set to something else
50+
if client_url == "https://platform.unstructuredapp.io":
51+
client_url = ""
52+
4753
url = endpoint_url if endpoint_url is not None else (client_url or default_endpoint_url)
4854
return clean_server_url(url)
4955

src/unstructured_client/sdk.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(
3131
api_key_auth: Optional[
3232
Union[Optional[str], Callable[[], Optional[str]]]
3333
] = None,
34+
server: Optional[str] = None,
3435
server_url: Optional[str] = None,
3536
url_params: Optional[Dict[str, str]] = None,
3637
client: Optional[HttpClient] = None,
@@ -42,6 +43,7 @@ def __init__(
4243
r"""Instantiates the SDK configuring it with the provided parameters.
4344
4445
:param api_key_auth: The api_key_auth required for authentication
46+
:param server: The server by name to use for all methods
4547
:param server_url: The server URL to use for all methods
4648
:param url_params: Parameters to optionally template the server URL with
4749
:param client: The HTTP client to use for all synchronous methods
@@ -84,6 +86,7 @@ def __init__(
8486
async_client=async_client,
8587
security=security,
8688
server_url=server_url,
89+
server=server,
8790
retry_config=retry_config,
8891
timeout_ms=timeout_ms,
8992
debug_logger=debug_logger,

src/unstructured_client/sdkconfiguration.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@
1616
from unstructured_client.types import OptionalNullable, UNSET
1717

1818

19+
SERVER_PLATFORM_API = "platform-api"
20+
r"""Unstructured Platform API"""
21+
SERVERS = {
22+
SERVER_PLATFORM_API: "https://platform.unstructuredapp.io/",
23+
}
24+
"""Contains the list of servers available to the SDK"""
25+
26+
1927
@dataclass
2028
class SDKConfiguration:
2129
client: HttpClient
2230
async_client: AsyncHttpClient
2331
debug_logger: Logger
2432
security: Optional[Union[shared.Security, Callable[[], shared.Security]]] = None
2533
server_url: Optional[str] = ""
34+
server: Optional[str] = ""
2635
language: str = "python"
2736
openapi_doc_version: str = __openapi_doc_version__
2837
sdk_version: str = __version__
@@ -35,10 +44,15 @@ def __post_init__(self):
3544
self._hooks = SDKHooks()
3645

3746
def get_server_details(self) -> Tuple[str, Dict[str, str]]:
38-
if self.server_url is None:
39-
return "", {}
47+
if self.server_url is not None and self.server_url:
48+
return remove_suffix(self.server_url, "/"), {}
49+
if not self.server:
50+
self.server = SERVER_PLATFORM_API
51+
52+
if self.server not in SERVERS:
53+
raise ValueError(f'Invalid server "{self.server}"')
4054

41-
return remove_suffix(self.server_url, "/"), {}
55+
return SERVERS[self.server], {}
4256

4357
def get_hooks(self) -> SDKHooks:
4458
return self._hooks

0 commit comments

Comments
 (0)