Skip to content

Commit

Permalink
Merge pull request #1015 from cloudflare/release-please--branches--ma…
Browse files Browse the repository at this point in the history
…in--changes--next

release: 3.0.0
  • Loading branch information
jacobbednarz committed Jun 24, 2024
2 parents 4e01b1c + a997b40 commit 7299d62
Show file tree
Hide file tree
Showing 219 changed files with 3,345 additions and 1,000 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "3.0.0-beta.10"
".": "3.0.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1348
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-49d54760f87326f9200c777f867e4ea579c92a43f481207ae252db9748c9b07b.yml
configured_endpoints: 1353
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-1274668bf5bb40cc6a93aa05b9b1c96050656b905a292bccdb53941f50eaf81e.yml
130 changes: 130 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

76 changes: 46 additions & 30 deletions api.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cloudflare"
version = "3.0.0-beta.10"
version = "3.0.0"
description = "The official Python library for the cloudflare API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
17 changes: 13 additions & 4 deletions src/cloudflare/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
RequestOptions,
ModelBuilderProtocol,
)
from ._utils import is_dict, is_list, is_given, lru_cache, is_mapping
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
from ._compat import model_copy, model_dump
from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
from ._response import (
Expand Down Expand Up @@ -358,6 +358,7 @@ def __init__(
self._custom_query = custom_query or {}
self._strict_response_validation = _strict_response_validation
self._idempotency_header = None
self._platform: Platform | None = None

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

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

def _parse_retry_after_header(self, response_headers: Optional[httpx.Headers] = None) -> float | None:
"""Returns a float of the number of seconds (not milliseconds) to wait after retrying, or None if unspecified.
Expand Down Expand Up @@ -1498,6 +1502,11 @@ async def _request(
stream_cls: type[_AsyncStreamT] | None,
remaining_retries: int | None,
) -> ResponseT | _AsyncStreamT:
if self._platform is None:
# `get_platform` can make blocking IO calls so we
# execute it earlier while we are in an async context
self._platform = await asyncify(get_platform)()

cast_to = self._maybe_override_cast_to(cast_to, options)
await self._prepare_options(options)

Expand Down Expand Up @@ -1921,11 +1930,11 @@ def get_platform() -> Platform:


@lru_cache(maxsize=None)
def platform_headers(version: str) -> Dict[str, str]:
def platform_headers(version: str, *, platform: Platform | None) -> Dict[str, str]:
return {
"X-Stainless-Lang": "python",
"X-Stainless-Package-Version": version,
"X-Stainless-OS": str(get_platform()),
"X-Stainless-OS": str(platform or get_platform()),
"X-Stainless-Arch": str(get_architecture()),
"X-Stainless-Runtime": get_python_runtime(),
"X-Stainless-Runtime-Version": get_python_version(),
Expand Down
1 change: 1 addition & 0 deletions src/cloudflare/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
maybe_transform as maybe_transform,
async_maybe_transform as async_maybe_transform,
)
from ._reflection import function_has_argument as function_has_argument
8 changes: 8 additions & 0 deletions src/cloudflare/_utils/_reflection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import inspect
from typing import Any, Callable


def function_has_argument(func: Callable[..., Any], arg_name: str) -> bool:
"""Returns whether or not the given function has a specific parameter"""
sig = inspect.signature(func)
return arg_name in sig.parameters
19 changes: 18 additions & 1 deletion src/cloudflare/_utils/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import anyio
import anyio.to_thread

from ._reflection import function_has_argument

T_Retval = TypeVar("T_Retval")
T_ParamSpec = ParamSpec("T_ParamSpec")

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

async def wrapper(*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs) -> T_Retval:
partial_f = functools.partial(function, *args, **kwargs)
return await anyio.to_thread.run_sync(partial_f, cancellable=cancellable, limiter=limiter)

# In `v4.1.0` anyio added the `abandon_on_cancel` argument and deprecated the old
# `cancellable` argument, so we need to use the new `abandon_on_cancel` to avoid
# surfacing deprecation warnings.
if function_has_argument(anyio.to_thread.run_sync, "abandon_on_cancel"):
return await anyio.to_thread.run_sync(
partial_f,
abandon_on_cancel=cancellable,
limiter=limiter,
)

return await anyio.to_thread.run_sync(
partial_f,
cancellable=cancellable,
limiter=limiter,
)

return wrapper
2 changes: 1 addition & 1 deletion src/cloudflare/_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__ = "cloudflare"
__version__ = "3.0.0-beta.10" # x-release-please-version
__version__ = "3.0.0" # x-release-please-version
4 changes: 2 additions & 2 deletions src/cloudflare/resources/ai_gateway/ai_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def list(
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> SyncV4PagePaginationArray[AIGatewayListResponse]:
"""
List Gateway's
List Gateways
Args:
id: gateway id
Expand Down Expand Up @@ -457,7 +457,7 @@ def list(
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> AsyncPaginator[AIGatewayListResponse, AsyncV4PagePaginationArray[AIGatewayListResponse]]:
"""
List Gateway's
List Gateways
Args:
id: gateway id
Expand Down
56 changes: 27 additions & 29 deletions src/cloudflare/resources/ai_gateway/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

from __future__ import annotations

from typing import Type, Union, cast
from typing import Union
from datetime import datetime
from typing_extensions import Literal

import httpx

from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ..._utils import (
maybe_transform,
async_maybe_transform,
)
from ..._utils import maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
Expand All @@ -21,12 +18,13 @@
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from ..._wrappers import ResultWrapper
from ...pagination import SyncV4PagePaginationArray, AsyncV4PagePaginationArray
from ..._base_client import (
AsyncPaginator,
make_request_options,
)
from ...types.ai_gateway import log_get_params
from ...types.ai_gateway.log_get_response import LogGetResponse
from ...types.ai_gateway import log_list_params
from ...types.ai_gateway.log_list_response import LogListResponse

__all__ = ["LogsResource", "AsyncLogsResource"]

Expand All @@ -40,7 +38,7 @@ def with_raw_response(self) -> LogsResourceWithRawResponse:
def with_streaming_response(self) -> LogsResourceWithStreamingResponse:
return LogsResourceWithStreamingResponse(self)

def get(
def list(
self,
id: str,
*,
Expand All @@ -60,7 +58,7 @@ def get(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> LogGetResponse:
) -> SyncV4PagePaginationArray[LogListResponse]:
"""
List Gateway Logs
Expand All @@ -79,8 +77,9 @@ def get(
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not id:
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
return self._get(
return self._get_api_list(
f"/accounts/{account_id}/ai-gateway/gateways/{id}/logs",
page=SyncV4PagePaginationArray[LogListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand All @@ -98,11 +97,10 @@ def get(
"start_date": start_date,
"success": success,
},
log_get_params.LogGetParams,
log_list_params.LogListParams,
),
post_parser=ResultWrapper[LogGetResponse]._unwrapper,
),
cast_to=cast(Type[LogGetResponse], ResultWrapper[LogGetResponse]),
model=LogListResponse,
)


Expand All @@ -115,7 +113,7 @@ def with_raw_response(self) -> AsyncLogsResourceWithRawResponse:
def with_streaming_response(self) -> AsyncLogsResourceWithStreamingResponse:
return AsyncLogsResourceWithStreamingResponse(self)

async def get(
def list(
self,
id: str,
*,
Expand All @@ -135,7 +133,7 @@ async def get(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> LogGetResponse:
) -> AsyncPaginator[LogListResponse, AsyncV4PagePaginationArray[LogListResponse]]:
"""
List Gateway Logs
Expand All @@ -154,14 +152,15 @@ async def get(
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not id:
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
return await self._get(
return self._get_api_list(
f"/accounts/{account_id}/ai-gateway/gateways/{id}/logs",
page=AsyncV4PagePaginationArray[LogListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=await async_maybe_transform(
query=maybe_transform(
{
"cached": cached,
"direction": direction,
Expand All @@ -173,45 +172,44 @@ async def get(
"start_date": start_date,
"success": success,
},
log_get_params.LogGetParams,
log_list_params.LogListParams,
),
post_parser=ResultWrapper[LogGetResponse]._unwrapper,
),
cast_to=cast(Type[LogGetResponse], ResultWrapper[LogGetResponse]),
model=LogListResponse,
)


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

self.get = to_raw_response_wrapper(
logs.get,
self.list = to_raw_response_wrapper(
logs.list,
)


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

self.get = async_to_raw_response_wrapper(
logs.get,
self.list = async_to_raw_response_wrapper(
logs.list,
)


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

self.get = to_streamed_response_wrapper(
logs.get,
self.list = to_streamed_response_wrapper(
logs.list,
)


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

self.get = async_to_streamed_response_wrapper(
logs.get,
self.list = async_to_streamed_response_wrapper(
logs.list,
)
14 changes: 0 additions & 14 deletions src/cloudflare/resources/api_gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@
ConfigurationsResourceWithStreamingResponse,
AsyncConfigurationsResourceWithStreamingResponse,
)
from .schema_validation import (
SchemaValidationResource,
AsyncSchemaValidationResource,
SchemaValidationResourceWithRawResponse,
AsyncSchemaValidationResourceWithRawResponse,
SchemaValidationResourceWithStreamingResponse,
AsyncSchemaValidationResourceWithStreamingResponse,
)

__all__ = [
"ConfigurationsResource",
Expand Down Expand Up @@ -102,12 +94,6 @@
"AsyncUserSchemasResourceWithRawResponse",
"UserSchemasResourceWithStreamingResponse",
"AsyncUserSchemasResourceWithStreamingResponse",
"SchemaValidationResource",
"AsyncSchemaValidationResource",
"SchemaValidationResourceWithRawResponse",
"AsyncSchemaValidationResourceWithRawResponse",
"SchemaValidationResourceWithStreamingResponse",
"AsyncSchemaValidationResourceWithStreamingResponse",
"APIGatewayResource",
"AsyncAPIGatewayResource",
"APIGatewayResourceWithRawResponse",
Expand Down
Loading

0 comments on commit 7299d62

Please sign in to comment.