Skip to content

Commit f90f0b9

Browse files
committed
2 parents a1ebfcc + 087dd39 commit f90f0b9

File tree

220 files changed

+3354
-1001
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+3354
-1001
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "3.0.0-beta.10"
2+
".": "3.0.1"
33
}

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1348
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-49d54760f87326f9200c777f867e4ea579c92a43f481207ae252db9748c9b07b.yml
1+
configured_endpoints: 1353
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-1274668bf5bb40cc6a93aa05b9b1c96050656b905a292bccdb53941f50eaf81e.yml

CHANGELOG.md

Lines changed: 138 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The REST API documentation can be found [on developers.cloudflare.com](https://d
1414

1515
```sh
1616
# install from PyPI
17-
pip install --pre cloudflare
17+
pip install cloudflare
1818
```
1919

2020
## Usage

api.md

Lines changed: 46 additions & 30 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cloudflare"
3-
version = "3.0.0-beta.10"
3+
version = "3.0.1"
44
description = "The official Python library for the cloudflare API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/cloudflare/_base_client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
RequestOptions,
6161
ModelBuilderProtocol,
6262
)
63-
from ._utils import is_dict, is_list, is_given, lru_cache, is_mapping
63+
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
6464
from ._compat import model_copy, model_dump
6565
from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
6666
from ._response import (
@@ -358,6 +358,7 @@ def __init__(
358358
self._custom_query = custom_query or {}
359359
self._strict_response_validation = _strict_response_validation
360360
self._idempotency_header = None
361+
self._platform: Platform | None = None
361362

362363
if max_retries is None: # pyright: ignore[reportUnnecessaryComparison]
363364
raise TypeError(
@@ -622,7 +623,10 @@ def base_url(self, url: URL | str) -> None:
622623
self._base_url = self._enforce_trailing_slash(url if isinstance(url, URL) else URL(url))
623624

624625
def platform_headers(self) -> Dict[str, str]:
625-
return platform_headers(self._version)
626+
# the actual implementation is in a separate `lru_cache` decorated
627+
# function because adding `lru_cache` to methods will leak memory
628+
# https://github.com/python/cpython/issues/88476
629+
return platform_headers(self._version, platform=self._platform)
626630

627631
def _parse_retry_after_header(self, response_headers: Optional[httpx.Headers] = None) -> float | None:
628632
"""Returns a float of the number of seconds (not milliseconds) to wait after retrying, or None if unspecified.
@@ -1498,6 +1502,11 @@ async def _request(
14981502
stream_cls: type[_AsyncStreamT] | None,
14991503
remaining_retries: int | None,
15001504
) -> ResponseT | _AsyncStreamT:
1505+
if self._platform is None:
1506+
# `get_platform` can make blocking IO calls so we
1507+
# execute it earlier while we are in an async context
1508+
self._platform = await asyncify(get_platform)()
1509+
15011510
cast_to = self._maybe_override_cast_to(cast_to, options)
15021511
await self._prepare_options(options)
15031512

@@ -1921,11 +1930,11 @@ def get_platform() -> Platform:
19211930

19221931

19231932
@lru_cache(maxsize=None)
1924-
def platform_headers(version: str) -> Dict[str, str]:
1933+
def platform_headers(version: str, *, platform: Platform | None) -> Dict[str, str]:
19251934
return {
19261935
"X-Stainless-Lang": "python",
19271936
"X-Stainless-Package-Version": version,
1928-
"X-Stainless-OS": str(get_platform()),
1937+
"X-Stainless-OS": str(platform or get_platform()),
19291938
"X-Stainless-Arch": str(get_architecture()),
19301939
"X-Stainless-Runtime": get_python_runtime(),
19311940
"X-Stainless-Runtime-Version": get_python_version(),

src/cloudflare/_utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@
4949
maybe_transform as maybe_transform,
5050
async_maybe_transform as async_maybe_transform,
5151
)
52+
from ._reflection import function_has_argument as function_has_argument

src/cloudflare/_utils/_reflection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import inspect
2+
from typing import Any, Callable
3+
4+
5+
def function_has_argument(func: Callable[..., Any], arg_name: str) -> bool:
6+
"""Returns whether or not the given function has a specific parameter"""
7+
sig = inspect.signature(func)
8+
return arg_name in sig.parameters

src/cloudflare/_utils/_sync.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import anyio
88
import anyio.to_thread
99

10+
from ._reflection import function_has_argument
11+
1012
T_Retval = TypeVar("T_Retval")
1113
T_ParamSpec = ParamSpec("T_ParamSpec")
1214

@@ -59,6 +61,21 @@ def do_work(arg1, arg2, kwarg1="", kwarg2="") -> str:
5961

6062
async def wrapper(*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs) -> T_Retval:
6163
partial_f = functools.partial(function, *args, **kwargs)
62-
return await anyio.to_thread.run_sync(partial_f, cancellable=cancellable, limiter=limiter)
64+
65+
# In `v4.1.0` anyio added the `abandon_on_cancel` argument and deprecated the old
66+
# `cancellable` argument, so we need to use the new `abandon_on_cancel` to avoid
67+
# surfacing deprecation warnings.
68+
if function_has_argument(anyio.to_thread.run_sync, "abandon_on_cancel"):
69+
return await anyio.to_thread.run_sync(
70+
partial_f,
71+
abandon_on_cancel=cancellable,
72+
limiter=limiter,
73+
)
74+
75+
return await anyio.to_thread.run_sync(
76+
partial_f,
77+
cancellable=cancellable,
78+
limiter=limiter,
79+
)
6380

6481
return wrapper

src/cloudflare/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "cloudflare"
4-
__version__ = "3.0.0-beta.10" # x-release-please-version
4+
__version__ = "3.0.1" # x-release-please-version

src/cloudflare/resources/ai_gateway/ai_gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def list(
190190
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
191191
) -> SyncV4PagePaginationArray[AIGatewayListResponse]:
192192
"""
193-
List Gateway's
193+
List Gateways
194194
195195
Args:
196196
id: gateway id
@@ -457,7 +457,7 @@ def list(
457457
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
458458
) -> AsyncPaginator[AIGatewayListResponse, AsyncV4PagePaginationArray[AIGatewayListResponse]]:
459459
"""
460-
List Gateway's
460+
List Gateways
461461
462462
Args:
463463
id: gateway id

src/cloudflare/resources/ai_gateway/logs.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
from __future__ import annotations
44

5-
from typing import Type, Union, cast
5+
from typing import Union
66
from datetime import datetime
77
from typing_extensions import Literal
88

99
import httpx
1010

1111
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
12-
from ..._utils import (
13-
maybe_transform,
14-
async_maybe_transform,
15-
)
12+
from ..._utils import maybe_transform
1613
from ..._compat import cached_property
1714
from ..._resource import SyncAPIResource, AsyncAPIResource
1815
from ..._response import (
@@ -21,12 +18,13 @@
2118
async_to_raw_response_wrapper,
2219
async_to_streamed_response_wrapper,
2320
)
24-
from ..._wrappers import ResultWrapper
21+
from ...pagination import SyncV4PagePaginationArray, AsyncV4PagePaginationArray
2522
from ..._base_client import (
23+
AsyncPaginator,
2624
make_request_options,
2725
)
28-
from ...types.ai_gateway import log_get_params
29-
from ...types.ai_gateway.log_get_response import LogGetResponse
26+
from ...types.ai_gateway import log_list_params
27+
from ...types.ai_gateway.log_list_response import LogListResponse
3028

3129
__all__ = ["LogsResource", "AsyncLogsResource"]
3230

@@ -40,7 +38,7 @@ def with_raw_response(self) -> LogsResourceWithRawResponse:
4038
def with_streaming_response(self) -> LogsResourceWithStreamingResponse:
4139
return LogsResourceWithStreamingResponse(self)
4240

43-
def get(
41+
def list(
4442
self,
4543
id: str,
4644
*,
@@ -60,7 +58,7 @@ def get(
6058
extra_query: Query | None = None,
6159
extra_body: Body | None = None,
6260
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
63-
) -> LogGetResponse:
61+
) -> SyncV4PagePaginationArray[LogListResponse]:
6462
"""
6563
List Gateway Logs
6664
@@ -79,8 +77,9 @@ def get(
7977
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
8078
if not id:
8179
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
82-
return self._get(
80+
return self._get_api_list(
8381
f"/accounts/{account_id}/ai-gateway/gateways/{id}/logs",
82+
page=SyncV4PagePaginationArray[LogListResponse],
8483
options=make_request_options(
8584
extra_headers=extra_headers,
8685
extra_query=extra_query,
@@ -98,11 +97,10 @@ def get(
9897
"start_date": start_date,
9998
"success": success,
10099
},
101-
log_get_params.LogGetParams,
100+
log_list_params.LogListParams,
102101
),
103-
post_parser=ResultWrapper[LogGetResponse]._unwrapper,
104102
),
105-
cast_to=cast(Type[LogGetResponse], ResultWrapper[LogGetResponse]),
103+
model=LogListResponse,
106104
)
107105

108106

@@ -115,7 +113,7 @@ def with_raw_response(self) -> AsyncLogsResourceWithRawResponse:
115113
def with_streaming_response(self) -> AsyncLogsResourceWithStreamingResponse:
116114
return AsyncLogsResourceWithStreamingResponse(self)
117115

118-
async def get(
116+
def list(
119117
self,
120118
id: str,
121119
*,
@@ -135,7 +133,7 @@ async def get(
135133
extra_query: Query | None = None,
136134
extra_body: Body | None = None,
137135
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
138-
) -> LogGetResponse:
136+
) -> AsyncPaginator[LogListResponse, AsyncV4PagePaginationArray[LogListResponse]]:
139137
"""
140138
List Gateway Logs
141139
@@ -154,14 +152,15 @@ async def get(
154152
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
155153
if not id:
156154
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
157-
return await self._get(
155+
return self._get_api_list(
158156
f"/accounts/{account_id}/ai-gateway/gateways/{id}/logs",
157+
page=AsyncV4PagePaginationArray[LogListResponse],
159158
options=make_request_options(
160159
extra_headers=extra_headers,
161160
extra_query=extra_query,
162161
extra_body=extra_body,
163162
timeout=timeout,
164-
query=await async_maybe_transform(
163+
query=maybe_transform(
165164
{
166165
"cached": cached,
167166
"direction": direction,
@@ -173,45 +172,44 @@ async def get(
173172
"start_date": start_date,
174173
"success": success,
175174
},
176-
log_get_params.LogGetParams,
175+
log_list_params.LogListParams,
177176
),
178-
post_parser=ResultWrapper[LogGetResponse]._unwrapper,
179177
),
180-
cast_to=cast(Type[LogGetResponse], ResultWrapper[LogGetResponse]),
178+
model=LogListResponse,
181179
)
182180

183181

184182
class LogsResourceWithRawResponse:
185183
def __init__(self, logs: LogsResource) -> None:
186184
self._logs = logs
187185

188-
self.get = to_raw_response_wrapper(
189-
logs.get,
186+
self.list = to_raw_response_wrapper(
187+
logs.list,
190188
)
191189

192190

193191
class AsyncLogsResourceWithRawResponse:
194192
def __init__(self, logs: AsyncLogsResource) -> None:
195193
self._logs = logs
196194

197-
self.get = async_to_raw_response_wrapper(
198-
logs.get,
195+
self.list = async_to_raw_response_wrapper(
196+
logs.list,
199197
)
200198

201199

202200
class LogsResourceWithStreamingResponse:
203201
def __init__(self, logs: LogsResource) -> None:
204202
self._logs = logs
205203

206-
self.get = to_streamed_response_wrapper(
207-
logs.get,
204+
self.list = to_streamed_response_wrapper(
205+
logs.list,
208206
)
209207

210208

211209
class AsyncLogsResourceWithStreamingResponse:
212210
def __init__(self, logs: AsyncLogsResource) -> None:
213211
self._logs = logs
214212

215-
self.get = async_to_streamed_response_wrapper(
216-
logs.get,
213+
self.list = async_to_streamed_response_wrapper(
214+
logs.list,
217215
)

src/cloudflare/resources/api_gateway/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@
5656
ConfigurationsResourceWithStreamingResponse,
5757
AsyncConfigurationsResourceWithStreamingResponse,
5858
)
59-
from .schema_validation import (
60-
SchemaValidationResource,
61-
AsyncSchemaValidationResource,
62-
SchemaValidationResourceWithRawResponse,
63-
AsyncSchemaValidationResourceWithRawResponse,
64-
SchemaValidationResourceWithStreamingResponse,
65-
AsyncSchemaValidationResourceWithStreamingResponse,
66-
)
6759

6860
__all__ = [
6961
"ConfigurationsResource",
@@ -102,12 +94,6 @@
10294
"AsyncUserSchemasResourceWithRawResponse",
10395
"UserSchemasResourceWithStreamingResponse",
10496
"AsyncUserSchemasResourceWithStreamingResponse",
105-
"SchemaValidationResource",
106-
"AsyncSchemaValidationResource",
107-
"SchemaValidationResourceWithRawResponse",
108-
"AsyncSchemaValidationResourceWithRawResponse",
109-
"SchemaValidationResourceWithStreamingResponse",
110-
"AsyncSchemaValidationResourceWithStreamingResponse",
11197
"APIGatewayResource",
11298
"AsyncAPIGatewayResource",
11399
"APIGatewayResourceWithRawResponse",

0 commit comments

Comments
 (0)