Skip to content

Commit 39edb7e

Browse files
speakeasybotscanny
authored andcommitted
ci: regenerated with OpenAPI Doc 0.0.1, Speakeasy CLI 1.200.0
1 parent e3f6de6 commit 39edb7e

File tree

16 files changed

+260
-36
lines changed

16 files changed

+260
-36
lines changed

.speakeasy/gen.lock

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
lockVersion: 2.0.0
22
id: 8b5fa338-9106-4734-abf0-e30d67044a90
33
management:
4-
docChecksum: 903444f359d1dfa6342c692ae3e5c7ff
4+
docChecksum: a112aea005467aa6818696fa4e99fcfe
55
docVersion: 0.0.1
66
speakeasyVersion: internal
7-
generationVersion: 2.263.3
8-
releaseVersion: 0.20.0
9-
configChecksum: cc7d371a0d9a447399c02d889587222d
7+
generationVersion: 2.277.0
8+
releaseVersion: 0.21.0
9+
configChecksum: c5e7c8526f43272d7585627468d8c4e5
1010
repoURL: https://github.com/Unstructured-IO/unstructured-python-client.git
1111
repoSubDirectory: .
1212
installationURL: https://github.com/Unstructured-IO/unstructured-python-client.git
1313
published: true
1414
features:
1515
python:
16-
core: 4.4.6
16+
core: 4.5.0
1717
examples: 2.81.3
18-
globalSecurity: 2.83.2
18+
globalSecurity: 2.83.4
1919
globalServerURLs: 2.82.1
2020
nameOverrides: 2.81.1
2121
retries: 2.82.1
2222
serverIDs: 2.81.1
23-
unions: 2.82.5
23+
unions: 2.82.6
2424
generatedFiles:
2525
- src/unstructured_client/sdkconfiguration.py
2626
- src/unstructured_client/general.py
@@ -51,3 +51,6 @@ generatedFiles:
5151
- docs/models/shared/security.md
5252
- USAGE.md
5353
- .gitattributes
54+
- src/unstructured_client/_hooks/sdkhooks.py
55+
- src/unstructured_client/_hooks/types.py
56+
- src/unstructured_client/_hooks/__init__.py

RELEASES.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,14 @@ Based on:
444444
### Generated
445445
- [python v0.20.0] .
446446
### Releases
447-
- [PyPI v0.20.0] https://pypi.org/project/unstructured-client/0.20.0 - .
447+
- [PyPI v0.20.0] https://pypi.org/project/unstructured-client/0.20.0 - .
448+
449+
## 2024-03-01 23:20:07
450+
### Changes
451+
Based on:
452+
- OpenAPI Doc 0.0.1
453+
- Speakeasy CLI 1.200.0 (2.277.0) https://github.com/speakeasy-api/speakeasy
454+
### Generated
455+
- [python v0.21.0] .
456+
### Releases
457+
- [PyPI v0.21.0] https://pypi.org/project/unstructured-client/0.21.0 - .

USAGE.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ req = shared.PartitionParameters(
2727
max_characters=1500,
2828
new_after_n_chars=1500,
2929
output_format='application/json',
30+
overlap=25,
31+
overlap_all=True,
3032
strategy='hi_res',
3133
)
3234

docs/models/shared/partitionparameters.md

+3-1
Large diffs are not rendered by default.

gen.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ generation:
77
nameResolutionDec2023: false
88
parameterOrderingFeb2024: false
99
requestResponseComponentNamesFeb2024: false
10+
auth:
11+
oAuth2ClientCredentialsEnabled: false
1012
python:
11-
version: 0.20.0
13+
version: 0.21.0
14+
additionalDependencies:
15+
dependencies: {}
16+
extraDependencies:
17+
dev: {}
1218
author: Unstructured
1319
clientServerStatusCodesAsErrors: true
1420
description: Python Client SDK for Unstructured API

pylintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ good-names=i,
179179
k,
180180
ex,
181181
Run,
182-
_
182+
_,
183+
e
183184

184185
# Good variable names regexes, separated by a comma. If names match any regex,
185186
# they will always be accepted

setup.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setuptools.setup(
1212
name="unstructured-client",
13-
version="0.20.0",
13+
version="0.21.0",
1414
author="Unstructured",
1515
description="Python Client SDK for Unstructured API",
1616
license = "MIT",
@@ -20,9 +20,9 @@
2020
install_requires=[
2121
"certifi>=2023.7.22",
2222
"charset-normalizer>=3.2.0",
23-
"dataclasses-json-speakeasy>=0.5.11",
23+
"dataclasses-json>=0.6.4",
2424
"idna>=3.4",
25-
"jsonpath-python>=1.0.6 ",
25+
"jsonpath-python>=1.0.6",
2626
"marshmallow>=3.19.0",
2727
"mypy-extensions>=1.0.0",
2828
"packaging>=23.1",
@@ -34,7 +34,9 @@
3434
"urllib3>=1.26.18",
3535
],
3636
extras_require={
37-
"dev":["pylint==2.16.2"]
37+
"dev": [
38+
"pylint==2.16.2",
39+
],
3840
},
3941
package_dir={'': 'src'},
4042
python_requires='>=3.8',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2+
3+
from .sdkhooks import *
4+
from .types import *
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2+
3+
import requests
4+
from .types import SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks
5+
from typing import List, Optional, Tuple, Union
6+
7+
8+
class SDKHooks(Hooks):
9+
sdk_init_hooks: List[SDKInitHook] = []
10+
before_request_hooks: List[BeforeRequestHook] = []
11+
after_success_hooks: List[AfterSuccessHook] = []
12+
after_error_hooks: List[AfterErrorHook] = []
13+
14+
def __init__(self):
15+
pass
16+
17+
def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
18+
self.sdk_init_hooks.append(hook)
19+
20+
def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
21+
self.before_request_hooks.append(hook)
22+
23+
def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
24+
self.after_success_hooks.append(hook)
25+
26+
def register_after_error_hook(self, hook: AfterErrorHook) -> None:
27+
self.after_error_hooks.append(hook)
28+
29+
def sdk_init(self, base_url: str, client: requests.Session) -> Tuple[str, requests.Session]:
30+
for hook in self.sdk_init_hooks:
31+
base_url, client = hook.sdk_init(base_url, client)
32+
return base_url, client
33+
34+
def before_request(self, hook_ctx: BeforeRequestContext, request: requests.PreparedRequest) -> Union[requests.PreparedRequest, Exception]:
35+
for hook in self.before_request_hooks:
36+
request = hook.before_request(hook_ctx, request)
37+
if isinstance(request, Exception):
38+
raise request
39+
40+
return request
41+
42+
def after_success(self, hook_ctx: AfterSuccessContext, response: requests.Response) -> requests.Response:
43+
for hook in self.after_success_hooks:
44+
response = hook.after_success(hook_ctx, response)
45+
if isinstance(response, Exception):
46+
raise response
47+
return response
48+
49+
def after_error(self, hook_ctx: AfterErrorContext, response: Optional[requests.Response], error: Optional[Exception]) -> Tuple[Optional[requests.Response], Optional[Exception]]:
50+
for hook in self.after_error_hooks:
51+
result = hook.after_error(hook_ctx, response, error)
52+
if isinstance(result, Exception):
53+
raise result
54+
response, error = result
55+
return response, error
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2+
3+
import requests as requests_http
4+
from abc import ABC, abstractmethod
5+
from typing import Any, Callable, List, Optional, Tuple, Union
6+
7+
8+
class HookContext:
9+
operation_id: str
10+
oauth2_scopes: Optional[List[str]] = None
11+
security_source: Optional[Union[Any, Callable[[], Any]]] = None
12+
13+
def __init__(self, operation_id: str, oauth2_scopes: Optional[List[str]], security_source: Optional[Union[Any, Callable[[], Any]]]):
14+
self.operation_id = operation_id
15+
self.oauth2_scopes = oauth2_scopes
16+
self.security_source = security_source
17+
18+
19+
class BeforeRequestContext(HookContext):
20+
pass
21+
22+
23+
class AfterSuccessContext(HookContext):
24+
pass
25+
26+
27+
class AfterErrorContext(HookContext):
28+
pass
29+
30+
31+
class SDKInitHook(ABC):
32+
@abstractmethod
33+
def sdk_init(self, base_url: str, client: requests_http.Session) -> Tuple[str, requests_http.Session]:
34+
pass
35+
36+
37+
class BeforeRequestHook(ABC):
38+
@abstractmethod
39+
def before_request(self, hook_ctx: BeforeRequestContext, request: requests_http.PreparedRequest) -> Union[requests_http.PreparedRequest, Exception]:
40+
pass
41+
42+
43+
class AfterSuccessHook(ABC):
44+
@abstractmethod
45+
def after_success(self, hook_ctx: AfterSuccessContext, response: requests_http.Response) -> Union[requests_http.PreparedRequest, Exception]:
46+
pass
47+
48+
49+
class AfterErrorHook(ABC):
50+
@abstractmethod
51+
def after_error(self, hook_ctx: AfterErrorContext, response: Optional[requests_http.Response], error: Optional[Exception]) -> Union[Tuple[Optional[requests_http.PreparedRequest], Optional[Exception]], Exception]:
52+
pass
53+
54+
55+
class Hooks(ABC):
56+
@abstractmethod
57+
def register_sdk_init_hook(self, hook: SDKInitHook):
58+
pass
59+
60+
@abstractmethod
61+
def register_before_request_hook(self, hook: BeforeRequestHook):
62+
pass
63+
64+
@abstractmethod
65+
def register_after_success_hook(self, hook: AfterSuccessHook):
66+
pass
67+
68+
@abstractmethod
69+
def register_after_error_hook(self, hook: AfterErrorHook):
70+
pass

src/unstructured_client/general.py

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
22

3+
import requests as requests_http
34
from .sdkconfiguration import SDKConfiguration
45
from typing import Any, List, Optional
56
from unstructured_client import utils
7+
from unstructured_client._hooks import HookContext
68
from unstructured_client.models import errors, operations, shared
9+
from unstructured_client.utils._human_utils import suggest_defining_url_if_401 # human code
710

811
class General:
912
sdk_configuration: SDKConfiguration
@@ -13,14 +16,16 @@ def __init__(self, sdk_config: SDKConfiguration) -> None:
1316

1417

1518

19+
@suggest_defining_url_if_401 # human code
1620
def partition(self, request: Optional[shared.PartitionParameters], retries: Optional[utils.RetryConfig] = None) -> operations.PartitionResponse:
1721
r"""Pipeline 1"""
22+
hook_ctx = HookContext(operation_id='partition', oauth2_scopes=[], security_source=self.sdk_configuration.security)
1823
base_url = utils.template_url(*self.sdk_configuration.get_server_details())
1924

2025
url = base_url + '/general/v0/general'
2126
headers = {}
2227
req_content_type, data, form = utils.serialize_request_body(request, Optional[shared.PartitionParameters], "request", False, True, 'multipart')
23-
if req_content_type not in ('multipart/form-data', 'multipart/mixed'):
28+
if req_content_type is not None and req_content_type not in ('multipart/form-data', 'multipart/mixed'):
2429
headers['content-type'] = req_content_type
2530
headers['Accept'] = 'application/json'
2631
headers['user-agent'] = self.sdk_configuration.user_agent
@@ -30,6 +35,7 @@ def partition(self, request: Optional[shared.PartitionParameters], retries: Opti
3035
else:
3136
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
3237

38+
3339
global_retry_config = self.sdk_configuration.retry_config
3440
retry_config = retries
3541
if retry_config is None:
@@ -39,11 +45,32 @@ def partition(self, request: Optional[shared.PartitionParameters], retries: Opti
3945
retry_config = utils.RetryConfig('backoff', utils.BackoffStrategy(500, 60000, 1.5, 900000), True)
4046

4147
def do_request():
42-
return client.request('POST', url, data=data, files=form, headers=headers)
48+
try:
49+
req = self.sdk_configuration.get_hooks().before_request(
50+
hook_ctx,
51+
requests_http.Request('POST', url, data=data, files=form, headers=headers).prepare(),
52+
)
53+
http_res = client.send(req)
54+
except Exception as e:
55+
_, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e)
56+
raise e
57+
58+
if utils.match_status_codes(['422','4XX','5XX'], http_res.status_code):
59+
http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None)
60+
if e:
61+
raise e
62+
else:
63+
result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res)
64+
if isinstance(result, Exception):
65+
raise result
66+
http_res = result
67+
68+
return http_res
4369

4470
http_res = utils.retry(do_request, utils.Retries(retry_config, [
4571
'5xx'
4672
]))
73+
4774
content_type = http_res.headers.get('Content-Type')
4875

4976
res = operations.PartitionResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
@@ -66,4 +93,4 @@ def do_request():
6693

6794
return res
6895

69-
96+

src/unstructured_client/models/shared/partition_parameters.py

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class PartitionParameters:
4343
r"""If chunking strategy is set, cut off new sections after reaching a length of n chars (soft max). Default: 1500"""
4444
output_format: Optional[str] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'output_format' }})
4545
r"""The format of the response. Supported formats are application/json and text/csv. Default: application/json."""
46+
overlap: Optional[int] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'overlap' }})
47+
r"""A prefix of this many trailing characters from prior text-split chunk is applied to second and later chunks formed from oversized elements by text-splitting. Default: None"""
48+
overlap_all: Optional[bool] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'overlap_all' }})
49+
r"""When True, overlap is also applied to 'normal' chunks formed by combining whole elements. Use with caution as this can introduce noise into otherwise clean semantic units. Default: None"""
4650
pdf_infer_table_structure: Optional[bool] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'pdf_infer_table_structure' }})
4751
r"""If True and strategy=hi_res, any Table Elements extracted from a PDF will include an additional metadata field, 'text_as_html', where the value (string) is a just a transformation of the data into an HTML <table>."""
4852
skip_infer_table_types: Optional[List[str]] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'skip_infer_table_types' }})

src/unstructured_client/sdk.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
from .sdkconfiguration import SDKConfiguration
66
from typing import Callable, Dict, Union
77
from unstructured_client import utils
8+
from unstructured_client._hooks import SDKHooks
89
from unstructured_client.models import shared
10+
from unstructured_client.utils._human_utils import clean_server_url # human code
911

1012
class UnstructuredClient:
1113
r"""Unstructured Pipeline API: Partition documents with the Unstructured library"""
1214
general: General
1315

1416
sdk_configuration: SDKConfiguration
1517

18+
@clean_server_url # human code
1619
def __init__(self,
1720
api_key_auth: Union[str, Callable[[], str]],
1821
server: str = None,
@@ -50,9 +53,19 @@ def security():
5053
server_url = utils.template_url(server_url, url_params)
5154

5255
self.sdk_configuration = SDKConfiguration(client, security, server_url, server, retry_config=retry_config)
56+
57+
hooks = SDKHooks()
58+
59+
current_server_url, *_ = self.sdk_configuration.get_server_details()
60+
server_url, self.sdk_configuration.client = hooks.sdk_init(current_server_url, self.sdk_configuration.client)
61+
if current_server_url != server_url:
62+
self.sdk_configuration.server_url = server_url
63+
64+
# pylint: disable=protected-access
65+
self.sdk_configuration._hooks=hooks
5366

5467
self._init_sdks()
5568

5669
def _init_sdks(self):
5770
self.general = General(self.sdk_configuration)
58-
71+

0 commit comments

Comments
 (0)