Skip to content

Commit

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


## PYTHON CHANGELOG

## responseFormat: 0.1.0 - 2024-03-02
### 🐝 New Features
- add support for response formats and flat responses *(commit by
[@TristanSpeakEasy](https://github.com/TristanSpeakeasy))*



## core: 4.5.1 - 2024-03-06
### 🐛 Bug Fixes
- fixes to security header handling to be compatible with hooks *(commit
by [@TristanSpeakEasy](https://github.com/tristanspeakeasy))*
- fix py.typed file *(commit by
[@ryan-timothy-albert](https://github.com/ryan-timothy-albert))*



## core: 4.4.7 - 2024-02-23
### 🐛 Bug Fixes
- example generation for complex objects *(commit by
[@ThomasRooney](https://github.com/ThomasRooney))*

---------

Co-authored-by: speakeasybot <[email protected]>
Co-authored-by: John <[email protected]>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent 6091d9e commit d6b3c89
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 94 deletions.
13 changes: 7 additions & 6 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ id: 8b5fa338-9106-4734-abf0-e30d67044a90
management:
docChecksum: 0474212adfef86a6c183841a3cb9d75b
docVersion: 0.0.1
speakeasyVersion: internal
generationVersion: 2.277.0
releaseVersion: 0.21.1
configChecksum: 37b07ca4ef319a1d49602f97748e7aba
speakeasyVersion: 1.204.1
generationVersion: 2.279.1
releaseVersion: 0.22.0
configChecksum: e458fc5426aa3514cb9bd40351fff33a
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.5.0
core: 4.5.1
examples: 2.81.3
globalSecurity: 2.83.4
globalServerURLs: 2.82.1
nameOverrides: 2.81.1
responseFormat: 0.1.0
retries: 2.82.1
serverIDs: 2.81.1
unions: 2.82.6
generatedFiles:
- src/unstructured_client/sdkconfiguration.py
- src/unstructured_client/general.py
- src/unstructured_client/sdk.py
- py.typed
- pylintrc
- setup.py
- src/unstructured_client/__init__.py
Expand All @@ -51,7 +53,6 @@ generatedFiles:
- docs/models/shared/security.md
- USAGE.md
- .gitattributes
- src/unstructured_client/_hooks/registration.py
- src/unstructured_client/_hooks/sdkhooks.py
- src/unstructured_client/_hooks/types.py
- src/unstructured_client/_hooks/__init__.py
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,14 @@ Based on:
### Generated
- [python v0.21.1] .
### Releases
- [PyPI v0.21.1] https://pypi.org/project/unstructured-client/0.21.1 - .
- [PyPI v0.21.1] https://pypi.org/project/unstructured-client/0.21.1 - .

## 2024-03-08 00:19:03
### Changes
Based on:
- OpenAPI Doc 0.0.1
- Speakeasy CLI 1.204.1 (2.279.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v0.22.0] .
### Releases
- [PyPI v0.22.0] https://pypi.org/project/unstructured-client/0.22.0 - .
1 change: 1 addition & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ res = s.general.partition(req)
if res.elements is not None:
# handle response
pass

```
<!-- End SDK Example Usage [usage] -->
3 changes: 2 additions & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
python:
version: 0.21.1
version: 0.22.0
additionalDependencies:
dependencies:
deepdiff: '>=6.0'
Expand All @@ -34,3 +34,4 @@ python:
maxMethodParams: 0
outputModelSuffix: output
packageName: unstructured-client
responseFormat: envelope
1 change: 1 addition & 0 deletions py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Marker file for PEP 561. The package enables type hints.
2 changes: 1 addition & 1 deletion 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.21.1",
version="0.22.0",
author="Unstructured",
description="Python Client SDK for Unstructured API",
license = "MIT",
Expand Down
9 changes: 4 additions & 5 deletions src/unstructured_client/_hooks/sdkhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@


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):
self.sdk_init_hooks: List[SDKInitHook] = []
self.before_request_hooks: List[BeforeRequestHook] = []
self.after_success_hooks: List[AfterSuccessHook] = []
self.after_error_hooks: List[AfterErrorHook] = []
init_hooks(self)

def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
Expand Down
32 changes: 18 additions & 14 deletions src/unstructured_client/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ def partition(self, request: Optional[shared.PartitionParameters], retries: Opti
base_url = utils.template_url(*self.sdk_configuration.get_server_details())

url = base_url + '/general/v0/general'
headers = {}

if callable(self.sdk_configuration.security):
headers, query_params = utils.get_security(self.sdk_configuration.security())
else:
headers, query_params = utils.get_security(self.sdk_configuration.security)

req_content_type, data, form = utils.serialize_request_body(request, Optional[shared.PartitionParameters], "request", False, True, 'multipart')
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

if callable(self.sdk_configuration.security):
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
else:
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)

client = self.sdk_configuration.client

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

req = None
def do_request():
nonlocal req
try:
req = self.sdk_configuration.get_hooks().before_request(
hook_ctx,
requests_http.Request('POST', url, data=data, files=form, headers=headers).prepare(),
requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(),
)
http_res = client.send(req)
except Exception as e:
Expand All @@ -72,26 +74,28 @@ def do_request():
'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)
res = operations.PartitionResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type'), raw_response=http_res)

if http_res.status_code == 200:
if utils.match_content_type(content_type, 'application/json'):
if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'):
out = utils.unmarshal_json(http_res.text, Optional[List[Any]])
res.elements = out
else:
content_type = http_res.headers.get('Content-Type')
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
elif http_res.status_code == 422:
if utils.match_content_type(content_type, 'application/json'):
if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'):
out = utils.unmarshal_json(http_res.text, errors.HTTPValidationError)
out.raw_response = http_res
raise out
else:
content_type = http_res.headers.get('Content-Type')
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
elif http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
else:
raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)

return res



2 changes: 1 addition & 1 deletion src/unstructured_client/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from unstructured_client.models import shared
from unstructured_client.utils._human_utils import clean_server_url # human code


class UnstructuredClient:
r"""Unstructured Pipeline API: Partition documents with the Unstructured library"""
general: General
Expand Down Expand Up @@ -69,3 +68,4 @@ def security():

def _init_sdks(self):
self.general = General(self.sdk_configuration)

6 changes: 3 additions & 3 deletions src/unstructured_client/sdkconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class SDKConfiguration:
server: str = ''
language: str = 'python'
openapi_doc_version: str = '0.0.1'
sdk_version: str = '0.21.1'
gen_version: str = '2.277.0'
user_agent: str = 'speakeasy-sdk/python 0.21.1 2.277.0 0.0.1 unstructured-client'
sdk_version: str = '0.22.0'
gen_version: str = '2.279.1'
user_agent: str = 'speakeasy-sdk/python 0.22.0 2.279.1 0.0.1 unstructured-client'
retry_config: RetryConfig = None
_hooks: SDKHooks = None

Expand Down
2 changes: 1 addition & 1 deletion src/unstructured_client/utils/retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from unstructured_client.utils._human_utils import log_retries # human code


class BackoffStrategy:
initial_interval: int
max_interval: int
Expand Down Expand Up @@ -121,3 +120,4 @@ def retry_with_backoff(func, initial_interval=500, max_interval=60000, exponent=
log_retries(retry_count=retries+1, sleep=sleep, exception=exception) # human code
time.sleep(sleep)
retries += 1

Loading

0 comments on commit d6b3c89

Please sign in to comment.