Skip to content

Commit

Permalink
chore: 🐝 Update SDK - Generate (#46)
Browse files Browse the repository at this point in the history
# SDK update
Based on:
- OpenAPI Doc 0.0.1 
- Speakeasy CLI 1.200.0 (2.277.0)
https://github.com/speakeasy-api/speakeasy


## PYTHON CHANGELOG

## unions: 2.82.6 - 2024-02-29
### 🐛 Bug Fixes
- null-enums are treated as switch a oneOf field to nullable *(commit by
[@disintegrator](https://github.com/disintegrator))*



## core: 4.5.0 - 2024-02-19
### 🐝 New Features
- add sdk hooks support to python *(commit by
[@TristanSpeakEasy](https://github.com/TristanSpeakeasy))*



## globalSecurity: 2.83.4 - 2024-02-26
### 🔧 Chores
- add no-security testcase *(commit by
[@2ynn](https://github.com/2ynn))*



## globalSecurity: 2.83.3 - 2024-02-23
### 🐛 Bug Fixes
- allow security to be disabled at the operation level *(commit by
[@TristanSpeakEasy](https://github.com/TristanSpeakeasy))*

---------

Co-authored-by: speakeasybot <[email protected]>
  • Loading branch information
github-actions[bot] and speakeasybot committed Mar 2, 2024
1 parent 3961bb0 commit 4afad44
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 47 deletions.
17 changes: 10 additions & 7 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
lockVersion: 2.0.0
id: 8b5fa338-9106-4734-abf0-e30d67044a90
management:
docChecksum: 903444f359d1dfa6342c692ae3e5c7ff
docChecksum: a112aea005467aa6818696fa4e99fcfe
docVersion: 0.0.1
speakeasyVersion: internal
generationVersion: 2.250.19
releaseVersion: 0.18.0
configChecksum: 938a4a39baa5695a3140be3b858483d4
generationVersion: 2.277.0
releaseVersion: 0.21.0
configChecksum: c5e7c8526f43272d7585627468d8c4e5
repoURL: https://github.com/Unstructured-IO/unstructured-python-client.git
repoSubDirectory: .
installationURL: https://github.com/Unstructured-IO/unstructured-python-client.git
published: true
features:
python:
core: 4.4.5
core: 4.5.0
examples: 2.81.3
globalSecurity: 2.83.2
globalSecurity: 2.83.4
globalServerURLs: 2.82.1
nameOverrides: 2.81.1
retries: 2.82.1
serverIDs: 2.81.1
unions: 2.82.5
unions: 2.82.6
generatedFiles:
- src/unstructured_client/sdkconfiguration.py
- src/unstructured_client/general.py
Expand Down Expand Up @@ -51,3 +51,6 @@ generatedFiles:
- docs/models/shared/security.md
- USAGE.md
- .gitattributes
- src/unstructured_client/_hooks/sdkhooks.py
- src/unstructured_client/_hooks/types.py
- src/unstructured_client/_hooks/__init__.py
32 changes: 31 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,34 @@ Based on:
### Generated
- [python v0.18.0] .
### Releases
- [PyPI v0.18.0] https://pypi.org/project/unstructured-client/0.18.0 - .
- [PyPI v0.18.0] https://pypi.org/project/unstructured-client/0.18.0 - .

## 2024-02-19 00:19:41
### Changes
Based on:
- OpenAPI Doc 0.0.64
- Speakeasy CLI 1.183.2 (2.262.2) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v0.19.0] .
### Releases
- [PyPI v0.19.0] https://pypi.org/project/unstructured-client/0.19.0 - .

## 2024-02-22 00:18:37
### Changes
Based on:
- OpenAPI Doc 0.0.1
- Speakeasy CLI 1.189.0 (2.263.3) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v0.20.0] .
### Releases
- [PyPI v0.20.0] https://pypi.org/project/unstructured-client/0.20.0 - .

## 2024-03-01 23:20:07
### Changes
Based on:
- OpenAPI Doc 0.0.1
- Speakeasy CLI 1.200.0 (2.277.0) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v0.21.0] .
### Releases
- [PyPI v0.21.0] https://pypi.org/project/unstructured-client/0.21.0 - .
9 changes: 2 additions & 7 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ req = shared.PartitionParameters(
'image',
'table',
],
files=shared.Files(
content='0x2cC94b2FEF'.encode(),
file_name='um.shtml',
),
gz_uncompressed_content_type='application/pdf',
hi_res_model_name='yolox',
languages=[
Expand All @@ -31,9 +27,8 @@ req = shared.PartitionParameters(
max_characters=1500,
new_after_n_chars=1500,
output_format='application/json',
skip_infer_table_types=[
'pdf',
],
overlap=25,
overlap_all=True,
strategy='hi_res',
)

Expand Down
4 changes: 3 additions & 1 deletion docs/models/shared/partitionparameters.md

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ generation:
nameResolutionDec2023: false
parameterOrderingFeb2024: false
requestResponseComponentNamesFeb2024: false
auth:
oAuth2ClientCredentialsEnabled: false
python:
version: 0.18.0
version: 0.21.0
additionalDependencies:
dependencies: {}
extraDependencies:
dev: {}
author: Unstructured
clientServerStatusCodesAsErrors: true
description: Python Client SDK for Unstructured API
Expand Down
3 changes: 2 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ good-names=i,
k,
ex,
Run,
_
_,
e

# Good variable names regexes, separated by a comma. If names match any regex,
# they will always be accepted
Expand Down
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setuptools.setup(
name="unstructured-client",
version="0.18.0",
version="0.21.0",
author="Unstructured",
description="Python Client SDK for Unstructured API",
license = "MIT",
Expand All @@ -20,9 +20,9 @@
install_requires=[
"certifi>=2023.7.22",
"charset-normalizer>=3.2.0",
"dataclasses-json-speakeasy>=0.5.11",
"dataclasses-json>=0.6.4",
"idna>=3.4",
"jsonpath-python>=1.0.6 ",
"jsonpath-python>=1.0.6",
"marshmallow>=3.19.0",
"mypy-extensions>=1.0.0",
"packaging>=23.1",
Expand All @@ -34,7 +34,9 @@
"urllib3>=1.26.18",
],
extras_require={
"dev":["pylint==2.16.2"]
"dev": [
"pylint==2.16.2",
],
},
package_dir={'': 'src'},
python_requires='>=3.8',
Expand Down
4 changes: 4 additions & 0 deletions src/unstructured_client/_hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""

from .sdkhooks import *
from .types import *
55 changes: 55 additions & 0 deletions src/unstructured_client/_hooks/sdkhooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""

import requests
from .types import SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks
from typing import List, Optional, Tuple, Union


class SDKHooks(Hooks):
sdk_init_hooks: List[SDKInitHook] = []
before_request_hooks: List[BeforeRequestHook] = []
after_success_hooks: List[AfterSuccessHook] = []
after_error_hooks: List[AfterErrorHook] = []

def __init__(self):
pass

def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
self.sdk_init_hooks.append(hook)

def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
self.before_request_hooks.append(hook)

def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
self.after_success_hooks.append(hook)

def register_after_error_hook(self, hook: AfterErrorHook) -> None:
self.after_error_hooks.append(hook)

def sdk_init(self, base_url: str, client: requests.Session) -> Tuple[str, requests.Session]:
for hook in self.sdk_init_hooks:
base_url, client = hook.sdk_init(base_url, client)
return base_url, client

def before_request(self, hook_ctx: BeforeRequestContext, request: requests.PreparedRequest) -> Union[requests.PreparedRequest, Exception]:
for hook in self.before_request_hooks:
request = hook.before_request(hook_ctx, request)
if isinstance(request, Exception):
raise request

return request

def after_success(self, hook_ctx: AfterSuccessContext, response: requests.Response) -> requests.Response:
for hook in self.after_success_hooks:
response = hook.after_success(hook_ctx, response)
if isinstance(response, Exception):
raise response
return response

def after_error(self, hook_ctx: AfterErrorContext, response: Optional[requests.Response], error: Optional[Exception]) -> Tuple[Optional[requests.Response], Optional[Exception]]:
for hook in self.after_error_hooks:
result = hook.after_error(hook_ctx, response, error)
if isinstance(result, Exception):
raise result
response, error = result
return response, error
70 changes: 70 additions & 0 deletions src/unstructured_client/_hooks/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""

import requests as requests_http
from abc import ABC, abstractmethod
from typing import Any, Callable, List, Optional, Tuple, Union


class HookContext:
operation_id: str
oauth2_scopes: Optional[List[str]] = None
security_source: Optional[Union[Any, Callable[[], Any]]] = None

def __init__(self, operation_id: str, oauth2_scopes: Optional[List[str]], security_source: Optional[Union[Any, Callable[[], Any]]]):
self.operation_id = operation_id
self.oauth2_scopes = oauth2_scopes
self.security_source = security_source


class BeforeRequestContext(HookContext):
pass


class AfterSuccessContext(HookContext):
pass


class AfterErrorContext(HookContext):
pass


class SDKInitHook(ABC):
@abstractmethod
def sdk_init(self, base_url: str, client: requests_http.Session) -> Tuple[str, requests_http.Session]:
pass


class BeforeRequestHook(ABC):
@abstractmethod
def before_request(self, hook_ctx: BeforeRequestContext, request: requests_http.PreparedRequest) -> Union[requests_http.PreparedRequest, Exception]:
pass


class AfterSuccessHook(ABC):
@abstractmethod
def after_success(self, hook_ctx: AfterSuccessContext, response: requests_http.Response) -> Union[requests_http.PreparedRequest, Exception]:
pass


class AfterErrorHook(ABC):
@abstractmethod
def after_error(self, hook_ctx: AfterErrorContext, response: Optional[requests_http.Response], error: Optional[Exception]) -> Union[Tuple[Optional[requests_http.PreparedRequest], Optional[Exception]], Exception]:
pass


class Hooks(ABC):
@abstractmethod
def register_sdk_init_hook(self, hook: SDKInitHook):
pass

@abstractmethod
def register_before_request_hook(self, hook: BeforeRequestHook):
pass

@abstractmethod
def register_after_success_hook(self, hook: AfterSuccessHook):
pass

@abstractmethod
def register_after_error_hook(self, hook: AfterErrorHook):
pass
32 changes: 29 additions & 3 deletions src/unstructured_client/general.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""

import requests as requests_http
from .sdkconfiguration import SDKConfiguration
from typing import Any, List, Optional
from unstructured_client import utils
from unstructured_client._hooks import HookContext
from unstructured_client.models import errors, operations, shared
from unstructured_client.utils._human_utils import suggest_defining_url_if_401 # human code

Expand All @@ -13,15 +15,17 @@ def __init__(self, sdk_config: SDKConfiguration) -> None:
self.sdk_configuration = sdk_config



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

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


global_retry_config = self.sdk_configuration.retry_config
retry_config = retries
if retry_config is None:
Expand All @@ -40,11 +45,32 @@ def partition(self, request: Optional[shared.PartitionParameters], retries: Opti
retry_config = utils.RetryConfig('backoff', utils.BackoffStrategy(500, 60000, 1.5, 900000), True)

def do_request():
return client.request('POST', url, data=data, files=form, headers=headers)
try:
req = self.sdk_configuration.get_hooks().before_request(
hook_ctx,
requests_http.Request('POST', url, data=data, files=form, headers=headers).prepare(),
)
http_res = client.send(req)
except Exception as e:
_, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e)
raise e

if utils.match_status_codes(['422','4XX','5XX'], http_res.status_code):
http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None)
if e:
raise e
else:
result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res)
if isinstance(result, Exception):
raise result
http_res = result

return http_res

http_res = utils.retry(do_request, utils.Retries(retry_config, [
'5xx'
]))

content_type = http_res.headers.get('Content-Type')

res = operations.PartitionResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
Expand All @@ -67,4 +93,4 @@ def do_request():

return res


4 changes: 4 additions & 0 deletions src/unstructured_client/models/shared/partition_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class PartitionParameters:
r"""If chunking strategy is set, cut off new sections after reaching a length of n chars (soft max). Default: 1500"""
output_format: Optional[str] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'output_format' }})
r"""The format of the response. Supported formats are application/json and text/csv. Default: application/json."""
overlap: Optional[int] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'overlap' }})
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"""
overlap_all: Optional[bool] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'overlap_all' }})
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"""
pdf_infer_table_structure: Optional[bool] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'pdf_infer_table_structure' }})
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>."""
skip_infer_table_types: Optional[List[str]] = dataclasses.field(default=None, metadata={'multipart_form': { 'field_name': 'skip_infer_table_types' }})
Expand Down
Loading

0 comments on commit 4afad44

Please sign in to comment.