From 79c39f31fdcdabda8548cf48d82a77b6bb677a41 Mon Sep 17 00:00:00 2001 From: speakeasybot Date: Mon, 3 Mar 2025 00:11:34 +0000 Subject: [PATCH 1/5] ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.508.1 --- .speakeasy/gen.lock | 16 ++++----- .speakeasy/workflow.lock | 18 +++++----- README.md | 39 ++++++++++++++++----- RELEASES.md | 11 ++++++ USAGE.md | 10 ++++-- codeSamples.yaml | 2 +- docs/sdks/destinations/README.md | 25 ++++++++++--- docs/sdks/general/README.md | 5 ++- docs/sdks/jobs/README.md | 15 ++++++-- docs/sdks/sources/README.md | 25 ++++++++++--- docs/sdks/workflows/README.md | 30 ++++++++++++---- gen.yaml | 5 ++- pyproject.toml | 2 +- src/unstructured_client/_version.py | 6 ++-- src/unstructured_client/basesdk.py | 8 +++++ src/unstructured_client/httpclient.py | 6 ++-- src/unstructured_client/sdk.py | 32 +++++++++++------ src/unstructured_client/sdkconfiguration.py | 11 +++--- src/unstructured_client/utils/__init__.py | 2 ++ src/unstructured_client/utils/values.py | 5 ++- 20 files changed, 198 insertions(+), 75 deletions(-) diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 7905f94a..d8e362ac 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 8b5fa338-9106-4734-abf0-e30d67044a90 management: - docChecksum: 83f88cfa4bd77e1d3065b11a97119361 + docChecksum: 05b52a7105c586797340defcb58dc573 docVersion: 1.0.78 - speakeasyVersion: 1.490.0 - generationVersion: 2.512.0 - releaseVersion: 0.30.6 - configChecksum: c946e26d3a3b2fe2756ff169416b448c + speakeasyVersion: 1.508.1 + generationVersion: 2.536.0 + releaseVersion: 0.31.0 + configChecksum: faf5191e78f1597b78cd7600af4f1d96 repoURL: https://github.com/Unstructured-IO/unstructured-python-client.git repoSubDirectory: . installationURL: https://github.com/Unstructured-IO/unstructured-python-client.git @@ -16,7 +16,7 @@ features: acceptHeaders: 3.0.0 additionalDependencies: 1.0.0 constsAndDefaults: 1.0.5 - core: 5.11.0 + core: 5.12.1 defaultEnabledRetries: 0.2.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.3.2 @@ -27,11 +27,11 @@ features: methodServerURLs: 3.1.1 multipartFileContentType: 1.0.0 nameOverrides: 3.0.1 - nullables: 1.0.0 + nullables: 1.0.1 openEnums: 1.0.0 responseFormat: 1.0.1 retries: 3.0.2 - sdkHooks: 1.0.0 + sdkHooks: 1.0.1 serverIDs: 3.0.0 unions: 3.0.4 uploadStreams: 1.0.0 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index b0d3c49b..88d148e8 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,21 +1,21 @@ -speakeasyVersion: 1.505.0 +speakeasyVersion: 1.508.1 sources: my-source: sourceNamespace: my-source - sourceRevisionDigest: sha256:8cba0cf748e247efccefbb5d1839dbeb6e2e3210bb2c90f7b75b9034c22ae24a - sourceBlobDigest: sha256:69fef8ed681f1d68013e71f67927821d64fc1045d3956ace3775fe62ed76b8bb + sourceRevisionDigest: sha256:807be0a9dea419a66c54f7b073b96fef228c9991996eb7faab57915d96d14298 + sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817 tags: - latest - - speakeasy-sdk-regen-1740605410 - - 1.0.68 + - speakeasy-sdk-regen-1740701396 + - 1.0.78 targets: unstructured-python: source: my-source sourceNamespace: my-source - sourceRevisionDigest: sha256:8cba0cf748e247efccefbb5d1839dbeb6e2e3210bb2c90f7b75b9034c22ae24a - sourceBlobDigest: sha256:69fef8ed681f1d68013e71f67927821d64fc1045d3956ace3775fe62ed76b8bb + sourceRevisionDigest: sha256:807be0a9dea419a66c54f7b073b96fef228c9991996eb7faab57915d96d14298 + sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817 codeSamplesNamespace: my-source-code-samples - codeSamplesRevisionDigest: sha256:d7a20fe1c8d687f377099cdb412c6d0dd733dd982ec4662052df0894da211da2 + codeSamplesRevisionDigest: sha256:b3ab6f3bec3f43fd73f807f9d389aab450876e5d631ad4b424907a3a3cfd8bde workflow: workflowVersion: 1.0.0 speakeasyVersion: latest @@ -23,7 +23,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/README.md b/README.md index 8517c7d1..d189c3fc 100755 --- a/README.md +++ b/README.md @@ -113,7 +113,10 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared from unstructured_client.utils import BackoffStrategy, RetryConfig -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -141,7 +144,9 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared from unstructured_client.utils import BackoffStrategy, RetryConfig + with UnstructuredClient( + server_url="https://api.example.com", retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False), ) as uc_client: @@ -193,7 +198,10 @@ When custom error responses are specified for an operation, the SDK may also rai from unstructured_client import UnstructuredClient from unstructured_client.models import errors, shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = None try: @@ -325,7 +333,10 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u from unstructured_client import UnstructuredClient from unstructured_client.models import shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -355,7 +366,10 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared async def main(): - async with UnstructuredClient() as uc_client: + + async with UnstructuredClient( + server_url="https://api.example.com", + ) as uc_client: res = await uc_client.destinations.create_destination_async(request={ "create_destination_connector": { @@ -451,7 +465,10 @@ Certain SDK methods accept file objects as part of a request body or multi-part from unstructured_client import UnstructuredClient from unstructured_client.models import shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.general.partition(request={ "partition_parameters": { @@ -486,13 +503,19 @@ The `UnstructuredClient` class implements the context manager protocol and regis ```python from unstructured_client import UnstructuredClient def main(): - with UnstructuredClient() as uc_client: + + with UnstructuredClient( + server_url="https://api.example.com", + ) as uc_client: # Rest of application here... # Or when using async: async def amain(): - async with UnstructuredClient() as uc_client: + + async with UnstructuredClient( + server_url="https://api.example.com", + ) as uc_client: # Rest of application here... ``` @@ -508,7 +531,7 @@ from unstructured_client import UnstructuredClient import logging logging.basicConfig(level=logging.DEBUG) -s = UnstructuredClient(debug_logger=logging.getLogger("unstructured_client")) +s = UnstructuredClient(server_url="https://example.com", debug_logger=logging.getLogger("unstructured_client")) ``` diff --git a/RELEASES.md b/RELEASES.md index 7a7a0c0e..04577fb8 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -835,3 +835,14 @@ Based on: - [python v0.30.6] . ### Releases - [PyPI v0.30.6] https://pypi.org/project/unstructured-client/0.30.6 - . + + +## 2025-03-03 00:10:16 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.508.1 (2.536.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v0.31.0] . +### Releases +- [PyPI v0.31.0] https://pypi.org/project/unstructured-client/0.31.0 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index 808460d6..4151cac7 100644 --- a/USAGE.md +++ b/USAGE.md @@ -4,7 +4,10 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -34,7 +37,10 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared async def main(): - async with UnstructuredClient() as uc_client: + + async with UnstructuredClient( + server_url="https://api.example.com", + ) as uc_client: res = await uc_client.destinations.create_destination_async(request={ "create_destination_connector": { 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/docs/sdks/destinations/README.md b/docs/sdks/destinations/README.md index bbaacac1..024fe0d0 100644 --- a/docs/sdks/destinations/README.md +++ b/docs/sdks/destinations/README.md @@ -21,7 +21,10 @@ Create a new destination connector using the provided configuration and name. from unstructured_client import UnstructuredClient from unstructured_client.models import shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -70,7 +73,10 @@ Delete a specific destination connector by its ID. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.delete_destination(request={ "destination_id": "10a88d76-65fb-4c88-8488-9e7d272c6373", @@ -111,7 +117,10 @@ Retrieve detailed information for a specific destination connector by its ID. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.get_destination(request={ "destination_id": "41ba03fb-faa3-4e9e-8cfb-27f133c4198a", @@ -152,7 +161,10 @@ Retrieve a list of available destination connectors. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.list_destinations(request={}) @@ -191,7 +203,10 @@ Update the configuration of an existing destination connector. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.destinations.update_destination(request={ "update_destination_connector": { diff --git a/docs/sdks/general/README.md b/docs/sdks/general/README.md index d23f3888..b8effcfd 100644 --- a/docs/sdks/general/README.md +++ b/docs/sdks/general/README.md @@ -17,7 +17,10 @@ Description from unstructured_client import UnstructuredClient from unstructured_client.models import shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.general.partition(request={ "partition_parameters": { diff --git a/docs/sdks/jobs/README.md b/docs/sdks/jobs/README.md index b92d2baa..ad61e13f 100644 --- a/docs/sdks/jobs/README.md +++ b/docs/sdks/jobs/README.md @@ -18,7 +18,10 @@ Cancel the specified job. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.jobs.cancel_job(request={ "job_id": "ec29bf67-0f30-4793-b5ee-8fc0da196032", @@ -59,7 +62,10 @@ Retrieve detailed information for a specific job by its ID. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.jobs.get_job(request={ "job_id": "6bb4cb72-a072-4398-9de3-194e59352a3c", @@ -100,7 +106,10 @@ Retrieve a list of jobs with optional filtering by workflow ID or job status. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.jobs.list_jobs(request={}) diff --git a/docs/sdks/sources/README.md b/docs/sdks/sources/README.md index 49b165c8..1be3a698 100644 --- a/docs/sdks/sources/README.md +++ b/docs/sdks/sources/README.md @@ -21,7 +21,10 @@ Create a new source connector using the provided configuration and name. from unstructured_client import UnstructuredClient from unstructured_client.models import shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.sources.create_source(request={ "create_source_connector": { @@ -75,7 +78,10 @@ Delete a specific source connector identified by its ID. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.sources.delete_source(request={ "source_id": "8a24d7ae-5524-45e9-83f9-b0adba5303d4", @@ -116,7 +122,10 @@ Retrieve detailed information for a specific source connector by its ID. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.sources.get_source(request={ "source_id": "e02d8147-b614-4e4c-9c6d-0cd9c4492ea0", @@ -157,7 +166,10 @@ Retrieve a list of available source connectors. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.sources.list_sources(request={}) @@ -196,7 +208,10 @@ Update the configuration of an existing source connector. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.sources.update_source(request={ "update_source_connector": { diff --git a/docs/sdks/workflows/README.md b/docs/sdks/workflows/README.md index a420809a..f21326ef 100644 --- a/docs/sdks/workflows/README.md +++ b/docs/sdks/workflows/README.md @@ -22,7 +22,10 @@ Create a new workflow, either custom or auto, and configure its settings. from unstructured_client import UnstructuredClient from unstructured_client.models import shared -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.workflows.create_workflow(request={ "create_workflow": { @@ -69,7 +72,10 @@ Delete a workflow by its ID. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.workflows.delete_workflow(request={ "workflow_id": "26c0bd77-269e-4239-86b8-71541359440c", @@ -110,7 +116,10 @@ Retrieve detailed information for a specific workflow by its ID. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.workflows.get_workflow(request={ "workflow_id": "270d9bb5-13f1-4e4d-bb84-4bcc30c93967", @@ -151,7 +160,10 @@ Retrieve a list of workflows, optionally filtered by source, destination, or sta ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.workflows.list_workflows(request={}) @@ -190,7 +202,10 @@ Run a workflow by triggering a new job if none is currently active. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.workflows.run_workflow(request={ "workflow_id": "6b67be6d-98e9-440c-88fd-721e5d2d0036", @@ -231,7 +246,10 @@ Update an existing workflow's name, connectors, schedule, or workflow type. ```python from unstructured_client import UnstructuredClient -with UnstructuredClient() as uc_client: + +with UnstructuredClient( + server_url="https://api.example.com", +) as uc_client: res = uc_client.workflows.update_workflow(request={ "update_workflow": {}, diff --git a/gen.yaml b/gen.yaml index 0d5851fd..0063214f 100644 --- a/gen.yaml +++ b/gen.yaml @@ -4,16 +4,15 @@ generation: usageSnippets: optionalPropertyRendering: withExample fixes: - nameResolutionDec2023: false + nameResolutionFeb2025: false parameterOrderingFeb2024: false requestResponseComponentNamesFeb2024: false securityFeb2025: false - nameResolutionFeb2025: false auth: oAuth2ClientCredentialsEnabled: false oAuth2PasswordEnabled: false python: - version: 0.30.6 + version: 0.31.0 additionalDependencies: dev: deepdiff: '>=6.0' diff --git a/pyproject.toml b/pyproject.toml index c7e7bb9c..f098ea67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "unstructured-client" -version = "0.30.6" +version = "0.31.0" description = "Python Client SDK for Unstructured API" authors = [{ name = "Unstructured" },] readme = "README-PYPI.md" diff --git a/src/unstructured_client/_version.py b/src/unstructured_client/_version.py index a1c80daf..3e535261 100644 --- a/src/unstructured_client/_version.py +++ b/src/unstructured_client/_version.py @@ -3,10 +3,10 @@ import importlib.metadata __title__: str = "unstructured-client" -__version__: str = "0.30.6" +__version__: str = "0.31.0" __openapi_doc_version__: str = "1.0.78" -__gen_version__: str = "2.512.0" -__user_agent__: str = "speakeasy-sdk/python 0.30.6 2.512.0 1.0.78 unstructured-client" +__gen_version__: str = "2.536.0" +__user_agent__: str = "speakeasy-sdk/python 0.31.0 2.536.0 1.0.78 unstructured-client" try: if __package__ is not None: diff --git a/src/unstructured_client/basesdk.py b/src/unstructured_client/basesdk.py index 7dbda808..56998813 100644 --- a/src/unstructured_client/basesdk.py +++ b/src/unstructured_client/basesdk.py @@ -236,6 +236,10 @@ def do(): req.headers, get_body_content(req), ) + + if client is None: + raise ValueError("client is required") + http_res = client.send(req, stream=stream) except Exception as e: _, e = self.sdk_configuration.get_hooks().after_error( @@ -308,6 +312,10 @@ async def do(): req.headers, get_body_content(req), ) + + if client is None: + raise ValueError("client is required") + http_res = await client.send(req, stream=stream) except Exception as e: _, e = self.sdk_configuration.get_hooks().after_error( diff --git a/src/unstructured_client/httpclient.py b/src/unstructured_client/httpclient.py index 9dc43cb0..1e426352 100644 --- a/src/unstructured_client/httpclient.py +++ b/src/unstructured_client/httpclient.py @@ -94,7 +94,9 @@ class ClientOwner(Protocol): def close_clients( owner: ClientOwner, sync_client: Union[HttpClient, None], + sync_client_supplied: bool, async_client: Union[AsyncHttpClient, None], + async_client_supplied: bool, ) -> None: """ A finalizer function that is meant to be used with weakref.finalize to close @@ -107,13 +109,13 @@ def close_clients( owner.client = None owner.async_client = None - if sync_client is not None: + if sync_client is not None and not sync_client_supplied: try: sync_client.close() except Exception: pass - if async_client is not None: + if async_client is not None and not async_client_supplied: is_async = False try: asyncio.get_running_loop() diff --git a/src/unstructured_client/sdk.py b/src/unstructured_client/sdk.py index e21b56e2..4dd607d5 100644 --- a/src/unstructured_client/sdk.py +++ b/src/unstructured_client/sdk.py @@ -6,8 +6,7 @@ from .utils.logger import Logger, get_default_logger from .utils.retries import RetryConfig import httpx -from typing import Any, Callable, Dict, Optional, Union, cast -from unstructured_client import utils +from typing import Any, Callable, Optional, Union, cast from unstructured_client._hooks import SDKHooks from unstructured_client.destinations import Destinations from unstructured_client.general import General @@ -28,11 +27,10 @@ class UnstructuredClient(BaseSDK): def __init__( self, + server_url: str, api_key_auth: Optional[ Union[Optional[str], Callable[[], Optional[str]]] ] = None, - server_url: Optional[str] = None, - url_params: Optional[Dict[str, str]] = None, client: Optional[HttpClient] = None, async_client: Optional[AsyncHttpClient] = None, retry_config: OptionalNullable[RetryConfig] = UNSET, @@ -49,15 +47,19 @@ def __init__( :param retry_config: The retry configuration to use for all supported methods :param timeout_ms: Optional request timeout applied to each operation in milliseconds """ + client_supplied = True if client is None: client = httpx.Client() + client_supplied = False assert issubclass( type(client), HttpClient ), "The provided client must implement the HttpClient protocol." + async_client_supplied = True if async_client is None: async_client = httpx.AsyncClient() + async_client_supplied = False if debug_logger is None: debug_logger = get_default_logger() @@ -73,15 +75,13 @@ def __init__( else: security = shared.Security(api_key_auth=api_key_auth) - if server_url is not None: - if url_params is not None: - server_url = utils.template_url(server_url, url_params) - BaseSDK.__init__( self, SDKConfiguration( client=client, + client_supplied=client_supplied, async_client=async_client, + async_client_supplied=async_client_supplied, security=security, server_url=server_url, retry_config=retry_config, @@ -94,7 +94,7 @@ def __init__( current_server_url, *_ = self.sdk_configuration.get_server_details() server_url, self.sdk_configuration.client = hooks.sdk_init( - current_server_url, self.sdk_configuration.client + current_server_url, client ) if current_server_url != server_url: self.sdk_configuration.server_url = server_url @@ -107,7 +107,9 @@ def __init__( close_clients, cast(ClientOwner, self.sdk_configuration), self.sdk_configuration.client, + self.sdk_configuration.client_supplied, self.sdk_configuration.async_client, + self.sdk_configuration.async_client_supplied, ) self._init_sdks() @@ -126,9 +128,17 @@ async def __aenter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): - if self.sdk_configuration.client is not None: + if ( + self.sdk_configuration.client is not None + and not self.sdk_configuration.client_supplied + ): self.sdk_configuration.client.close() + self.sdk_configuration.client = None async def __aexit__(self, exc_type, exc_val, exc_tb): - if self.sdk_configuration.async_client is not None: + if ( + self.sdk_configuration.async_client is not None + and not self.sdk_configuration.async_client_supplied + ): await self.sdk_configuration.async_client.aclose() + self.sdk_configuration.async_client = None diff --git a/src/unstructured_client/sdkconfiguration.py b/src/unstructured_client/sdkconfiguration.py index 5850fb5d..42e290a7 100644 --- a/src/unstructured_client/sdkconfiguration.py +++ b/src/unstructured_client/sdkconfiguration.py @@ -18,11 +18,13 @@ @dataclass class SDKConfiguration: - client: HttpClient - async_client: AsyncHttpClient + client: Union[HttpClient, None] + client_supplied: bool + async_client: Union[AsyncHttpClient, None] + async_client_supplied: bool debug_logger: Logger + server_url: str security: Optional[Union[shared.Security, Callable[[], shared.Security]]] = None - server_url: Optional[str] = "" language: str = "python" openapi_doc_version: str = __openapi_doc_version__ sdk_version: str = __version__ @@ -35,9 +37,6 @@ def __post_init__(self): self._hooks = SDKHooks() def get_server_details(self) -> Tuple[str, Dict[str, str]]: - if self.server_url is None: - return "", {} - return remove_suffix(self.server_url, "/"), {} def get_hooks(self) -> SDKHooks: diff --git a/src/unstructured_client/utils/__init__.py b/src/unstructured_client/utils/__init__.py index 26d51ae8..3cded8fe 100644 --- a/src/unstructured_client/utils/__init__.py +++ b/src/unstructured_client/utils/__init__.py @@ -42,6 +42,7 @@ match_content_type, match_status_codes, match_response, + cast_partial, ) from .logger import Logger, get_body_content, get_default_logger @@ -94,4 +95,5 @@ "validate_float", "validate_int", "validate_open_enum", + "cast_partial", ] diff --git a/src/unstructured_client/utils/values.py b/src/unstructured_client/utils/values.py index 2b4b6832..dae01a44 100644 --- a/src/unstructured_client/utils/values.py +++ b/src/unstructured_client/utils/values.py @@ -3,8 +3,9 @@ from datetime import datetime from enum import Enum from email.message import Message +from functools import partial import os -from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union, cast from httpx import Response from pydantic import BaseModel @@ -51,6 +52,8 @@ def match_status_codes(status_codes: List[str], status_code: int) -> bool: T = TypeVar("T") +def cast_partial(typ): + return partial(cast, typ) def get_global_from_env( value: Optional[T], env_key: str, type_cast: Callable[[str], T] From ea4e5e79a80259402498ed77a6478c7cad356507 Mon Sep 17 00:00:00 2001 From: Austin Walker Date: Mon, 3 Mar 2025 11:57:49 -0500 Subject: [PATCH 2/5] Regenerate with default server settings in spec --- .speakeasy/gen.lock | 17 ++++----- .speakeasy/workflow.lock | 7 ++-- README.md | 39 +++++---------------- RELEASES.md | 4 +-- USAGE.md | 10 ++---- docs/sdks/destinations/README.md | 25 +++---------- docs/sdks/general/README.md | 5 +-- docs/sdks/jobs/README.md | 15 ++------ docs/sdks/sources/README.md | 25 +++---------- docs/sdks/workflows/README.md | 30 ++++------------ gen.yaml | 5 +-- overlay_client.yaml | 6 ++++ pyproject.toml | 2 +- src/unstructured_client/_version.py | 6 ++-- src/unstructured_client/basesdk.py | 8 ----- src/unstructured_client/httpclient.py | 6 ++-- src/unstructured_client/sdk.py | 35 ++++++++---------- src/unstructured_client/sdkconfiguration.py | 27 ++++++++++---- src/unstructured_client/utils/__init__.py | 2 -- src/unstructured_client/utils/values.py | 5 +-- 20 files changed, 95 insertions(+), 184 deletions(-) diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index d8e362ac..0c14304a 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 8b5fa338-9106-4734-abf0-e30d67044a90 management: - docChecksum: 05b52a7105c586797340defcb58dc573 + docChecksum: de9f013dc09f5ad50eaa7dd5716106ca docVersion: 1.0.78 - speakeasyVersion: 1.508.1 - generationVersion: 2.536.0 - releaseVersion: 0.31.0 - configChecksum: faf5191e78f1597b78cd7600af4f1d96 + speakeasyVersion: 1.490.0 + generationVersion: 2.512.0 + releaseVersion: 0.30.7 + configChecksum: 46f8726e2bf10ce486127f02ec9801dd repoURL: https://github.com/Unstructured-IO/unstructured-python-client.git repoSubDirectory: . installationURL: https://github.com/Unstructured-IO/unstructured-python-client.git @@ -16,7 +16,7 @@ features: acceptHeaders: 3.0.0 additionalDependencies: 1.0.0 constsAndDefaults: 1.0.5 - core: 5.12.1 + core: 5.11.0 defaultEnabledRetries: 0.2.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.3.2 @@ -24,14 +24,15 @@ 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 - nullables: 1.0.1 + nullables: 1.0.0 openEnums: 1.0.0 responseFormat: 1.0.1 retries: 3.0.2 - sdkHooks: 1.0.1 + sdkHooks: 1.0.0 serverIDs: 3.0.0 unions: 3.0.4 uploadStreams: 1.0.0 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 88d148e8..053b17c9 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -2,20 +2,19 @@ speakeasyVersion: 1.508.1 sources: my-source: sourceNamespace: my-source - sourceRevisionDigest: sha256:807be0a9dea419a66c54f7b073b96fef228c9991996eb7faab57915d96d14298 + sourceRevisionDigest: sha256:7c3885b2b10e35c3ce714ade8cf040b7af2d30c631aa9469af14c647e4eebd4c sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817 tags: - latest - - speakeasy-sdk-regen-1740701396 - 1.0.78 targets: unstructured-python: source: my-source sourceNamespace: my-source - sourceRevisionDigest: sha256:807be0a9dea419a66c54f7b073b96fef228c9991996eb7faab57915d96d14298 + sourceRevisionDigest: sha256:7c3885b2b10e35c3ce714ade8cf040b7af2d30c631aa9469af14c647e4eebd4c sourceBlobDigest: sha256:49a96e011be598dc1667da0d814c547d9544305f503cb992018176bcf78f3817 codeSamplesNamespace: my-source-code-samples - codeSamplesRevisionDigest: sha256:b3ab6f3bec3f43fd73f807f9d389aab450876e5d631ad4b424907a3a3cfd8bde + codeSamplesRevisionDigest: sha256:5f12b0195d8ed16e87269dc286ef0b48ba59a6c95b2ad935f85ec95e417394ae workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/README.md b/README.md index d189c3fc..8517c7d1 100755 --- a/README.md +++ b/README.md @@ -113,10 +113,7 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared from unstructured_client.utils import BackoffStrategy, RetryConfig - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -144,9 +141,7 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared from unstructured_client.utils import BackoffStrategy, RetryConfig - with UnstructuredClient( - server_url="https://api.example.com", retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False), ) as uc_client: @@ -198,10 +193,7 @@ When custom error responses are specified for an operation, the SDK may also rai from unstructured_client import UnstructuredClient from unstructured_client.models import errors, shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = None try: @@ -333,10 +325,7 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u from unstructured_client import UnstructuredClient from unstructured_client.models import shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -366,10 +355,7 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared async def main(): - - async with UnstructuredClient( - server_url="https://api.example.com", - ) as uc_client: + async with UnstructuredClient() as uc_client: res = await uc_client.destinations.create_destination_async(request={ "create_destination_connector": { @@ -465,10 +451,7 @@ Certain SDK methods accept file objects as part of a request body or multi-part from unstructured_client import UnstructuredClient from unstructured_client.models import shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.general.partition(request={ "partition_parameters": { @@ -503,19 +486,13 @@ The `UnstructuredClient` class implements the context manager protocol and regis ```python from unstructured_client import UnstructuredClient def main(): - - with UnstructuredClient( - server_url="https://api.example.com", - ) as uc_client: + with UnstructuredClient() as uc_client: # Rest of application here... # Or when using async: async def amain(): - - async with UnstructuredClient( - server_url="https://api.example.com", - ) as uc_client: + async with UnstructuredClient() as uc_client: # Rest of application here... ``` @@ -531,7 +508,7 @@ from unstructured_client import UnstructuredClient import logging logging.basicConfig(level=logging.DEBUG) -s = UnstructuredClient(server_url="https://example.com", debug_logger=logging.getLogger("unstructured_client")) +s = UnstructuredClient(debug_logger=logging.getLogger("unstructured_client")) ``` diff --git a/RELEASES.md b/RELEASES.md index 04577fb8..c58cbdc1 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -843,6 +843,6 @@ Based on: - OpenAPI Doc - Speakeasy CLI 1.508.1 (2.536.0) https://github.com/speakeasy-api/speakeasy ### Generated -- [python v0.31.0] . +- [python v0.30.7] . ### Releases -- [PyPI v0.31.0] https://pypi.org/project/unstructured-client/0.31.0 - . \ No newline at end of file +- [PyPI v0.30.7] https://pypi.org/project/unstructured-client/0.30.7 - . diff --git a/USAGE.md b/USAGE.md index 4151cac7..808460d6 100644 --- a/USAGE.md +++ b/USAGE.md @@ -4,10 +4,7 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -37,10 +34,7 @@ from unstructured_client import UnstructuredClient from unstructured_client.models import shared async def main(): - - async with UnstructuredClient( - server_url="https://api.example.com", - ) as uc_client: + async with UnstructuredClient() as uc_client: res = await uc_client.destinations.create_destination_async(request={ "create_destination_connector": { diff --git a/docs/sdks/destinations/README.md b/docs/sdks/destinations/README.md index 024fe0d0..bbaacac1 100644 --- a/docs/sdks/destinations/README.md +++ b/docs/sdks/destinations/README.md @@ -21,10 +21,7 @@ Create a new destination connector using the provided configuration and name. from unstructured_client import UnstructuredClient from unstructured_client.models import shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.create_destination(request={ "create_destination_connector": { @@ -73,10 +70,7 @@ Delete a specific destination connector by its ID. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.delete_destination(request={ "destination_id": "10a88d76-65fb-4c88-8488-9e7d272c6373", @@ -117,10 +111,7 @@ Retrieve detailed information for a specific destination connector by its ID. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.get_destination(request={ "destination_id": "41ba03fb-faa3-4e9e-8cfb-27f133c4198a", @@ -161,10 +152,7 @@ Retrieve a list of available destination connectors. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.list_destinations(request={}) @@ -203,10 +191,7 @@ Update the configuration of an existing destination connector. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.destinations.update_destination(request={ "update_destination_connector": { diff --git a/docs/sdks/general/README.md b/docs/sdks/general/README.md index b8effcfd..d23f3888 100644 --- a/docs/sdks/general/README.md +++ b/docs/sdks/general/README.md @@ -17,10 +17,7 @@ Description from unstructured_client import UnstructuredClient from unstructured_client.models import shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.general.partition(request={ "partition_parameters": { diff --git a/docs/sdks/jobs/README.md b/docs/sdks/jobs/README.md index ad61e13f..b92d2baa 100644 --- a/docs/sdks/jobs/README.md +++ b/docs/sdks/jobs/README.md @@ -18,10 +18,7 @@ Cancel the specified job. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.jobs.cancel_job(request={ "job_id": "ec29bf67-0f30-4793-b5ee-8fc0da196032", @@ -62,10 +59,7 @@ Retrieve detailed information for a specific job by its ID. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.jobs.get_job(request={ "job_id": "6bb4cb72-a072-4398-9de3-194e59352a3c", @@ -106,10 +100,7 @@ Retrieve a list of jobs with optional filtering by workflow ID or job status. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.jobs.list_jobs(request={}) diff --git a/docs/sdks/sources/README.md b/docs/sdks/sources/README.md index 1be3a698..49b165c8 100644 --- a/docs/sdks/sources/README.md +++ b/docs/sdks/sources/README.md @@ -21,10 +21,7 @@ Create a new source connector using the provided configuration and name. from unstructured_client import UnstructuredClient from unstructured_client.models import shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.sources.create_source(request={ "create_source_connector": { @@ -78,10 +75,7 @@ Delete a specific source connector identified by its ID. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.sources.delete_source(request={ "source_id": "8a24d7ae-5524-45e9-83f9-b0adba5303d4", @@ -122,10 +116,7 @@ Retrieve detailed information for a specific source connector by its ID. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.sources.get_source(request={ "source_id": "e02d8147-b614-4e4c-9c6d-0cd9c4492ea0", @@ -166,10 +157,7 @@ Retrieve a list of available source connectors. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.sources.list_sources(request={}) @@ -208,10 +196,7 @@ Update the configuration of an existing source connector. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.sources.update_source(request={ "update_source_connector": { diff --git a/docs/sdks/workflows/README.md b/docs/sdks/workflows/README.md index f21326ef..a420809a 100644 --- a/docs/sdks/workflows/README.md +++ b/docs/sdks/workflows/README.md @@ -22,10 +22,7 @@ Create a new workflow, either custom or auto, and configure its settings. from unstructured_client import UnstructuredClient from unstructured_client.models import shared - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.workflows.create_workflow(request={ "create_workflow": { @@ -72,10 +69,7 @@ Delete a workflow by its ID. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.workflows.delete_workflow(request={ "workflow_id": "26c0bd77-269e-4239-86b8-71541359440c", @@ -116,10 +110,7 @@ Retrieve detailed information for a specific workflow by its ID. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.workflows.get_workflow(request={ "workflow_id": "270d9bb5-13f1-4e4d-bb84-4bcc30c93967", @@ -160,10 +151,7 @@ Retrieve a list of workflows, optionally filtered by source, destination, or sta ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.workflows.list_workflows(request={}) @@ -202,10 +190,7 @@ Run a workflow by triggering a new job if none is currently active. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.workflows.run_workflow(request={ "workflow_id": "6b67be6d-98e9-440c-88fd-721e5d2d0036", @@ -246,10 +231,7 @@ Update an existing workflow's name, connectors, schedule, or workflow type. ```python from unstructured_client import UnstructuredClient - -with UnstructuredClient( - server_url="https://api.example.com", -) as uc_client: +with UnstructuredClient() as uc_client: res = uc_client.workflows.update_workflow(request={ "update_workflow": {}, diff --git a/gen.yaml b/gen.yaml index 0063214f..b0793c46 100644 --- a/gen.yaml +++ b/gen.yaml @@ -4,15 +4,16 @@ generation: usageSnippets: optionalPropertyRendering: withExample fixes: - nameResolutionFeb2025: false + nameResolutionDec2023: false parameterOrderingFeb2024: false requestResponseComponentNamesFeb2024: false securityFeb2025: false + nameResolutionFeb2025: false auth: oAuth2ClientCredentialsEnabled: false oAuth2PasswordEnabled: false python: - version: 0.31.0 + version: 0.30.7 additionalDependencies: dev: deepdiff: '>=6.0' 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/pyproject.toml b/pyproject.toml index f098ea67..d8f0075e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "unstructured-client" -version = "0.31.0" +version = "0.30.7" description = "Python Client SDK for Unstructured API" authors = [{ name = "Unstructured" },] readme = "README-PYPI.md" diff --git a/src/unstructured_client/_version.py b/src/unstructured_client/_version.py index 3e535261..83cf82c9 100644 --- a/src/unstructured_client/_version.py +++ b/src/unstructured_client/_version.py @@ -3,10 +3,10 @@ import importlib.metadata __title__: str = "unstructured-client" -__version__: str = "0.31.0" +__version__: str = "0.30.7" __openapi_doc_version__: str = "1.0.78" -__gen_version__: str = "2.536.0" -__user_agent__: str = "speakeasy-sdk/python 0.31.0 2.536.0 1.0.78 unstructured-client" +__gen_version__: str = "2.512.0" +__user_agent__: str = "speakeasy-sdk/python 0.30.7 2.512.0 1.0.78 unstructured-client" try: if __package__ is not None: diff --git a/src/unstructured_client/basesdk.py b/src/unstructured_client/basesdk.py index 56998813..7dbda808 100644 --- a/src/unstructured_client/basesdk.py +++ b/src/unstructured_client/basesdk.py @@ -236,10 +236,6 @@ def do(): req.headers, get_body_content(req), ) - - if client is None: - raise ValueError("client is required") - http_res = client.send(req, stream=stream) except Exception as e: _, e = self.sdk_configuration.get_hooks().after_error( @@ -312,10 +308,6 @@ async def do(): req.headers, get_body_content(req), ) - - if client is None: - raise ValueError("client is required") - http_res = await client.send(req, stream=stream) except Exception as e: _, e = self.sdk_configuration.get_hooks().after_error( diff --git a/src/unstructured_client/httpclient.py b/src/unstructured_client/httpclient.py index 1e426352..9dc43cb0 100644 --- a/src/unstructured_client/httpclient.py +++ b/src/unstructured_client/httpclient.py @@ -94,9 +94,7 @@ class ClientOwner(Protocol): def close_clients( owner: ClientOwner, sync_client: Union[HttpClient, None], - sync_client_supplied: bool, async_client: Union[AsyncHttpClient, None], - async_client_supplied: bool, ) -> None: """ A finalizer function that is meant to be used with weakref.finalize to close @@ -109,13 +107,13 @@ def close_clients( owner.client = None owner.async_client = None - if sync_client is not None and not sync_client_supplied: + if sync_client is not None: try: sync_client.close() except Exception: pass - if async_client is not None and not async_client_supplied: + if async_client is not None: is_async = False try: asyncio.get_running_loop() diff --git a/src/unstructured_client/sdk.py b/src/unstructured_client/sdk.py index 4dd607d5..70af1973 100644 --- a/src/unstructured_client/sdk.py +++ b/src/unstructured_client/sdk.py @@ -6,7 +6,8 @@ from .utils.logger import Logger, get_default_logger from .utils.retries import RetryConfig import httpx -from typing import Any, Callable, Optional, Union, cast +from typing import Any, Callable, Dict, Optional, Union, cast +from unstructured_client import utils from unstructured_client._hooks import SDKHooks from unstructured_client.destinations import Destinations from unstructured_client.general import General @@ -27,10 +28,12 @@ class UnstructuredClient(BaseSDK): def __init__( self, - server_url: str, 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, async_client: Optional[AsyncHttpClient] = None, retry_config: OptionalNullable[RetryConfig] = UNSET, @@ -40,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 @@ -47,19 +51,15 @@ def __init__( :param retry_config: The retry configuration to use for all supported methods :param timeout_ms: Optional request timeout applied to each operation in milliseconds """ - client_supplied = True if client is None: client = httpx.Client() - client_supplied = False assert issubclass( type(client), HttpClient ), "The provided client must implement the HttpClient protocol." - async_client_supplied = True if async_client is None: async_client = httpx.AsyncClient() - async_client_supplied = False if debug_logger is None: debug_logger = get_default_logger() @@ -75,15 +75,18 @@ def __init__( else: security = shared.Security(api_key_auth=api_key_auth) + if server_url is not None: + if url_params is not None: + server_url = utils.template_url(server_url, url_params) + BaseSDK.__init__( self, SDKConfiguration( client=client, - client_supplied=client_supplied, async_client=async_client, - async_client_supplied=async_client_supplied, security=security, server_url=server_url, + server=server, retry_config=retry_config, timeout_ms=timeout_ms, debug_logger=debug_logger, @@ -94,7 +97,7 @@ def __init__( current_server_url, *_ = self.sdk_configuration.get_server_details() server_url, self.sdk_configuration.client = hooks.sdk_init( - current_server_url, client + current_server_url, self.sdk_configuration.client ) if current_server_url != server_url: self.sdk_configuration.server_url = server_url @@ -107,9 +110,7 @@ def __init__( close_clients, cast(ClientOwner, self.sdk_configuration), self.sdk_configuration.client, - self.sdk_configuration.client_supplied, self.sdk_configuration.async_client, - self.sdk_configuration.async_client_supplied, ) self._init_sdks() @@ -128,17 +129,9 @@ async def __aenter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): - if ( - self.sdk_configuration.client is not None - and not self.sdk_configuration.client_supplied - ): + if self.sdk_configuration.client is not None: self.sdk_configuration.client.close() - self.sdk_configuration.client = None async def __aexit__(self, exc_type, exc_val, exc_tb): - if ( - self.sdk_configuration.async_client is not None - and not self.sdk_configuration.async_client_supplied - ): + if self.sdk_configuration.async_client is not None: await self.sdk_configuration.async_client.aclose() - self.sdk_configuration.async_client = None diff --git a/src/unstructured_client/sdkconfiguration.py b/src/unstructured_client/sdkconfiguration.py index 42e290a7..9451aab1 100644 --- a/src/unstructured_client/sdkconfiguration.py +++ b/src/unstructured_client/sdkconfiguration.py @@ -16,15 +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: Union[HttpClient, None] - client_supplied: bool - async_client: Union[AsyncHttpClient, None] - async_client_supplied: bool + client: HttpClient + async_client: AsyncHttpClient debug_logger: Logger - server_url: str 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__ @@ -37,7 +44,15 @@ def __post_init__(self): self._hooks = SDKHooks() def get_server_details(self) -> Tuple[str, Dict[str, str]]: - return remove_suffix(self.server_url, "/"), {} + 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 SERVERS[self.server], {} def get_hooks(self) -> SDKHooks: return self._hooks diff --git a/src/unstructured_client/utils/__init__.py b/src/unstructured_client/utils/__init__.py index 3cded8fe..26d51ae8 100644 --- a/src/unstructured_client/utils/__init__.py +++ b/src/unstructured_client/utils/__init__.py @@ -42,7 +42,6 @@ match_content_type, match_status_codes, match_response, - cast_partial, ) from .logger import Logger, get_body_content, get_default_logger @@ -95,5 +94,4 @@ "validate_float", "validate_int", "validate_open_enum", - "cast_partial", ] diff --git a/src/unstructured_client/utils/values.py b/src/unstructured_client/utils/values.py index dae01a44..2b4b6832 100644 --- a/src/unstructured_client/utils/values.py +++ b/src/unstructured_client/utils/values.py @@ -3,9 +3,8 @@ from datetime import datetime from enum import Enum from email.message import Message -from functools import partial import os -from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union, cast +from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union from httpx import Response from pydantic import BaseModel @@ -52,8 +51,6 @@ def match_status_codes(status_codes: List[str], status_code: int) -> bool: T = TypeVar("T") -def cast_partial(typ): - return partial(cast, typ) def get_global_from_env( value: Optional[T], env_key: str, type_cast: Callable[[str], T] From eb2871ce46d4015d1acc731add631c809802e480 Mon Sep 17 00:00:00 2001 From: Austin Walker Date: Mon, 3 Mar 2025 11:58:03 -0500 Subject: [PATCH 3/5] Ensure that general.partition can still set a client level url --- .../_hooks/custom/clean_server_url_hook.py | 6 ++++++ 1 file changed, 6 insertions(+) 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) From 6297e13637127a6ac6191134d5d7ae0c28a207f9 Mon Sep 17 00:00:00 2001 From: Austin Walker Date: Mon, 3 Mar 2025 12:04:21 -0500 Subject: [PATCH 4/5] Remove server url unit test --- _test_unstructured_client/unit/test_custom_hooks.py | 6 ------ 1 file changed, 6 deletions(-) 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", [ From 144e5789954dcc67d2b46e356c4784e27ca8edb3 Mon Sep 17 00:00:00 2001 From: Austin Walker Date: Mon, 3 Mar 2025 12:09:24 -0500 Subject: [PATCH 5/5] Reset to 0.30.6 --- .speakeasy/gen.lock | 4 ++-- RELEASES.md | 11 ----------- gen.yaml | 2 +- pyproject.toml | 2 +- src/unstructured_client/_version.py | 4 ++-- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 0c14304a..2b826dce 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -5,8 +5,8 @@ management: docVersion: 1.0.78 speakeasyVersion: 1.490.0 generationVersion: 2.512.0 - releaseVersion: 0.30.7 - configChecksum: 46f8726e2bf10ce486127f02ec9801dd + releaseVersion: 0.30.6 + configChecksum: c946e26d3a3b2fe2756ff169416b448c repoURL: https://github.com/Unstructured-IO/unstructured-python-client.git repoSubDirectory: . installationURL: https://github.com/Unstructured-IO/unstructured-python-client.git diff --git a/RELEASES.md b/RELEASES.md index c58cbdc1..7a7a0c0e 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -835,14 +835,3 @@ Based on: - [python v0.30.6] . ### Releases - [PyPI v0.30.6] https://pypi.org/project/unstructured-client/0.30.6 - . - - -## 2025-03-03 00:10:16 -### Changes -Based on: -- OpenAPI Doc -- Speakeasy CLI 1.508.1 (2.536.0) https://github.com/speakeasy-api/speakeasy -### Generated -- [python v0.30.7] . -### Releases -- [PyPI v0.30.7] https://pypi.org/project/unstructured-client/0.30.7 - . diff --git a/gen.yaml b/gen.yaml index b0793c46..0d5851fd 100644 --- a/gen.yaml +++ b/gen.yaml @@ -13,7 +13,7 @@ generation: oAuth2ClientCredentialsEnabled: false oAuth2PasswordEnabled: false python: - version: 0.30.7 + version: 0.30.6 additionalDependencies: dev: deepdiff: '>=6.0' diff --git a/pyproject.toml b/pyproject.toml index d8f0075e..c7e7bb9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "unstructured-client" -version = "0.30.7" +version = "0.30.6" description = "Python Client SDK for Unstructured API" authors = [{ name = "Unstructured" },] readme = "README-PYPI.md" diff --git a/src/unstructured_client/_version.py b/src/unstructured_client/_version.py index 83cf82c9..a1c80daf 100644 --- a/src/unstructured_client/_version.py +++ b/src/unstructured_client/_version.py @@ -3,10 +3,10 @@ import importlib.metadata __title__: str = "unstructured-client" -__version__: str = "0.30.7" +__version__: str = "0.30.6" __openapi_doc_version__: str = "1.0.78" __gen_version__: str = "2.512.0" -__user_agent__: str = "speakeasy-sdk/python 0.30.7 2.512.0 1.0.78 unstructured-client" +__user_agent__: str = "speakeasy-sdk/python 0.30.6 2.512.0 1.0.78 unstructured-client" try: if __package__ is not None: