Skip to content
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 @@
{
".": "1.12.2"
".": "1.13.0"
}
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 1.13.0 (2025-06-27)

Full Changelog: [v1.12.2...v1.13.0](https://github.com/OneBusAway/python-sdk/compare/v1.12.2...v1.13.0)

### Features

* **client:** add support for aiohttp ([30eada9](https://github.com/OneBusAway/python-sdk/commit/30eada97ab7083d960307901bb55ef931ff6b202))


### Bug Fixes

* **ci:** release-doctor — report correct token name ([32bbbb3](https://github.com/OneBusAway/python-sdk/commit/32bbbb36efc1e3ebe55502aba1d140b0670e671c))


### Chores

* **tests:** skip some failing tests on the latest python versions ([6a88517](https://github.com/OneBusAway/python-sdk/commit/6a88517328513ff342df314e1d1da26795f3bb72))

## 1.12.2 (2025-06-19)

Full Changelog: [v1.12.1...v1.12.2](https://github.com/OneBusAway/python-sdk/compare/v1.12.1...v1.12.2)
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,37 @@ asyncio.run(main())

Functionality between the synchronous and asynchronous clients is otherwise identical.

### With aiohttp

By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.

You can enable this by installing `aiohttp`:

```sh
# install from PyPI
pip install onebusaway[aiohttp]
```

Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:

```python
import os
import asyncio
from onebusaway import DefaultAioHttpClient
from onebusaway import AsyncOnebusawaySDK


async def main() -> None:
async with AsyncOnebusawaySDK(
api_key=os.environ.get("ONEBUSAWAY_API_KEY"), # This is the default and can be omitted
http_client=DefaultAioHttpClient(),
) as client:
current_time = await client.current_time.retrieve()


asyncio.run(main())
```

## Using types

Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
Expand Down
2 changes: 1 addition & 1 deletion bin/check-release-environment
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
errors=()

if [ -z "${PYPI_TOKEN}" ]; then
errors+=("The ONEBUSAWAY_SDK_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
errors+=("The PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
fi

lenErrors=${#errors[@]}
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "onebusaway"
version = "1.12.2"
version = "1.13.0"
description = "The official Python library for the onebusaway-sdk API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -37,6 +37,8 @@ classifiers = [
Homepage = "https://github.com/OneBusAway/python-sdk"
Repository = "https://github.com/OneBusAway/python-sdk"

[project.optional-dependencies]
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.6"]

[tool.rye]
managed = true
Expand Down
27 changes: 27 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@
# universal: false

-e file:.
aiohappyeyeballs==2.6.1
# via aiohttp
aiohttp==3.12.8
# via httpx-aiohttp
# via onebusaway
aiosignal==1.3.2
# via aiohttp
annotated-types==0.6.0
# via pydantic
anyio==4.4.0
# via httpx
# via onebusaway
argcomplete==3.1.2
# via nox
async-timeout==5.0.1
# via aiohttp
attrs==25.3.0
# via aiohttp
certifi==2023.7.22
# via httpcore
# via httpx
Expand All @@ -34,23 +45,33 @@ execnet==2.1.1
# via pytest-xdist
filelock==3.12.4
# via virtualenv
frozenlist==1.6.2
# via aiohttp
# via aiosignal
h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.28.1
# via httpx-aiohttp
# via onebusaway
# via respx
httpx-aiohttp==0.1.6
# via onebusaway
idna==3.4
# via anyio
# via httpx
# via yarl
importlib-metadata==7.0.0
iniconfig==2.0.0
# via pytest
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
multidict==6.4.4
# via aiohttp
# via yarl
mypy==1.14.1
mypy-extensions==1.0.0
# via mypy
Expand All @@ -65,6 +86,9 @@ platformdirs==3.11.0
# via virtualenv
pluggy==1.5.0
# via pytest
propcache==0.3.1
# via aiohttp
# via yarl
pydantic==2.10.3
# via onebusaway
pydantic-core==2.27.1
Expand Down Expand Up @@ -97,12 +121,15 @@ tomli==2.0.2
# via pytest
typing-extensions==4.12.2
# via anyio
# via multidict
# via mypy
# via onebusaway
# via pydantic
# via pydantic-core
# via pyright
virtualenv==20.24.5
# via nox
yarl==1.20.0
# via aiohttp
zipp==3.17.0
# via importlib-metadata
27 changes: 27 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,51 @@
# universal: false

-e file:.
aiohappyeyeballs==2.6.1
# via aiohttp
aiohttp==3.12.8
# via httpx-aiohttp
# via onebusaway
aiosignal==1.3.2
# via aiohttp
annotated-types==0.6.0
# via pydantic
anyio==4.4.0
# via httpx
# via onebusaway
async-timeout==5.0.1
# via aiohttp
attrs==25.3.0
# via aiohttp
certifi==2023.7.22
# via httpcore
# via httpx
distro==1.8.0
# via onebusaway
exceptiongroup==1.2.2
# via anyio
frozenlist==1.6.2
# via aiohttp
# via aiosignal
h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.28.1
# via httpx-aiohttp
# via onebusaway
httpx-aiohttp==0.1.6
# via onebusaway
idna==3.4
# via anyio
# via httpx
# via yarl
multidict==6.4.4
# via aiohttp
# via yarl
propcache==0.3.1
# via aiohttp
# via yarl
pydantic==2.10.3
# via onebusaway
pydantic-core==2.27.1
Expand All @@ -40,6 +64,9 @@ sniffio==1.3.0
# via onebusaway
typing-extensions==4.12.2
# via anyio
# via multidict
# via onebusaway
# via pydantic
# via pydantic-core
yarl==1.20.0
# via aiohttp
3 changes: 2 additions & 1 deletion src/onebusaway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
UnprocessableEntityError,
APIResponseValidationError,
)
from ._base_client import DefaultHttpxClient, DefaultAsyncHttpxClient
from ._base_client import DefaultHttpxClient, DefaultAioHttpClient, DefaultAsyncHttpxClient
from ._utils._logs import setup_logging as _setup_logging

__all__ = [
Expand Down Expand Up @@ -78,6 +78,7 @@
"DEFAULT_CONNECTION_LIMITS",
"DefaultHttpxClient",
"DefaultAsyncHttpxClient",
"DefaultAioHttpClient",
]

if not _t.TYPE_CHECKING:
Expand Down
22 changes: 22 additions & 0 deletions src/onebusaway/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,24 @@ def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)


try:
import httpx_aiohttp
except ImportError:

class _DefaultAioHttpClient(httpx.AsyncClient):
def __init__(self, **_kwargs: Any) -> None:
raise RuntimeError("To use the aiohttp client you must have installed the package with the `aiohttp` extra")
else:

class _DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
def __init__(self, **kwargs: Any) -> None:
kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
kwargs.setdefault("follow_redirects", True)

super().__init__(**kwargs)


if TYPE_CHECKING:
DefaultAsyncHttpxClient = httpx.AsyncClient
"""An alias to `httpx.AsyncClient` that provides the same defaults that this SDK
Expand All @@ -1297,8 +1315,12 @@ def __init__(self, **kwargs: Any) -> None:
This is useful because overriding the `http_client` with your own instance of
`httpx.AsyncClient` will result in httpx's defaults being used, not ours.
"""

DefaultAioHttpClient = httpx.AsyncClient
"""An alias to `httpx.AsyncClient` that changes the default HTTP transport to `aiohttp`."""
else:
DefaultAsyncHttpxClient = _DefaultAsyncHttpxClient
DefaultAioHttpClient = _DefaultAioHttpClient


class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
Expand Down
2 changes: 1 addition & 1 deletion src/onebusaway/_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__ = "onebusaway"
__version__ = "1.12.2" # x-release-please-version
__version__ = "1.13.0" # x-release-please-version
4 changes: 3 additions & 1 deletion tests/api_resources/test_agencies_with_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_streaming_response_list(self, client: OnebusawaySDK) -> None:


class TestAsyncAgenciesWithCoverage:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_list(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tests/api_resources/test_agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def test_path_params_retrieve(self, client: OnebusawaySDK) -> None:


class TestAsyncAgency:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tests/api_resources/test_arrival_and_departure.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ def test_path_params_list(self, client: OnebusawaySDK) -> None:


class TestAsyncArrivalAndDeparture:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tests/api_resources/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def test_path_params_retrieve(self, client: OnebusawaySDK) -> None:


class TestAsyncBlock:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tests/api_resources/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_streaming_response_retrieve(self, client: OnebusawaySDK) -> None:


class TestAsyncConfig:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tests/api_resources/test_current_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_streaming_response_retrieve(self, client: OnebusawaySDK) -> None:


class TestAsyncCurrentTime:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tests/api_resources/test_report_problem_with_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def test_path_params_retrieve(self, client: OnebusawaySDK) -> None:


class TestAsyncReportProblemWithStop:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tests/api_resources/test_report_problem_with_trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def test_path_params_retrieve(self, client: OnebusawaySDK) -> None:


class TestAsyncReportProblemWithTrip:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
parametrize = pytest.mark.parametrize(
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@parametrize
async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None:
Expand Down
Loading