Skip to content

Commit 10b7707

Browse files
feat(api): update via SDK Studio (#5)
1 parent 2cc56e6 commit 10b7707

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ import os
2828
from oxp import Oxp
2929

3030
client = Oxp(
31-
bearer_token=os.environ.get("OXP_BEARER_TOKEN"), # This is the default and can be omitted
31+
bearer_token=os.environ.get("OXP_API_KEY"), # This is the default and can be omitted
3232
)
3333

34-
client.health.check()
34+
tool = client.tools.list()
35+
print(tool.items)
3536
```
3637

3738
While you can provide a `bearer_token` keyword argument,
3839
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
39-
to add `OXP_BEARER_TOKEN="My Bearer Token"` to your `.env` file
40+
to add `OXP_API_KEY="My Bearer Token"` to your `.env` file
4041
so that your Bearer Token is not stored in source control.
4142

4243
## Async usage
@@ -49,12 +50,13 @@ import asyncio
4950
from oxp import AsyncOxp
5051

5152
client = AsyncOxp(
52-
bearer_token=os.environ.get("OXP_BEARER_TOKEN"), # This is the default and can be omitted
53+
bearer_token=os.environ.get("OXP_API_KEY"), # This is the default and can be omitted
5354
)
5455

5556

5657
async def main() -> None:
57-
await client.health.check()
58+
tool = await client.tools.list()
59+
print(tool.items)
5860

5961

6062
asyncio.run(main())
@@ -122,7 +124,7 @@ from oxp import Oxp
122124
client = Oxp()
123125

124126
try:
125-
client.health.check()
127+
client.tools.list()
126128
except oxp.APIConnectionError as e:
127129
print("The server could not be reached")
128130
print(e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -165,7 +167,7 @@ client = Oxp(
165167
)
166168

167169
# Or, configure per-request:
168-
client.with_options(max_retries=5).health.check()
170+
client.with_options(max_retries=5).tools.list()
169171
```
170172

171173
### Timeouts
@@ -188,7 +190,7 @@ client = Oxp(
188190
)
189191

190192
# Override per-request:
191-
client.with_options(timeout=5.0).health.check()
193+
client.with_options(timeout=5.0).tools.list()
192194
```
193195

194196
On timeout, an `APITimeoutError` is thrown.
@@ -229,11 +231,11 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
229231
from oxp import Oxp
230232

231233
client = Oxp()
232-
response = client.health.with_raw_response.check()
234+
response = client.tools.with_raw_response.list()
233235
print(response.headers.get('X-My-Header'))
234236

235-
health = response.parse() # get the object that `health.check()` would have returned
236-
print(health)
237+
tool = response.parse() # get the object that `tools.list()` would have returned
238+
print(tool.items)
237239
```
238240

239241
These methods return an [`APIResponse`](https://github.com/OpenExecProtocol/oxp-python/tree/main/src/oxp/_response.py) object.
@@ -247,7 +249,7 @@ The above interface eagerly reads the full response body when you make the reque
247249
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
248250

249251
```python
250-
with client.health.with_streaming_response.check() as response:
252+
with client.tools.with_streaming_response.list() as response:
251253
print(response.headers.get("X-My-Header"))
252254

253255
for line in response.iter_lines():

src/oxp/_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ def __init__(
7070
) -> None:
7171
"""Construct a new synchronous Oxp client instance.
7272
73-
This automatically infers the `bearer_token` argument from the `OXP_BEARER_TOKEN` environment variable if it is not provided.
73+
This automatically infers the `bearer_token` argument from the `OXP_API_KEY` environment variable if it is not provided.
7474
"""
7575
if bearer_token is None:
76-
bearer_token = os.environ.get("OXP_BEARER_TOKEN")
76+
bearer_token = os.environ.get("OXP_API_KEY")
7777
if bearer_token is None:
7878
raise OxpError(
79-
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the OXP_BEARER_TOKEN environment variable"
79+
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the OXP_API_KEY environment variable"
8080
)
8181
self.bearer_token = bearer_token
8282

8383
if base_url is None:
8484
base_url = os.environ.get("OXP_BASE_URL")
8585
if base_url is None:
86-
base_url = f"https://api.example.com"
86+
base_url = f"https://api.arcade.dev"
8787

8888
super().__init__(
8989
version=__version__,
@@ -240,20 +240,20 @@ def __init__(
240240
) -> None:
241241
"""Construct a new async AsyncOxp client instance.
242242
243-
This automatically infers the `bearer_token` argument from the `OXP_BEARER_TOKEN` environment variable if it is not provided.
243+
This automatically infers the `bearer_token` argument from the `OXP_API_KEY` environment variable if it is not provided.
244244
"""
245245
if bearer_token is None:
246-
bearer_token = os.environ.get("OXP_BEARER_TOKEN")
246+
bearer_token = os.environ.get("OXP_API_KEY")
247247
if bearer_token is None:
248248
raise OxpError(
249-
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the OXP_BEARER_TOKEN environment variable"
249+
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the OXP_API_KEY environment variable"
250250
)
251251
self.bearer_token = bearer_token
252252

253253
if base_url is None:
254254
base_url = os.environ.get("OXP_BASE_URL")
255255
if base_url is None:
256-
base_url = f"https://api.example.com"
256+
base_url = f"https://api.arcade.dev"
257257

258258
super().__init__(
259259
version=__version__,

tests/test_client.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def test_validate_headers(self) -> None:
341341
assert request.headers.get("Authorization") == f"Bearer {bearer_token}"
342342

343343
with pytest.raises(OxpError):
344-
with update_env(**{"OXP_BEARER_TOKEN": Omit()}):
344+
with update_env(**{"OXP_API_KEY": Omit()}):
345345
client2 = Oxp(base_url=base_url, bearer_token=None, _strict_response_validation=True)
346346
_ = client2
347347

@@ -735,20 +735,20 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
735735
@mock.patch("oxp._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
736736
@pytest.mark.respx(base_url=base_url)
737737
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
738-
respx_mock.get("/health").mock(side_effect=httpx.TimeoutException("Test timeout error"))
738+
respx_mock.get("/tools").mock(side_effect=httpx.TimeoutException("Test timeout error"))
739739

740740
with pytest.raises(APITimeoutError):
741-
self.client.get("/health", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}})
741+
self.client.get("/tools", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}})
742742

743743
assert _get_open_connections(self.client) == 0
744744

745745
@mock.patch("oxp._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
746746
@pytest.mark.respx(base_url=base_url)
747747
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
748-
respx_mock.get("/health").mock(return_value=httpx.Response(500))
748+
respx_mock.get("/tools").mock(return_value=httpx.Response(500))
749749

750750
with pytest.raises(APIStatusError):
751-
self.client.get("/health", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}})
751+
self.client.get("/tools", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}})
752752

753753
assert _get_open_connections(self.client) == 0
754754

@@ -776,9 +776,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
776776
return httpx.Response(500)
777777
return httpx.Response(200)
778778

779-
respx_mock.get("/health").mock(side_effect=retry_handler)
779+
respx_mock.get("/tools").mock(side_effect=retry_handler)
780780

781-
response = client.health.with_raw_response.check()
781+
response = client.tools.with_raw_response.list()
782782

783783
assert response.retries_taken == failures_before_success
784784
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
@@ -798,9 +798,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
798798
return httpx.Response(500)
799799
return httpx.Response(200)
800800

801-
respx_mock.get("/health").mock(side_effect=retry_handler)
801+
respx_mock.get("/tools").mock(side_effect=retry_handler)
802802

803-
response = client.health.with_raw_response.check(extra_headers={"x-stainless-retry-count": Omit()})
803+
response = client.tools.with_raw_response.list(extra_headers={"x-stainless-retry-count": Omit()})
804804

805805
assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0
806806

@@ -821,9 +821,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
821821
return httpx.Response(500)
822822
return httpx.Response(200)
823823

824-
respx_mock.get("/health").mock(side_effect=retry_handler)
824+
respx_mock.get("/tools").mock(side_effect=retry_handler)
825825

826-
response = client.health.with_raw_response.check(extra_headers={"x-stainless-retry-count": "42"})
826+
response = client.tools.with_raw_response.list(extra_headers={"x-stainless-retry-count": "42"})
827827

828828
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
829829

@@ -1119,7 +1119,7 @@ def test_validate_headers(self) -> None:
11191119
assert request.headers.get("Authorization") == f"Bearer {bearer_token}"
11201120

11211121
with pytest.raises(OxpError):
1122-
with update_env(**{"OXP_BEARER_TOKEN": Omit()}):
1122+
with update_env(**{"OXP_API_KEY": Omit()}):
11231123
client2 = AsyncOxp(base_url=base_url, bearer_token=None, _strict_response_validation=True)
11241124
_ = client2
11251125

@@ -1517,23 +1517,23 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15171517
@mock.patch("oxp._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15181518
@pytest.mark.respx(base_url=base_url)
15191519
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1520-
respx_mock.get("/health").mock(side_effect=httpx.TimeoutException("Test timeout error"))
1520+
respx_mock.get("/tools").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15211521

15221522
with pytest.raises(APITimeoutError):
15231523
await self.client.get(
1524-
"/health", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}
1524+
"/tools", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}
15251525
)
15261526

15271527
assert _get_open_connections(self.client) == 0
15281528

15291529
@mock.patch("oxp._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15301530
@pytest.mark.respx(base_url=base_url)
15311531
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1532-
respx_mock.get("/health").mock(return_value=httpx.Response(500))
1532+
respx_mock.get("/tools").mock(return_value=httpx.Response(500))
15331533

15341534
with pytest.raises(APIStatusError):
15351535
await self.client.get(
1536-
"/health", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}
1536+
"/tools", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}
15371537
)
15381538

15391539
assert _get_open_connections(self.client) == 0
@@ -1563,9 +1563,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
15631563
return httpx.Response(500)
15641564
return httpx.Response(200)
15651565

1566-
respx_mock.get("/health").mock(side_effect=retry_handler)
1566+
respx_mock.get("/tools").mock(side_effect=retry_handler)
15671567

1568-
response = await client.health.with_raw_response.check()
1568+
response = await client.tools.with_raw_response.list()
15691569

15701570
assert response.retries_taken == failures_before_success
15711571
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
@@ -1588,9 +1588,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
15881588
return httpx.Response(500)
15891589
return httpx.Response(200)
15901590

1591-
respx_mock.get("/health").mock(side_effect=retry_handler)
1591+
respx_mock.get("/tools").mock(side_effect=retry_handler)
15921592

1593-
response = await client.health.with_raw_response.check(extra_headers={"x-stainless-retry-count": Omit()})
1593+
response = await client.tools.with_raw_response.list(extra_headers={"x-stainless-retry-count": Omit()})
15941594

15951595
assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0
15961596

@@ -1612,9 +1612,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16121612
return httpx.Response(500)
16131613
return httpx.Response(200)
16141614

1615-
respx_mock.get("/health").mock(side_effect=retry_handler)
1615+
respx_mock.get("/tools").mock(side_effect=retry_handler)
16161616

1617-
response = await client.health.with_raw_response.check(extra_headers={"x-stainless-retry-count": "42"})
1617+
response = await client.tools.with_raw_response.list(extra_headers={"x-stainless-retry-count": "42"})
16181618

16191619
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
16201620

0 commit comments

Comments
 (0)