Skip to content

release: 0.0.2 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.1-alpha.1"
".": "0.0.2"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.0.2 (2025-03-15)

Full Changelog: [v0.0.1-alpha.1...v0.0.2](https://github.com/OpenExecProtocol/oxp-python/compare/v0.0.1-alpha.1...v0.0.2)

### Features

* **api:** update via SDK Studio ([#5](https://github.com/OpenExecProtocol/oxp-python/issues/5)) ([10b7707](https://github.com/OpenExecProtocol/oxp-python/commit/10b770743b760ccc9b7a806fbebcd6d6c5eab9e9))

## 0.0.1-alpha.1 (2025-03-15)

Full Changelog: [v0.0.1-alpha.0...v0.0.1-alpha.1](https://github.com/OpenExecProtocol/oxp-python/compare/v0.0.1-alpha.0...v0.0.1-alpha.1)
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The REST API documentation can be found on [openexecprotocol.org](https://openex

```sh
# install from PyPI
pip install --pre oxp
pip install oxp
```

## Usage
Expand All @@ -28,15 +28,16 @@ import os
from oxp import Oxp

client = Oxp(
bearer_token=os.environ.get("OXP_BEARER_TOKEN"), # This is the default and can be omitted
bearer_token=os.environ.get("OXP_API_KEY"), # This is the default and can be omitted
)

client.health.check()
tool = client.tools.list()
print(tool.items)
```

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

## Async usage
Expand All @@ -49,12 +50,13 @@ import asyncio
from oxp import AsyncOxp

client = AsyncOxp(
bearer_token=os.environ.get("OXP_BEARER_TOKEN"), # This is the default and can be omitted
bearer_token=os.environ.get("OXP_API_KEY"), # This is the default and can be omitted
)


async def main() -> None:
await client.health.check()
tool = await client.tools.list()
print(tool.items)


asyncio.run(main())
Expand Down Expand Up @@ -122,7 +124,7 @@ from oxp import Oxp
client = Oxp()

try:
client.health.check()
client.tools.list()
except oxp.APIConnectionError as e:
print("The server could not be reached")
print(e.__cause__) # an underlying Exception, likely raised within httpx.
Expand Down Expand Up @@ -165,7 +167,7 @@ client = Oxp(
)

# Or, configure per-request:
client.with_options(max_retries=5).health.check()
client.with_options(max_retries=5).tools.list()
```

### Timeouts
Expand All @@ -188,7 +190,7 @@ client = Oxp(
)

# Override per-request:
client.with_options(timeout=5.0).health.check()
client.with_options(timeout=5.0).tools.list()
```

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

client = Oxp()
response = client.health.with_raw_response.check()
response = client.tools.with_raw_response.list()
print(response.headers.get('X-My-Header'))

health = response.parse() # get the object that `health.check()` would have returned
print(health)
tool = response.parse() # get the object that `tools.list()` would have returned
print(tool.items)
```

These methods return an [`APIResponse`](https://github.com/OpenExecProtocol/oxp-python/tree/main/src/oxp/_response.py) object.
Expand All @@ -247,7 +249,7 @@ The above interface eagerly reads the full response body when you make the reque
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.

```python
with client.health.with_streaming_response.check() as response:
with client.tools.with_streaming_response.list() as response:
print(response.headers.get("X-My-Header"))

for line in response.iter_lines():
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "oxp"
version = "0.0.1-alpha.1"
version = "0.0.2"
description = "The official Python library for the oxp API"
dynamic = ["readme"]
license = "MIT"
Expand Down
16 changes: 8 additions & 8 deletions src/oxp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ def __init__(
) -> None:
"""Construct a new synchronous Oxp client instance.

This automatically infers the `bearer_token` argument from the `OXP_BEARER_TOKEN` environment variable if it is not provided.
This automatically infers the `bearer_token` argument from the `OXP_API_KEY` environment variable if it is not provided.
"""
if bearer_token is None:
bearer_token = os.environ.get("OXP_BEARER_TOKEN")
bearer_token = os.environ.get("OXP_API_KEY")
if bearer_token is None:
raise OxpError(
"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"
"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"
)
self.bearer_token = bearer_token

if base_url is None:
base_url = os.environ.get("OXP_BASE_URL")
if base_url is None:
base_url = f"https://api.example.com"
base_url = f"https://api.arcade.dev"

super().__init__(
version=__version__,
Expand Down Expand Up @@ -240,20 +240,20 @@ def __init__(
) -> None:
"""Construct a new async AsyncOxp client instance.

This automatically infers the `bearer_token` argument from the `OXP_BEARER_TOKEN` environment variable if it is not provided.
This automatically infers the `bearer_token` argument from the `OXP_API_KEY` environment variable if it is not provided.
"""
if bearer_token is None:
bearer_token = os.environ.get("OXP_BEARER_TOKEN")
bearer_token = os.environ.get("OXP_API_KEY")
if bearer_token is None:
raise OxpError(
"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"
"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"
)
self.bearer_token = bearer_token

if base_url is None:
base_url = os.environ.get("OXP_BASE_URL")
if base_url is None:
base_url = f"https://api.example.com"
base_url = f"https://api.arcade.dev"

super().__init__(
version=__version__,
Expand Down
2 changes: 1 addition & 1 deletion src/oxp/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "oxp"
__version__ = "0.0.1-alpha.1" # x-release-please-version
__version__ = "0.0.2" # x-release-please-version
44 changes: 22 additions & 22 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def test_validate_headers(self) -> None:
assert request.headers.get("Authorization") == f"Bearer {bearer_token}"

with pytest.raises(OxpError):
with update_env(**{"OXP_BEARER_TOKEN": Omit()}):
with update_env(**{"OXP_API_KEY": Omit()}):
client2 = Oxp(base_url=base_url, bearer_token=None, _strict_response_validation=True)
_ = client2

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

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

assert _get_open_connections(self.client) == 0

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

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

assert _get_open_connections(self.client) == 0

Expand Down Expand Up @@ -776,9 +776,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
return httpx.Response(500)
return httpx.Response(200)

respx_mock.get("/health").mock(side_effect=retry_handler)
respx_mock.get("/tools").mock(side_effect=retry_handler)

response = client.health.with_raw_response.check()
response = client.tools.with_raw_response.list()

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

respx_mock.get("/health").mock(side_effect=retry_handler)
respx_mock.get("/tools").mock(side_effect=retry_handler)

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

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

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

respx_mock.get("/health").mock(side_effect=retry_handler)
respx_mock.get("/tools").mock(side_effect=retry_handler)

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

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

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

with pytest.raises(OxpError):
with update_env(**{"OXP_BEARER_TOKEN": Omit()}):
with update_env(**{"OXP_API_KEY": Omit()}):
client2 = AsyncOxp(base_url=base_url, bearer_token=None, _strict_response_validation=True)
_ = client2

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

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

assert _get_open_connections(self.client) == 0

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

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

assert _get_open_connections(self.client) == 0
Expand Down Expand Up @@ -1563,9 +1563,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
return httpx.Response(500)
return httpx.Response(200)

respx_mock.get("/health").mock(side_effect=retry_handler)
respx_mock.get("/tools").mock(side_effect=retry_handler)

response = await client.health.with_raw_response.check()
response = await client.tools.with_raw_response.list()

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

respx_mock.get("/health").mock(side_effect=retry_handler)
respx_mock.get("/tools").mock(side_effect=retry_handler)

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

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

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

respx_mock.get("/health").mock(side_effect=retry_handler)
respx_mock.get("/tools").mock(side_effect=retry_handler)

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

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

Expand Down