Skip to content
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

feat(api): update via SDK Studio #233

Merged
merged 1 commit into from
Apr 9, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,12 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
- Additional [advanced](https://www.python-httpx.org/advanced/#client-instances) functionality

```python
import httpx
from cloudflare import Cloudflare
from cloudflare import Cloudflare, DefaultHttpxClient

client = Cloudflare(
# Or use the `CLOUDFLARE_BASE_URL` env var
base_url="http://my.test.server.example.com:8083",
http_client=httpx.Client(
http_client=DefaultHttpxClient(
proxies="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
Expand Down
1,117 changes: 514 additions & 603 deletions api.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/cloudflare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
UnprocessableEntityError,
APIResponseValidationError,
)
from ._base_client import DefaultHttpxClient, DefaultAsyncHttpxClient
from ._utils._logs import setup_logging as _setup_logging

__all__ = [
Expand Down Expand Up @@ -72,6 +73,8 @@
"DEFAULT_TIMEOUT",
"DEFAULT_MAX_RETRIES",
"DEFAULT_CONNECTION_LIMITS",
"DefaultHttpxClient",
"DefaultAsyncHttpxClient",
]

_setup_logging()
Expand Down
44 changes: 42 additions & 2 deletions src/cloudflare/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,27 @@ def _idempotency_key(self) -> str:
return f"stainless-python-retry-{uuid.uuid4()}"


class SyncHttpxClientWrapper(httpx.Client):
class _DefaultHttpxClient(httpx.Client):
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:
DefaultHttpxClient = httpx.Client
"""An alias to `httpx.Client` that provides the same defaults that this SDK
uses internally.

This is useful because overriding the `http_client` with your own instance of
`httpx.Client` will result in httpx's defaults being used, not ours.
"""
else:
DefaultHttpxClient = _DefaultHttpxClient


class SyncHttpxClientWrapper(DefaultHttpxClient):
def __del__(self) -> None:
try:
self.close()
Expand Down Expand Up @@ -1248,7 +1268,27 @@ def get_api_list(
return self._request_api_list(model, page, opts)


class AsyncHttpxClientWrapper(httpx.AsyncClient):
class _DefaultAsyncHttpxClient(httpx.AsyncClient):
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
uses internally.

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.
"""
else:
DefaultAsyncHttpxClient = _DefaultAsyncHttpxClient


class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
def __del__(self) -> None:
try:
# TODO(someday): support non asyncio runtimes here
Expand Down
40 changes: 22 additions & 18 deletions src/cloudflare/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Cloudflare(SyncAPIClient):
origin_ca_certificates: resources.OriginCACertificates
ips: resources.IPs
memberships: resources.Memberships
user: resources.UserResource
user: resources.User
zones: resources.Zones
load_balancers: resources.LoadBalancers
cache: resources.Cache
Expand Down Expand Up @@ -108,7 +108,7 @@ class Cloudflare(SyncAPIClient):
storage: resources.Storage
stream: resources.Stream
alerting: resources.Alerting
d1: resources.D1
d1: resources.D1Resource
r2: resources.R2
warp_connector: resources.WARPConnector
workers_for_platforms: resources.WorkersForPlatforms
Expand Down Expand Up @@ -148,7 +148,9 @@ def __init__(
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
# Configure a custom httpx client. See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
# Configure a custom httpx client.
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
http_client: httpx.Client | None = None,
# Enable or disable schema validation for data returned by the API.
# When enabled an error APIResponseValidationError is raised
Expand Down Expand Up @@ -204,7 +206,7 @@ def __init__(
self.origin_ca_certificates = resources.OriginCACertificates(self)
self.ips = resources.IPs(self)
self.memberships = resources.Memberships(self)
self.user = resources.UserResource(self)
self.user = resources.User(self)
self.zones = resources.Zones(self)
self.load_balancers = resources.LoadBalancers(self)
self.cache = resources.Cache(self)
Expand Down Expand Up @@ -261,7 +263,7 @@ def __init__(
self.storage = resources.Storage(self)
self.stream = resources.Stream(self)
self.alerting = resources.Alerting(self)
self.d1 = resources.D1(self)
self.d1 = resources.D1Resource(self)
self.r2 = resources.R2(self)
self.warp_connector = resources.WARPConnector(self)
self.workers_for_platforms = resources.WorkersForPlatforms(self)
Expand Down Expand Up @@ -462,7 +464,7 @@ class AsyncCloudflare(AsyncAPIClient):
origin_ca_certificates: resources.AsyncOriginCACertificates
ips: resources.AsyncIPs
memberships: resources.AsyncMemberships
user: resources.AsyncUserResource
user: resources.AsyncUser
zones: resources.AsyncZones
load_balancers: resources.AsyncLoadBalancers
cache: resources.AsyncCache
Expand Down Expand Up @@ -519,7 +521,7 @@ class AsyncCloudflare(AsyncAPIClient):
storage: resources.AsyncStorage
stream: resources.AsyncStream
alerting: resources.AsyncAlerting
d1: resources.AsyncD1
d1: resources.AsyncD1Resource
r2: resources.AsyncR2
warp_connector: resources.AsyncWARPConnector
workers_for_platforms: resources.AsyncWorkersForPlatforms
Expand Down Expand Up @@ -559,7 +561,9 @@ def __init__(
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
# Configure a custom httpx client. See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
# Configure a custom httpx client.
# We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
http_client: httpx.AsyncClient | None = None,
# Enable or disable schema validation for data returned by the API.
# When enabled an error APIResponseValidationError is raised
Expand Down Expand Up @@ -615,7 +619,7 @@ def __init__(
self.origin_ca_certificates = resources.AsyncOriginCACertificates(self)
self.ips = resources.AsyncIPs(self)
self.memberships = resources.AsyncMemberships(self)
self.user = resources.AsyncUserResource(self)
self.user = resources.AsyncUser(self)
self.zones = resources.AsyncZones(self)
self.load_balancers = resources.AsyncLoadBalancers(self)
self.cache = resources.AsyncCache(self)
Expand Down Expand Up @@ -672,7 +676,7 @@ def __init__(
self.storage = resources.AsyncStorage(self)
self.stream = resources.AsyncStream(self)
self.alerting = resources.AsyncAlerting(self)
self.d1 = resources.AsyncD1(self)
self.d1 = resources.AsyncD1Resource(self)
self.r2 = resources.AsyncR2(self)
self.warp_connector = resources.AsyncWARPConnector(self)
self.workers_for_platforms = resources.AsyncWorkersForPlatforms(self)
Expand Down Expand Up @@ -874,7 +878,7 @@ def __init__(self, client: Cloudflare) -> None:
self.origin_ca_certificates = resources.OriginCACertificatesWithRawResponse(client.origin_ca_certificates)
self.ips = resources.IPsWithRawResponse(client.ips)
self.memberships = resources.MembershipsWithRawResponse(client.memberships)
self.user = resources.UserResourceWithRawResponse(client.user)
self.user = resources.UserWithRawResponse(client.user)
self.zones = resources.ZonesWithRawResponse(client.zones)
self.load_balancers = resources.LoadBalancersWithRawResponse(client.load_balancers)
self.cache = resources.CacheWithRawResponse(client.cache)
Expand Down Expand Up @@ -931,7 +935,7 @@ def __init__(self, client: Cloudflare) -> None:
self.storage = resources.StorageWithRawResponse(client.storage)
self.stream = resources.StreamWithRawResponse(client.stream)
self.alerting = resources.AlertingWithRawResponse(client.alerting)
self.d1 = resources.D1WithRawResponse(client.d1)
self.d1 = resources.D1ResourceWithRawResponse(client.d1)
self.r2 = resources.R2WithRawResponse(client.r2)
self.warp_connector = resources.WARPConnectorWithRawResponse(client.warp_connector)
self.workers_for_platforms = resources.WorkersForPlatformsWithRawResponse(client.workers_for_platforms)
Expand Down Expand Up @@ -960,7 +964,7 @@ def __init__(self, client: AsyncCloudflare) -> None:
self.origin_ca_certificates = resources.AsyncOriginCACertificatesWithRawResponse(client.origin_ca_certificates)
self.ips = resources.AsyncIPsWithRawResponse(client.ips)
self.memberships = resources.AsyncMembershipsWithRawResponse(client.memberships)
self.user = resources.AsyncUserResourceWithRawResponse(client.user)
self.user = resources.AsyncUserWithRawResponse(client.user)
self.zones = resources.AsyncZonesWithRawResponse(client.zones)
self.load_balancers = resources.AsyncLoadBalancersWithRawResponse(client.load_balancers)
self.cache = resources.AsyncCacheWithRawResponse(client.cache)
Expand Down Expand Up @@ -1021,7 +1025,7 @@ def __init__(self, client: AsyncCloudflare) -> None:
self.storage = resources.AsyncStorageWithRawResponse(client.storage)
self.stream = resources.AsyncStreamWithRawResponse(client.stream)
self.alerting = resources.AsyncAlertingWithRawResponse(client.alerting)
self.d1 = resources.AsyncD1WithRawResponse(client.d1)
self.d1 = resources.AsyncD1ResourceWithRawResponse(client.d1)
self.r2 = resources.AsyncR2WithRawResponse(client.r2)
self.warp_connector = resources.AsyncWARPConnectorWithRawResponse(client.warp_connector)
self.workers_for_platforms = resources.AsyncWorkersForPlatformsWithRawResponse(client.workers_for_platforms)
Expand Down Expand Up @@ -1050,7 +1054,7 @@ def __init__(self, client: Cloudflare) -> None:
self.origin_ca_certificates = resources.OriginCACertificatesWithStreamingResponse(client.origin_ca_certificates)
self.ips = resources.IPsWithStreamingResponse(client.ips)
self.memberships = resources.MembershipsWithStreamingResponse(client.memberships)
self.user = resources.UserResourceWithStreamingResponse(client.user)
self.user = resources.UserWithStreamingResponse(client.user)
self.zones = resources.ZonesWithStreamingResponse(client.zones)
self.load_balancers = resources.LoadBalancersWithStreamingResponse(client.load_balancers)
self.cache = resources.CacheWithStreamingResponse(client.cache)
Expand Down Expand Up @@ -1111,7 +1115,7 @@ def __init__(self, client: Cloudflare) -> None:
self.storage = resources.StorageWithStreamingResponse(client.storage)
self.stream = resources.StreamWithStreamingResponse(client.stream)
self.alerting = resources.AlertingWithStreamingResponse(client.alerting)
self.d1 = resources.D1WithStreamingResponse(client.d1)
self.d1 = resources.D1ResourceWithStreamingResponse(client.d1)
self.r2 = resources.R2WithStreamingResponse(client.r2)
self.warp_connector = resources.WARPConnectorWithStreamingResponse(client.warp_connector)
self.workers_for_platforms = resources.WorkersForPlatformsWithStreamingResponse(client.workers_for_platforms)
Expand Down Expand Up @@ -1142,7 +1146,7 @@ def __init__(self, client: AsyncCloudflare) -> None:
)
self.ips = resources.AsyncIPsWithStreamingResponse(client.ips)
self.memberships = resources.AsyncMembershipsWithStreamingResponse(client.memberships)
self.user = resources.AsyncUserResourceWithStreamingResponse(client.user)
self.user = resources.AsyncUserWithStreamingResponse(client.user)
self.zones = resources.AsyncZonesWithStreamingResponse(client.zones)
self.load_balancers = resources.AsyncLoadBalancersWithStreamingResponse(client.load_balancers)
self.cache = resources.AsyncCacheWithStreamingResponse(client.cache)
Expand Down Expand Up @@ -1205,7 +1209,7 @@ def __init__(self, client: AsyncCloudflare) -> None:
self.storage = resources.AsyncStorageWithStreamingResponse(client.storage)
self.stream = resources.AsyncStreamWithStreamingResponse(client.stream)
self.alerting = resources.AsyncAlertingWithStreamingResponse(client.alerting)
self.d1 = resources.AsyncD1WithStreamingResponse(client.d1)
self.d1 = resources.AsyncD1ResourceWithStreamingResponse(client.d1)
self.r2 = resources.AsyncR2WithStreamingResponse(client.r2)
self.warp_connector = resources.AsyncWARPConnectorWithStreamingResponse(client.warp_connector)
self.workers_for_platforms = resources.AsyncWorkersForPlatformsWithStreamingResponse(
Expand Down
48 changes: 24 additions & 24 deletions src/cloudflare/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from .d1 import (
D1,
AsyncD1,
D1WithRawResponse,
AsyncD1WithRawResponse,
D1WithStreamingResponse,
AsyncD1WithStreamingResponse,
D1Resource,
AsyncD1Resource,
D1ResourceWithRawResponse,
AsyncD1ResourceWithRawResponse,
D1ResourceWithStreamingResponse,
AsyncD1ResourceWithStreamingResponse,
)
from .kv import (
KV,
Expand Down Expand Up @@ -81,12 +81,12 @@
AsyncLogsWithStreamingResponse,
)
from .user import (
UserResource,
AsyncUserResource,
UserResourceWithRawResponse,
AsyncUserResourceWithRawResponse,
UserResourceWithStreamingResponse,
AsyncUserResourceWithStreamingResponse,
User,
AsyncUser,
UserWithRawResponse,
AsyncUserWithRawResponse,
UserWithStreamingResponse,
AsyncUserWithStreamingResponse,
)
from .web3 import (
Web3,
Expand Down Expand Up @@ -666,12 +666,12 @@
"AsyncMembershipsWithRawResponse",
"MembershipsWithStreamingResponse",
"AsyncMembershipsWithStreamingResponse",
"UserResource",
"AsyncUserResource",
"UserResourceWithRawResponse",
"AsyncUserResourceWithRawResponse",
"UserResourceWithStreamingResponse",
"AsyncUserResourceWithStreamingResponse",
"User",
"AsyncUser",
"UserWithRawResponse",
"AsyncUserWithRawResponse",
"UserWithStreamingResponse",
"AsyncUserWithStreamingResponse",
"Zones",
"AsyncZones",
"ZonesWithRawResponse",
Expand Down Expand Up @@ -1008,12 +1008,12 @@
"AsyncAlertingWithRawResponse",
"AlertingWithStreamingResponse",
"AsyncAlertingWithStreamingResponse",
"D1",
"AsyncD1",
"D1WithRawResponse",
"AsyncD1WithRawResponse",
"D1WithStreamingResponse",
"AsyncD1WithStreamingResponse",
"D1Resource",
"AsyncD1Resource",
"D1ResourceWithRawResponse",
"AsyncD1ResourceWithRawResponse",
"D1ResourceWithStreamingResponse",
"AsyncD1ResourceWithStreamingResponse",
"R2",
"AsyncR2",
"R2WithRawResponse",
Expand Down
15 changes: 8 additions & 7 deletions src/cloudflare/resources/accounts/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
)
from ...types.accounts import (
Member,
MemberWithCode,
MemberRoleParam,
MemberListResponse,
MemberDeleteResponse,
MemberWithInviteCode,
member_list_params,
member_create_params,
member_delete_params,
Expand Down Expand Up @@ -62,7 +63,7 @@ def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> MemberWithCode:
) -> MemberWithInviteCode:
"""
Add a user to the list of members for this account.

Expand Down Expand Up @@ -96,15 +97,15 @@ def create(
timeout=timeout,
post_parser=ResultWrapper._unwrapper,
),
cast_to=cast(Type[MemberWithCode], ResultWrapper[MemberWithCode]),
cast_to=cast(Type[MemberWithInviteCode], ResultWrapper[MemberWithInviteCode]),
)

def update(
self,
member_id: str,
*,
account_id: object,
roles: Iterable[member_update_params.Role],
roles: Iterable[MemberRoleParam],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down Expand Up @@ -308,7 +309,7 @@ async def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> MemberWithCode:
) -> MemberWithInviteCode:
"""
Add a user to the list of members for this account.

Expand Down Expand Up @@ -342,15 +343,15 @@ async def create(
timeout=timeout,
post_parser=ResultWrapper._unwrapper,
),
cast_to=cast(Type[MemberWithCode], ResultWrapper[MemberWithCode]),
cast_to=cast(Type[MemberWithInviteCode], ResultWrapper[MemberWithInviteCode]),
)

async def update(
self,
member_id: str,
*,
account_id: object,
roles: Iterable[member_update_params.Role],
roles: Iterable[MemberRoleParam],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down
Loading