Skip to content

Commit 2b9c5ca

Browse files
feat(api): api update
1 parent ea2c0ab commit 2b9c5ca

File tree

158 files changed

+1314
-2745
lines changed

Some content is hidden

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

158 files changed

+1314
-2745
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 229
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/increase%2Fincrease-bd464d151612058d8029150b376949b22d5515af23621465c0ce1c1069b91644.yml
33
openapi_spec_hash: e60e1548c523a0ee7c9daa1bd988cbc5
4-
config_hash: eecc5886c26d07c167f37f30ae505a2c
4+
config_hash: ca1425272e17fa23d4466d33492334fa

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ client = Increase(
3434

3535
account = client.accounts.create(
3636
name="New Account!",
37+
entity_id="entity_n8y8tnk2p9339ti393yi",
38+
program_id="program_i2v2os4mwza1oetokh9i",
3739
)
3840
print(account.id)
3941
```
@@ -62,6 +64,8 @@ client = AsyncIncrease(
6264
async def main() -> None:
6365
account = await client.accounts.create(
6466
name="New Account!",
67+
entity_id="entity_n8y8tnk2p9339ti393yi",
68+
program_id="program_i2v2os4mwza1oetokh9i",
6569
)
6670
print(account.id)
6771

@@ -97,6 +101,8 @@ async def main() -> None:
97101
) as client:
98102
account = await client.accounts.create(
99103
name="New Account!",
104+
entity_id="entity_n8y8tnk2p9339ti393yi",
105+
program_id="program_i2v2os4mwza1oetokh9i",
100106
)
101107
print(account.id)
102108

@@ -113,6 +119,69 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
113119

114120
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
115121

122+
## Pagination
123+
124+
List methods in the Increase API are paginated.
125+
126+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
127+
128+
```python
129+
from increase import Increase
130+
131+
client = Increase()
132+
133+
all_accounts = []
134+
# Automatically fetches more pages as needed.
135+
for account in client.accounts.list():
136+
# Do something with account here
137+
all_accounts.append(account)
138+
print(all_accounts)
139+
```
140+
141+
Or, asynchronously:
142+
143+
```python
144+
import asyncio
145+
from increase import AsyncIncrease
146+
147+
client = AsyncIncrease()
148+
149+
150+
async def main() -> None:
151+
all_accounts = []
152+
# Iterate through items across all pages, issuing requests as needed.
153+
async for account in client.accounts.list():
154+
all_accounts.append(account)
155+
print(all_accounts)
156+
157+
158+
asyncio.run(main())
159+
```
160+
161+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
162+
163+
```python
164+
first_page = await client.accounts.list()
165+
if first_page.has_next_page():
166+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
167+
next_page = await first_page.get_next_page()
168+
print(f"number of items we just fetched: {len(next_page.data)}")
169+
170+
# Remove `await` for non-async usage.
171+
```
172+
173+
Or just work directly with the returned data:
174+
175+
```python
176+
first_page = await client.accounts.list()
177+
178+
print(f"next page cursor: {first_page.next_cursor}") # => "next page cursor: ..."
179+
for account in first_page.data:
180+
print(account.id)
181+
182+
# Remove `await` for non-async usage.
183+
```
184+
116185
## Nested params
117186

118187
Nested parameters are dictionaries, typed using `TypedDict`, for example:
@@ -298,6 +367,8 @@ client = Increase(
298367
# Or, configure per-request:
299368
client.with_options(max_retries=5).accounts.create(
300369
name="New Account!",
370+
entity_id="entity_n8y8tnk2p9339ti393yi",
371+
program_id="program_i2v2os4mwza1oetokh9i",
301372
)
302373
```
303374

@@ -323,6 +394,8 @@ client = Increase(
323394
# Override per-request:
324395
client.with_options(timeout=5.0).accounts.create(
325396
name="New Account!",
397+
entity_id="entity_n8y8tnk2p9339ti393yi",
398+
program_id="program_i2v2os4mwza1oetokh9i",
326399
)
327400
```
328401

@@ -366,6 +439,8 @@ from increase import Increase
366439
client = Increase()
367440
response = client.accounts.with_raw_response.create(
368441
name="New Account!",
442+
entity_id="entity_n8y8tnk2p9339ti393yi",
443+
program_id="program_i2v2os4mwza1oetokh9i",
369444
)
370445
print(response.headers.get('X-My-Header'))
371446

@@ -386,6 +461,8 @@ To stream the response body, use `.with_streaming_response` instead, which requi
386461
```python
387462
with client.accounts.with_streaming_response.create(
388463
name="New Account!",
464+
entity_id="entity_n8y8tnk2p9339ti393yi",
465+
program_id="program_i2v2os4mwza1oetokh9i",
389466
) as response:
390467
print(response.headers.get("X-My-Header"))
391468

api.md

Lines changed: 101 additions & 108 deletions
Large diffs are not rendered by default.

src/increase/pagination.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from typing import List, Generic, TypeVar, Optional
44
from typing_extensions import override
55

6-
from pydantic import Field as FieldInfo
7-
86
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
97

108
__all__ = ["SyncPage", "AsyncPage"]
@@ -13,12 +11,15 @@
1311

1412

1513
class SyncPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
16-
data: Optional[object] = FieldInfo(alias=":data", default=None)
17-
next_cursor: Optional[object] = FieldInfo(alias=":next_cursor", default=None)
14+
data: List[_T]
15+
next_cursor: Optional[str] = None
16+
"""A pointer to a place in the list."""
1817

1918
@override
2019
def _get_page_items(self) -> List[_T]:
2120
data = self.data
21+
if not data:
22+
return []
2223
return data
2324

2425
@override
@@ -27,16 +28,19 @@ def next_page_info(self) -> Optional[PageInfo]:
2728
if not next_cursor:
2829
return None
2930

30-
return PageInfo(params={":cursor": next_cursor})
31+
return PageInfo(params={"cursor": next_cursor})
3132

3233

3334
class AsyncPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
34-
data: Optional[object] = FieldInfo(alias=":data", default=None)
35-
next_cursor: Optional[object] = FieldInfo(alias=":next_cursor", default=None)
35+
data: List[_T]
36+
next_cursor: Optional[str] = None
37+
"""A pointer to a place in the list."""
3638

3739
@override
3840
def _get_page_items(self) -> List[_T]:
3941
data = self.data
42+
if not data:
43+
return []
4044
return data
4145

4246
@override
@@ -45,4 +49,4 @@ def next_page_info(self) -> Optional[PageInfo]:
4549
if not next_cursor:
4650
return None
4751

48-
return PageInfo(params={":cursor": next_cursor})
52+
return PageInfo(params={"cursor": next_cursor})

src/increase/resources/account_numbers.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
async_to_raw_response_wrapper,
1818
async_to_streamed_response_wrapper,
1919
)
20-
from .._base_client import make_request_options
20+
from ..pagination import SyncPage, AsyncPage
21+
from .._base_client import AsyncPaginator, make_request_options
2122
from ..types.account_number import AccountNumber
22-
from ..types.account_number_list_response import AccountNumberListResponse
2323

2424
__all__ = ["AccountNumbersResource", "AsyncAccountNumbersResource"]
2525

@@ -222,7 +222,7 @@ def list(
222222
extra_query: Query | None = None,
223223
extra_body: Body | None = None,
224224
timeout: float | httpx.Timeout | None | NotGiven = not_given,
225-
) -> AccountNumberListResponse:
225+
) -> SyncPage[AccountNumber]:
226226
"""
227227
List Account Numbers
228228
@@ -247,8 +247,9 @@ def list(
247247
248248
timeout: Override the client-level default timeout for this request, in seconds
249249
"""
250-
return self._get(
250+
return self._get_api_list(
251251
"/account_numbers",
252+
page=SyncPage[AccountNumber],
252253
options=make_request_options(
253254
extra_headers=extra_headers,
254255
extra_query=extra_query,
@@ -267,7 +268,7 @@ def list(
267268
account_number_list_params.AccountNumberListParams,
268269
),
269270
),
270-
cast_to=AccountNumberListResponse,
271+
model=AccountNumber,
271272
)
272273

273274

@@ -453,7 +454,7 @@ async def update(
453454
cast_to=AccountNumber,
454455
)
455456

456-
async def list(
457+
def list(
457458
self,
458459
*,
459460
account_id: str | Omit = omit,
@@ -469,7 +470,7 @@ async def list(
469470
extra_query: Query | None = None,
470471
extra_body: Body | None = None,
471472
timeout: float | httpx.Timeout | None | NotGiven = not_given,
472-
) -> AccountNumberListResponse:
473+
) -> AsyncPaginator[AccountNumber, AsyncPage[AccountNumber]]:
473474
"""
474475
List Account Numbers
475476
@@ -494,14 +495,15 @@ async def list(
494495
495496
timeout: Override the client-level default timeout for this request, in seconds
496497
"""
497-
return await self._get(
498+
return self._get_api_list(
498499
"/account_numbers",
500+
page=AsyncPage[AccountNumber],
499501
options=make_request_options(
500502
extra_headers=extra_headers,
501503
extra_query=extra_query,
502504
extra_body=extra_body,
503505
timeout=timeout,
504-
query=await async_maybe_transform(
506+
query=maybe_transform(
505507
{
506508
"account_id": account_id,
507509
"ach_debit_status": ach_debit_status,
@@ -514,7 +516,7 @@ async def list(
514516
account_number_list_params.AccountNumberListParams,
515517
),
516518
),
517-
cast_to=AccountNumberListResponse,
519+
model=AccountNumber,
518520
)
519521

520522

src/increase/resources/account_statements.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ..types import account_statement_list_params
88
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
9-
from .._utils import maybe_transform, async_maybe_transform
9+
from .._utils import maybe_transform
1010
from .._compat import cached_property
1111
from .._resource import SyncAPIResource, AsyncAPIResource
1212
from .._response import (
@@ -15,9 +15,9 @@
1515
async_to_raw_response_wrapper,
1616
async_to_streamed_response_wrapper,
1717
)
18-
from .._base_client import make_request_options
18+
from ..pagination import SyncPage, AsyncPage
19+
from .._base_client import AsyncPaginator, make_request_options
1920
from ..types.account_statement import AccountStatement
20-
from ..types.account_statement_list_response import AccountStatementListResponse
2121

2222
__all__ = ["AccountStatementsResource", "AsyncAccountStatementsResource"]
2323

@@ -92,7 +92,7 @@ def list(
9292
extra_query: Query | None = None,
9393
extra_body: Body | None = None,
9494
timeout: float | httpx.Timeout | None | NotGiven = not_given,
95-
) -> AccountStatementListResponse:
95+
) -> SyncPage[AccountStatement]:
9696
"""
9797
List Account Statements
9898
@@ -112,8 +112,9 @@ def list(
112112
113113
timeout: Override the client-level default timeout for this request, in seconds
114114
"""
115-
return self._get(
115+
return self._get_api_list(
116116
"/account_statements",
117+
page=SyncPage[AccountStatement],
117118
options=make_request_options(
118119
extra_headers=extra_headers,
119120
extra_query=extra_query,
@@ -129,7 +130,7 @@ def list(
129130
account_statement_list_params.AccountStatementListParams,
130131
),
131132
),
132-
cast_to=AccountStatementListResponse,
133+
model=AccountStatement,
133134
)
134135

135136

@@ -190,7 +191,7 @@ async def retrieve(
190191
cast_to=AccountStatement,
191192
)
192193

193-
async def list(
194+
def list(
194195
self,
195196
*,
196197
account_id: str | Omit = omit,
@@ -203,7 +204,7 @@ async def list(
203204
extra_query: Query | None = None,
204205
extra_body: Body | None = None,
205206
timeout: float | httpx.Timeout | None | NotGiven = not_given,
206-
) -> AccountStatementListResponse:
207+
) -> AsyncPaginator[AccountStatement, AsyncPage[AccountStatement]]:
207208
"""
208209
List Account Statements
209210
@@ -223,14 +224,15 @@ async def list(
223224
224225
timeout: Override the client-level default timeout for this request, in seconds
225226
"""
226-
return await self._get(
227+
return self._get_api_list(
227228
"/account_statements",
229+
page=AsyncPage[AccountStatement],
228230
options=make_request_options(
229231
extra_headers=extra_headers,
230232
extra_query=extra_query,
231233
extra_body=extra_body,
232234
timeout=timeout,
233-
query=await async_maybe_transform(
235+
query=maybe_transform(
234236
{
235237
"account_id": account_id,
236238
"cursor": cursor,
@@ -240,7 +242,7 @@ async def list(
240242
account_statement_list_params.AccountStatementListParams,
241243
),
242244
),
243-
cast_to=AccountStatementListResponse,
245+
model=AccountStatement,
244246
)
245247

246248

0 commit comments

Comments
 (0)