Skip to content

Commit 51e5e61

Browse files
yuming-longgithub-actions[bot]speakeasybot
authored
NEXUS-909 feat Enable custom server URLs in the workflow endpoints (#265)
## Summary * `server_url` logic in workflow endpoints is now the same as partition endpoint: user should be able to pass it from Client init to each endpoint and if no input we will just fallback to default based on endpoint operation * NOTE changes to developers: generate GHA will need manual changes * you need to change the automate speakeasy bot PR made generate GHA -> so that it won't revert the changes on `base_url` in each endpoint (see #266) * we could add those file under `.genignore` so that speakeasy bot ignore the ^^ changes -> but i don't like this way since we might still need to modify workflow API endpoint and speakeasy bot will ignore them if we do * [another trick](https://www.speakeasy.com/docs/customize/code/code-regions/overview) i found that could solve the issue -> we could pay speakeasy more... but still not very flexible * or we could also patch `_get_url` in `basesdk.py` but thats in deeper stack of code might be difficult to read the flow (and write tests) * all reasons ^^^^ include i decide to go with manual changes in generate GHA -> we need a developer to approve that auto PR anyway ## Test you got three ways of using the url ``` ## make sure the version of unstructured_client is the local one should be 0.34.0 import unstructured_client from unstructured_client.models import operations, shared from unstructured_client import UnstructuredClient # 1. init custom url when you create the Client (suggested way for in-VPC) uc_client = UnstructuredClient(server_url="http://localhost:8081/", api_key_auth="XXXX") create_workflow_data = { "name": "custom sdk workflow", "workflow_type": shared.WorkflowType.BASIC, } client_res = uc_client.workflows.create_workflow(request={ "create_workflow": create_workflow_data, }) # 2. pass url when you call the specific endpoint (probably nobody will use this one...) uc_client = UnstructuredClient(api_key_auth="XXX") create_workflow_data = { "name": "custom sdk workflow", "workflow_type": shared.WorkflowType.BASIC, } client_res = uc_client.workflows.create_workflow( request={"create_workflow": create_workflow_data,}, server_url="http://localhost:8081/", ) # 3. no passing any url, fallback to default uc_client = UnstructuredClient(api_key_auth="XXX) create_workflow_data = { "name": "custom sdk workflow", "workflow_type": shared.WorkflowType.BASIC, } client_res = uc_client.workflows.create_workflow( request={"create_workflow": create_workflow_data,}, ) ``` and responses would be (last one is default fallback) ``` INFO: HTTP Request: POST http://localhost:8081/api/v1/workflows/ "HTTP/1.1 200 OK" INFO: HTTP Request: POST http://localhost:8081/api/v1/workflows/ "HTTP/1.1 200 OK" INFO: HTTP Request: POST https://platform.unstructuredapp.io/api/v1/workflows/ "HTTP/1.1 200 OK" ``` --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: speakeasybot <[email protected]>
1 parent ddb8bff commit 51e5e61

20 files changed

+367
-629
lines changed

.genignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
# https://www.speakeasyapi.dev/docs/customize-sdks/monkey-patching
1+
# https://www.speakeasy.com/docs/customize/code/monkey-patching
22

33
# ignore human-written files and directories
4-
src/unstructured_client/_unstructured
54
_jupyter
65
_sample_docs
76
_test_unstructured_client
87

98
# ignore Makefile
109
Makefile
1110

12-
# Ignore the general.partition code until we can fix the base_url issue
13-
src/unstructured_client/general.py

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.speakeasy/temp/
12
.speakeasy/reports
23
.venv/
34
README-PYPI.md
@@ -11,10 +12,8 @@ __pycache__/
1112
# human-added igore files
1213
.ipynb_checkpoints/
1314
.idea/
14-
1515
.local
1616
*.ipynb
17-
1817
openapi.json
1918
openapi_client.json
2019
openapi_serverless.json

.speakeasy/gen.lock

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ id: 8b5fa338-9106-4734-abf0-e30d67044a90
33
management:
44
docChecksum: 6433f28e5b70c3c0d7754fc7a88db327
55
docVersion: 1.1.7
6-
speakeasyVersion: 1.535.1
7-
generationVersion: 2.585.2
8-
releaseVersion: 0.33.1
9-
configChecksum: 8b5e7fbd95d040ba09964f3c97c3156a
6+
speakeasyVersion: 1.537.0
7+
generationVersion: 2.588.0
8+
releaseVersion: 0.34.0
9+
configChecksum: 0ba814fcbe0d0489903de407d36313af
1010
repoURL: https://github.com/Unstructured-IO/unstructured-python-client.git
1111
repoSubDirectory: .
1212
installationURL: https://github.com/Unstructured-IO/unstructured-python-client.git
@@ -16,7 +16,7 @@ features:
1616
acceptHeaders: 3.0.0
1717
additionalDependencies: 1.0.0
1818
constsAndDefaults: 1.0.5
19-
core: 5.14.0
19+
core: 5.15.0
2020
defaultEnabledRetries: 0.2.0
2121
enumUnions: 0.1.0
2222
envVarSecurityUsage: 0.3.2
@@ -228,6 +228,7 @@ generatedFiles:
228228
- src/unstructured_client/_version.py
229229
- src/unstructured_client/basesdk.py
230230
- src/unstructured_client/destinations.py
231+
- src/unstructured_client/general.py
231232
- src/unstructured_client/httpclient.py
232233
- src/unstructured_client/jobs.py
233234
- src/unstructured_client/models/__init__.py
@@ -369,6 +370,7 @@ generatedFiles:
369370
- src/unstructured_client/types/basemodel.py
370371
- src/unstructured_client/utils/__init__.py
371372
- src/unstructured_client/utils/annotations.py
373+
- src/unstructured_client/utils/datetimes.py
372374
- src/unstructured_client/utils/enums.py
373375
- src/unstructured_client/utils/eventstreaming.py
374376
- src/unstructured_client/utils/forms.py
@@ -668,7 +670,7 @@ examples:
668670
"200":
669671
application/json: {"created_at": "2025-03-13T23:31:02.383Z", "id": "c3274f55-9861-4e4e-8526-4273aa4d2772", "status": "FAILURE"}
670672
"422":
671-
application/json: {"detail": [{"loc": ["<value>"], "msg": "<value>", "type": "<value>"}, {"loc": [], "msg": "<value>", "type": "<value>"}, {"loc": [], "msg": "<value>", "type": "<value>"}]}
673+
application/json: {"detail": "<value>"}
672674
create_connection_check_sources:
673675
speakeasy-default-create-connection-check-sources:
674676
parameters:
@@ -679,7 +681,7 @@ examples:
679681
"202":
680682
application/json: {"created_at": "2023-03-12T05:54:05.025Z", "id": "b5793adb-057f-470c-ae7e-309d786a99eb", "status": "SUCCESS"}
681683
"422":
682-
application/json: {"detail": []}
684+
application/json: {"detail": "<value>"}
683685
get_connection_check_sources:
684686
speakeasy-default-get-connection-check-sources:
685687
parameters:
@@ -690,6 +692,6 @@ examples:
690692
"200":
691693
application/json: {"created_at": "2023-09-12T00:38:55.692Z", "id": "f7d1d931-a753-4fe9-ae3f-671f188a9b55", "status": "SUCCESS"}
692694
"422":
693-
application/json: {"detail": [{"loc": ["<value>"], "msg": "<value>", "type": "<value>"}, {"loc": [], "msg": "<value>", "type": "<value>"}]}
695+
application/json: {"detail": "<value>"}
694696
examplesVersion: 1.0.1
695697
generatedTests: {}

.speakeasy/workflow.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
speakeasyVersion: 1.535.1
1+
speakeasyVersion: 1.537.0
22
sources:
33
my-source:
44
sourceNamespace: my-source
5-
sourceRevisionDigest: sha256:6771a944eaf5581cde4835c43e7997635f7d80ce441763c47cad9c305ba4a91e
5+
sourceRevisionDigest: sha256:f5fa536ffbf6240b18b267193074d11564a899dd6fdee36261205b93c8f84880
66
sourceBlobDigest: sha256:521a1c7be485e2be9f33ff7b82566823e96827cb69f7ca7775e0dd3dcc52d825
77
tags:
88
- latest
9-
- speakeasy-sdk-regen-1745261613
9+
- speakeasy-sdk-regen-1745334275
1010
- 1.1.7
1111
targets:
1212
unstructured-python:
1313
source: my-source
1414
sourceNamespace: my-source
15-
sourceRevisionDigest: sha256:6771a944eaf5581cde4835c43e7997635f7d80ce441763c47cad9c305ba4a91e
15+
sourceRevisionDigest: sha256:f5fa536ffbf6240b18b267193074d11564a899dd6fdee36261205b93c8f84880
1616
sourceBlobDigest: sha256:521a1c7be485e2be9f33ff7b82566823e96827cb69f7ca7775e0dd3dcc52d825
1717
codeSamplesNamespace: my-source-code-samples
18-
codeSamplesRevisionDigest: sha256:06bd35ef844f603c2c2357092fc875febff06f5c9eb855e262ff013b8935d8d6
18+
codeSamplesRevisionDigest: sha256:5940dadc286e702b4e23f58d1b7b536ffea4648a9f4f4a7ab650c6c107730a28
1919
workflow:
2020
workflowVersion: 1.0.0
2121
speakeasyVersion: latest

RELEASES.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -977,4 +977,14 @@ Based on:
977977
### Generated
978978
- [python v0.33.1] .
979979
### Releases
980-
- [PyPI v0.33.1] https://pypi.org/project/unstructured-client/0.33.1 - .
980+
- [PyPI v0.33.1] https://pypi.org/project/unstructured-client/0.33.1 - .
981+
982+
## 2025-04-22 15:11:11
983+
### Changes
984+
Based on:
985+
- OpenAPI Doc
986+
- Speakeasy CLI 1.537.0 (2.588.0) https://github.com/speakeasy-api/speakeasy
987+
### Generated
988+
- [python v0.34.0] .
989+
### Releases
990+
- [PyPI v0.34.0] https://pypi.org/project/unstructured-client/0.34.0 - .

_test_unstructured_client/unit/test_custom_hooks.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def mock_post(request):
169169
with pytest.raises(Exception):
170170
session.general.partition(request=req, retries=retries)
171171

172-
pattern = re.compile(f"Failed to process a request due to connection error .*? "
172+
pattern = re.compile("Failed to process a request due to connection error .*? "
173173
"Attempting retry number 1 after sleep.")
174174
assert bool(pattern.search(caplog.text))
175175

@@ -198,23 +198,20 @@ def test_unit_clean_server_url_fixes_malformed_paid_api_url(server_url: str):
198198

199199

200200
@pytest.mark.parametrize(
201-
"server_url",
201+
"server_url,expected_url",
202202
[
203-
# -- well-formed url --
204-
"http://localhost:8000",
205-
# -- common malformed urls --
206-
"localhost:8000",
207-
"localhost:8000/general/v0/general",
208-
"http://localhost:8000/general/v0/general",
203+
("http://localhost:8000", "http://localhost:8000"),
204+
("localhost:8000", "http://localhost:8000"),
205+
("localhost:8000/general/v0/general", "http://localhost:8000/general/v0/general"),
206+
("http://localhost:8000/general/v0/general", "http://localhost:8000/general/v0/general"),
209207
],
210208
)
211-
def test_unit_clean_server_url_fixes_malformed_localhost_url(server_url: str):
209+
def test_unit_clean_server_url_fixes_non_unst_domain_url(server_url: str, expected_url: str):
212210
client = UnstructuredClient(
213211
server_url=server_url,
214212
api_key_auth=FAKE_KEY,
215213
)
216-
assert client.general.sdk_configuration.server_url == "http://localhost:8000"
217-
214+
assert client.general.sdk_configuration.server_url == expected_url
218215

219216
@pytest.mark.parametrize(
220217
"server_url",

_test_unstructured_client/unit/test_request_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
get_base_url,
88
get_multipart_stream_fields,
99
)
10-
from unstructured_client.models import shared
1110

1211

1312
# make the above test using @pytest.mark.parametrize

0 commit comments

Comments
 (0)