Skip to content

Commit

Permalink
release: 0.0.11 (#18)
Browse files Browse the repository at this point in the history
* chore(internal): version bump (#16)

* feat(api): update via SDK Studio (#19)

* release: 0.0.11

---------

Co-authored-by: Stainless Bot <[email protected]>
Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
  • Loading branch information
stainless-app[bot] and Stainless Bot authored May 23, 2024
1 parent 405544f commit 30354ec
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.10"
}
".": "0.0.11"
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.0.11 (2024-05-23)

Full Changelog: [v0.0.10...v0.0.11](https://github.com/plastic-labs/honcho-python/compare/v0.0.10...v0.0.11)

### Features

* **api:** update via SDK Studio ([#19](https://github.com/plastic-labs/honcho-python/issues/19)) ([f9c3c3e](https://github.com/plastic-labs/honcho-python/commit/f9c3c3ec4934309b402f45dbeffb21e9b564dab1))


### Chores

* **internal:** version bump ([#16](https://github.com/plastic-labs/honcho-python/issues/16)) ([e873340](https://github.com/plastic-labs/honcho-python/commit/e873340f281f09c774b6cafe1502d2b7a205bcd0))

## 0.0.10 (2024-05-23)

Full Changelog: [v0.0.9...v0.0.10](https://github.com/plastic-labs/honcho-python/compare/v0.0.9...v0.0.10)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ from honcho import Honcho

client = Honcho(
# This is the default and can be omitted
api_key=os.environ.get("HONCHO_AUTH_TOKEN"),
api_key=os.environ.get("HONCHO_API_KEY"),
# defaults to "local".
environment="demo",
)
Expand All @@ -42,7 +42,7 @@ print(app.id)

While you can provide an `api_key` keyword argument,
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
to add `HONCHO_AUTH_TOKEN="My API Key"` to your `.env` file
to add `HONCHO_API_KEY="My API Key"` to your `.env` file
so that your API Key is not stored in source control.

## Async usage
Expand All @@ -56,7 +56,7 @@ from honcho import AsyncHoncho

client = AsyncHoncho(
# This is the default and can be omitted
api_key=os.environ.get("HONCHO_AUTH_TOKEN"),
api_key=os.environ.get("HONCHO_API_KEY"),
# defaults to "local".
environment="demo",
)
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 = "honcho-ai"
version = "0.0.10"
version = "0.0.11"
description = "The official Python library for the honcho API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
49 changes: 34 additions & 15 deletions src/honcho/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ._types import (
NOT_GIVEN,
Omit,
Headers,
Timeout,
NotGiven,
Transport,
Expand All @@ -25,7 +26,7 @@
)
from ._version import __version__
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
from ._exceptions import HonchoError, APIStatusError
from ._exceptions import APIStatusError
from ._base_client import (
DEFAULT_MAX_RETRIES,
SyncAPIClient,
Expand Down Expand Up @@ -57,7 +58,7 @@ class Honcho(SyncAPIClient):
with_streaming_response: HonchoWithStreamedResponse

# client options
api_key: str
api_key: str | None

_environment: Literal["local", "demo"] | NotGiven

Expand Down Expand Up @@ -87,14 +88,10 @@ def __init__(
) -> None:
"""Construct a new synchronous honcho client instance.
This automatically infers the `api_key` argument from the `HONCHO_AUTH_TOKEN` environment variable if it is not provided.
This automatically infers the `api_key` argument from the `HONCHO_API_KEY` environment variable if it is not provided.
"""
if api_key is None:
api_key = os.environ.get("HONCHO_AUTH_TOKEN")
if api_key is None:
raise HonchoError(
"The api_key client option must be set either by passing api_key to the client or by setting the HONCHO_AUTH_TOKEN environment variable"
)
api_key = os.environ.get("HONCHO_API_KEY")
self.api_key = api_key

self._environment = environment
Expand Down Expand Up @@ -147,6 +144,8 @@ def qs(self) -> Querystring:
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
if api_key is None:
return {}
return {"Authorization": f"Bearer {api_key}"}

@property
Expand All @@ -158,6 +157,17 @@ def default_headers(self) -> dict[str, str | Omit]:
**self._custom_headers,
}

@override
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
if self.api_key and headers.get("Authorization"):
return
if isinstance(custom_headers.get("Authorization"), Omit):
return

raise TypeError(
'"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
)

def copy(
self,
*,
Expand Down Expand Up @@ -251,7 +261,7 @@ class AsyncHoncho(AsyncAPIClient):
with_streaming_response: AsyncHonchoWithStreamedResponse

# client options
api_key: str
api_key: str | None

_environment: Literal["local", "demo"] | NotGiven

Expand Down Expand Up @@ -281,14 +291,10 @@ def __init__(
) -> None:
"""Construct a new async honcho client instance.
This automatically infers the `api_key` argument from the `HONCHO_AUTH_TOKEN` environment variable if it is not provided.
This automatically infers the `api_key` argument from the `HONCHO_API_KEY` environment variable if it is not provided.
"""
if api_key is None:
api_key = os.environ.get("HONCHO_AUTH_TOKEN")
if api_key is None:
raise HonchoError(
"The api_key client option must be set either by passing api_key to the client or by setting the HONCHO_AUTH_TOKEN environment variable"
)
api_key = os.environ.get("HONCHO_API_KEY")
self.api_key = api_key

self._environment = environment
Expand Down Expand Up @@ -341,6 +347,8 @@ def qs(self) -> Querystring:
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
if api_key is None:
return {}
return {"Authorization": f"Bearer {api_key}"}

@property
Expand All @@ -352,6 +360,17 @@ def default_headers(self) -> dict[str, str | Omit]:
**self._custom_headers,
}

@override
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
if self.api_key and headers.get("Authorization"):
return
if isinstance(custom_headers.get("Authorization"), Omit):
return

raise TypeError(
'"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
)

def copy(
self,
*,
Expand Down
2 changes: 1 addition & 1 deletion src/honcho/_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__ = "honcho"
__version__ = "0.0.10" # x-release-please-version
__version__ = "0.0.11" # x-release-please-version
33 changes: 26 additions & 7 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
from pydantic import ValidationError

from honcho import Honcho, AsyncHoncho, APIResponseValidationError
from honcho._types import Omit
from honcho._models import BaseModel, FinalRequestOptions
from honcho._constants import RAW_RESPONSE_HEADER
from honcho._exceptions import HonchoError, APIStatusError, APITimeoutError, APIResponseValidationError
from honcho._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
from honcho._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options

from .utils import update_env
Expand Down Expand Up @@ -326,9 +327,18 @@ def test_validate_headers(self) -> None:
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
assert request.headers.get("Authorization") == f"Bearer {api_key}"

with pytest.raises(HonchoError):
client2 = Honcho(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2
client2 = Honcho(base_url=base_url, api_key=None, _strict_response_validation=True)

with pytest.raises(
TypeError,
match="Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted",
):
client2._build_request(FinalRequestOptions(method="get", url="/foo"))

request2 = client2._build_request(
FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()})
)
assert request2.headers.get("Authorization") is None

def test_default_query_option(self) -> None:
client = Honcho(
Expand Down Expand Up @@ -1017,9 +1027,18 @@ def test_validate_headers(self) -> None:
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
assert request.headers.get("Authorization") == f"Bearer {api_key}"

with pytest.raises(HonchoError):
client2 = AsyncHoncho(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2
client2 = AsyncHoncho(base_url=base_url, api_key=None, _strict_response_validation=True)

with pytest.raises(
TypeError,
match="Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted",
):
client2._build_request(FinalRequestOptions(method="get", url="/foo"))

request2 = client2._build_request(
FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()})
)
assert request2.headers.get("Authorization") is None

def test_default_query_option(self) -> None:
client = AsyncHoncho(
Expand Down

0 comments on commit 30354ec

Please sign in to comment.