Skip to content

Commit d072e97

Browse files
committed
feat(api): add usage analytics breakdown endpoint
Stainless-Generated-From: 1419feffe5d572da65476f9a4e1803a151b4d402
1 parent ec709a5 commit d072e97

11 files changed

Lines changed: 927 additions & 1 deletion

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 48
1+
configured_endpoints: 49

api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ Methods:
206206

207207
- <code title="get /v1/accounts/usage">client.accounts.usage.<a href="./src/imagekitio/resources/accounts/usage.py">get</a>(\*\*<a href="src/imagekitio/types/accounts/usage_get_params.py">params</a>) -> <a href="./src/imagekitio/types/accounts/usage_get_response.py">UsageGetResponse</a></code>
208208

209+
## UsageAnalytics
210+
211+
Types:
212+
213+
```python
214+
from imagekitio.types.accounts import RequestBandwidthEntry, UsageAnalyticsResponse
215+
```
216+
217+
Methods:
218+
219+
- <code title="get /v1/accounts/usage-analytics">client.accounts.usage_analytics.<a href="./src/imagekitio/resources/accounts/usage_analytics.py">get</a>(\*\*<a href="src/imagekitio/types/accounts/usage_analytics_get_params.py">params</a>) -> <a href="./src/imagekitio/types/accounts/usage_analytics_response.py">UsageAnalyticsResponse</a></code>
220+
209221
## Origins
210222

211223
Types:

src/imagekitio/resources/accounts/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
URLEndpointsResourceWithStreamingResponse,
3333
AsyncURLEndpointsResourceWithStreamingResponse,
3434
)
35+
from .usage_analytics import (
36+
UsageAnalyticsResource,
37+
AsyncUsageAnalyticsResource,
38+
UsageAnalyticsResourceWithRawResponse,
39+
AsyncUsageAnalyticsResourceWithRawResponse,
40+
UsageAnalyticsResourceWithStreamingResponse,
41+
AsyncUsageAnalyticsResourceWithStreamingResponse,
42+
)
3543

3644
__all__ = [
3745
"UsageResource",
@@ -40,6 +48,12 @@
4048
"AsyncUsageResourceWithRawResponse",
4149
"UsageResourceWithStreamingResponse",
4250
"AsyncUsageResourceWithStreamingResponse",
51+
"UsageAnalyticsResource",
52+
"AsyncUsageAnalyticsResource",
53+
"UsageAnalyticsResourceWithRawResponse",
54+
"AsyncUsageAnalyticsResourceWithRawResponse",
55+
"UsageAnalyticsResourceWithStreamingResponse",
56+
"AsyncUsageAnalyticsResourceWithStreamingResponse",
4357
"OriginsResource",
4458
"AsyncOriginsResource",
4559
"OriginsResourceWithRawResponse",

src/imagekitio/resources/accounts/accounts.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
URLEndpointsResourceWithStreamingResponse,
2929
AsyncURLEndpointsResourceWithStreamingResponse,
3030
)
31+
from .usage_analytics import (
32+
UsageAnalyticsResource,
33+
AsyncUsageAnalyticsResource,
34+
UsageAnalyticsResourceWithRawResponse,
35+
AsyncUsageAnalyticsResourceWithRawResponse,
36+
UsageAnalyticsResourceWithStreamingResponse,
37+
AsyncUsageAnalyticsResourceWithStreamingResponse,
38+
)
3139

3240
__all__ = ["AccountsResource", "AsyncAccountsResource"]
3341

@@ -37,6 +45,10 @@ class AccountsResource(SyncAPIResource):
3745
def usage(self) -> UsageResource:
3846
return UsageResource(self._client)
3947

48+
@cached_property
49+
def usage_analytics(self) -> UsageAnalyticsResource:
50+
return UsageAnalyticsResource(self._client)
51+
4052
@cached_property
4153
def origins(self) -> OriginsResource:
4254
return OriginsResource(self._client)
@@ -70,6 +82,10 @@ class AsyncAccountsResource(AsyncAPIResource):
7082
def usage(self) -> AsyncUsageResource:
7183
return AsyncUsageResource(self._client)
7284

85+
@cached_property
86+
def usage_analytics(self) -> AsyncUsageAnalyticsResource:
87+
return AsyncUsageAnalyticsResource(self._client)
88+
7389
@cached_property
7490
def origins(self) -> AsyncOriginsResource:
7591
return AsyncOriginsResource(self._client)
@@ -106,6 +122,10 @@ def __init__(self, accounts: AccountsResource) -> None:
106122
def usage(self) -> UsageResourceWithRawResponse:
107123
return UsageResourceWithRawResponse(self._accounts.usage)
108124

125+
@cached_property
126+
def usage_analytics(self) -> UsageAnalyticsResourceWithRawResponse:
127+
return UsageAnalyticsResourceWithRawResponse(self._accounts.usage_analytics)
128+
109129
@cached_property
110130
def origins(self) -> OriginsResourceWithRawResponse:
111131
return OriginsResourceWithRawResponse(self._accounts.origins)
@@ -123,6 +143,10 @@ def __init__(self, accounts: AsyncAccountsResource) -> None:
123143
def usage(self) -> AsyncUsageResourceWithRawResponse:
124144
return AsyncUsageResourceWithRawResponse(self._accounts.usage)
125145

146+
@cached_property
147+
def usage_analytics(self) -> AsyncUsageAnalyticsResourceWithRawResponse:
148+
return AsyncUsageAnalyticsResourceWithRawResponse(self._accounts.usage_analytics)
149+
126150
@cached_property
127151
def origins(self) -> AsyncOriginsResourceWithRawResponse:
128152
return AsyncOriginsResourceWithRawResponse(self._accounts.origins)
@@ -140,6 +164,10 @@ def __init__(self, accounts: AccountsResource) -> None:
140164
def usage(self) -> UsageResourceWithStreamingResponse:
141165
return UsageResourceWithStreamingResponse(self._accounts.usage)
142166

167+
@cached_property
168+
def usage_analytics(self) -> UsageAnalyticsResourceWithStreamingResponse:
169+
return UsageAnalyticsResourceWithStreamingResponse(self._accounts.usage_analytics)
170+
143171
@cached_property
144172
def origins(self) -> OriginsResourceWithStreamingResponse:
145173
return OriginsResourceWithStreamingResponse(self._accounts.origins)
@@ -157,6 +185,10 @@ def __init__(self, accounts: AsyncAccountsResource) -> None:
157185
def usage(self) -> AsyncUsageResourceWithStreamingResponse:
158186
return AsyncUsageResourceWithStreamingResponse(self._accounts.usage)
159187

188+
@cached_property
189+
def usage_analytics(self) -> AsyncUsageAnalyticsResourceWithStreamingResponse:
190+
return AsyncUsageAnalyticsResourceWithStreamingResponse(self._accounts.usage_analytics)
191+
160192
@cached_property
161193
def origins(self) -> AsyncOriginsResourceWithStreamingResponse:
162194
return AsyncOriginsResourceWithStreamingResponse(self._accounts.origins)

src/imagekitio/resources/accounts/usage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ def get(
6363
other words, the data covers the period starting from the specified start date
6464
up to, but not including, the end date.
6565
66+
For an agency account, the returned usage is aggregated across the agency and
67+
all of its child accounts that are billed to it.
68+
69+
The response is cached for 6 hours per account, date range and requested
70+
metrics.
71+
6672
Args:
6773
end_date: Specify a `endDate` in `YYYY-MM-DD` format. It should be after the `startDate`.
6874
The difference between `startDate` and `endDate` should be less than 90 days.
@@ -136,6 +142,12 @@ async def get(
136142
other words, the data covers the period starting from the specified start date
137143
up to, but not including, the end date.
138144
145+
For an agency account, the returned usage is aggregated across the agency and
146+
all of its child accounts that are billed to it.
147+
148+
The response is cached for 6 hours per account, date range and requested
149+
metrics.
150+
139151
Args:
140152
end_date: Specify a `endDate` in `YYYY-MM-DD` format. It should be after the `startDate`.
141153
The difference between `startDate` and `endDate` should be less than 90 days.
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing import Union
6+
from datetime import date
7+
8+
import httpx
9+
10+
from ..._types import Body, Query, Headers, NotGiven, not_given
11+
from ..._utils import maybe_transform, async_maybe_transform
12+
from ..._compat import cached_property
13+
from ..._resource import SyncAPIResource, AsyncAPIResource
14+
from ..._response import (
15+
to_raw_response_wrapper,
16+
to_streamed_response_wrapper,
17+
async_to_raw_response_wrapper,
18+
async_to_streamed_response_wrapper,
19+
)
20+
from ..._base_client import make_request_options
21+
from ...types.accounts import usage_analytics_get_params
22+
from ...types.accounts.usage_analytics_response import UsageAnalyticsResponse
23+
24+
__all__ = ["UsageAnalyticsResource", "AsyncUsageAnalyticsResource"]
25+
26+
27+
class UsageAnalyticsResource(SyncAPIResource):
28+
@cached_property
29+
def with_raw_response(self) -> UsageAnalyticsResourceWithRawResponse:
30+
"""
31+
This property can be used as a prefix for any HTTP method call to return
32+
the raw response object instead of the parsed content.
33+
34+
For more information, see https://www.github.com/imagekit-developer/imagekit-python#accessing-raw-response-data-eg-headers
35+
"""
36+
return UsageAnalyticsResourceWithRawResponse(self)
37+
38+
@cached_property
39+
def with_streaming_response(self) -> UsageAnalyticsResourceWithStreamingResponse:
40+
"""
41+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
42+
43+
For more information, see https://www.github.com/imagekit-developer/imagekit-python#with_streaming_response
44+
"""
45+
return UsageAnalyticsResourceWithStreamingResponse(self)
46+
47+
def get(
48+
self,
49+
*,
50+
end_date: Union[str, date],
51+
start_date: Union[str, date],
52+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
53+
# The extra values given here take precedence over values defined on the client or passed to this method.
54+
extra_headers: Headers | None = None,
55+
extra_query: Query | None = None,
56+
extra_body: Body | None = None,
57+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
58+
) -> UsageAnalyticsResponse:
59+
"""
60+
**Note:** This API is currently in beta.
61+
62+
Get the account analytics data between two dates. The response covers the period
63+
from the start date to the end date, both dates inclusive. Both dates are
64+
interpreted as UTC calendar days.
65+
66+
The returned data is scoped to the requesting account only. Unlike
67+
`/v1/accounts/usage`, an agency account's analytics are not aggregated across
68+
its child accounts.
69+
70+
The response is cached for 5 minutes per account and date range. Use
71+
`generatedAt` to check how fresh the returned data is.
72+
73+
Args:
74+
end_date: Specify an `endDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day.
75+
It should be after the `startDate`. The difference between `startDate` and
76+
`endDate` should be less than 90 days.
77+
78+
start_date: Specify a `startDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day.
79+
It should be before the `endDate`. The difference between `startDate` and
80+
`endDate` should be less than 90 days.
81+
82+
extra_headers: Send extra headers
83+
84+
extra_query: Add additional query parameters to the request
85+
86+
extra_body: Add additional JSON properties to the request
87+
88+
timeout: Override the client-level default timeout for this request, in seconds
89+
"""
90+
return self._get(
91+
"/v1/accounts/usage-analytics",
92+
options=make_request_options(
93+
extra_headers=extra_headers,
94+
extra_query=extra_query,
95+
extra_body=extra_body,
96+
timeout=timeout,
97+
query=maybe_transform(
98+
{
99+
"end_date": end_date,
100+
"start_date": start_date,
101+
},
102+
usage_analytics_get_params.UsageAnalyticsGetParams,
103+
),
104+
),
105+
cast_to=UsageAnalyticsResponse,
106+
)
107+
108+
109+
class AsyncUsageAnalyticsResource(AsyncAPIResource):
110+
@cached_property
111+
def with_raw_response(self) -> AsyncUsageAnalyticsResourceWithRawResponse:
112+
"""
113+
This property can be used as a prefix for any HTTP method call to return
114+
the raw response object instead of the parsed content.
115+
116+
For more information, see https://www.github.com/imagekit-developer/imagekit-python#accessing-raw-response-data-eg-headers
117+
"""
118+
return AsyncUsageAnalyticsResourceWithRawResponse(self)
119+
120+
@cached_property
121+
def with_streaming_response(self) -> AsyncUsageAnalyticsResourceWithStreamingResponse:
122+
"""
123+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
124+
125+
For more information, see https://www.github.com/imagekit-developer/imagekit-python#with_streaming_response
126+
"""
127+
return AsyncUsageAnalyticsResourceWithStreamingResponse(self)
128+
129+
async def get(
130+
self,
131+
*,
132+
end_date: Union[str, date],
133+
start_date: Union[str, date],
134+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
135+
# The extra values given here take precedence over values defined on the client or passed to this method.
136+
extra_headers: Headers | None = None,
137+
extra_query: Query | None = None,
138+
extra_body: Body | None = None,
139+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
140+
) -> UsageAnalyticsResponse:
141+
"""
142+
**Note:** This API is currently in beta.
143+
144+
Get the account analytics data between two dates. The response covers the period
145+
from the start date to the end date, both dates inclusive. Both dates are
146+
interpreted as UTC calendar days.
147+
148+
The returned data is scoped to the requesting account only. Unlike
149+
`/v1/accounts/usage`, an agency account's analytics are not aggregated across
150+
its child accounts.
151+
152+
The response is cached for 5 minutes per account and date range. Use
153+
`generatedAt` to check how fresh the returned data is.
154+
155+
Args:
156+
end_date: Specify an `endDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day.
157+
It should be after the `startDate`. The difference between `startDate` and
158+
`endDate` should be less than 90 days.
159+
160+
start_date: Specify a `startDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day.
161+
It should be before the `endDate`. The difference between `startDate` and
162+
`endDate` should be less than 90 days.
163+
164+
extra_headers: Send extra headers
165+
166+
extra_query: Add additional query parameters to the request
167+
168+
extra_body: Add additional JSON properties to the request
169+
170+
timeout: Override the client-level default timeout for this request, in seconds
171+
"""
172+
return await self._get(
173+
"/v1/accounts/usage-analytics",
174+
options=make_request_options(
175+
extra_headers=extra_headers,
176+
extra_query=extra_query,
177+
extra_body=extra_body,
178+
timeout=timeout,
179+
query=await async_maybe_transform(
180+
{
181+
"end_date": end_date,
182+
"start_date": start_date,
183+
},
184+
usage_analytics_get_params.UsageAnalyticsGetParams,
185+
),
186+
),
187+
cast_to=UsageAnalyticsResponse,
188+
)
189+
190+
191+
class UsageAnalyticsResourceWithRawResponse:
192+
def __init__(self, usage_analytics: UsageAnalyticsResource) -> None:
193+
self._usage_analytics = usage_analytics
194+
195+
self.get = to_raw_response_wrapper(
196+
usage_analytics.get,
197+
)
198+
199+
200+
class AsyncUsageAnalyticsResourceWithRawResponse:
201+
def __init__(self, usage_analytics: AsyncUsageAnalyticsResource) -> None:
202+
self._usage_analytics = usage_analytics
203+
204+
self.get = async_to_raw_response_wrapper(
205+
usage_analytics.get,
206+
)
207+
208+
209+
class UsageAnalyticsResourceWithStreamingResponse:
210+
def __init__(self, usage_analytics: UsageAnalyticsResource) -> None:
211+
self._usage_analytics = usage_analytics
212+
213+
self.get = to_streamed_response_wrapper(
214+
usage_analytics.get,
215+
)
216+
217+
218+
class AsyncUsageAnalyticsResourceWithStreamingResponse:
219+
def __init__(self, usage_analytics: AsyncUsageAnalyticsResource) -> None:
220+
self._usage_analytics = usage_analytics
221+
222+
self.get = async_to_streamed_response_wrapper(
223+
usage_analytics.get,
224+
)

src/imagekitio/types/accounts/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from .origin_request_param import OriginRequestParam as OriginRequestParam
1111
from .origin_update_params import OriginUpdateParams as OriginUpdateParams
1212
from .url_endpoint_response import URLEndpointResponse as URLEndpointResponse
13+
from .request_bandwidth_entry import RequestBandwidthEntry as RequestBandwidthEntry
14+
from .usage_analytics_response import UsageAnalyticsResponse as UsageAnalyticsResponse
1315
from .url_endpoint_create_params import URLEndpointCreateParams as URLEndpointCreateParams
1416
from .url_endpoint_list_response import URLEndpointListResponse as URLEndpointListResponse
1517
from .url_endpoint_update_params import URLEndpointUpdateParams as URLEndpointUpdateParams
18+
from .usage_analytics_get_params import UsageAnalyticsGetParams as UsageAnalyticsGetParams

0 commit comments

Comments
 (0)