> ## Documentation Index
> Fetch the complete documentation index at: https://s2.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Paginators

> Use S2 SDK paginators to iterate through list results without managing cursors.

List operations like [`listBasins`](/api/basins/list), [`listStreams`](/api/streams/list), and [`listAccessTokens`](/api/access-tokens/list) return paginated results.

SDKs provide automatic pagination helpers that handle async fetching of subsequent pages transparently.

## Usage

Instead of manually handling `hasMore` and `startAfter` cursor parameters, use the paginator variants which return an iterable that automatically fetches pages as needed:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    // Iterate through all streams with automatic pagination
    for await (const stream of basin.streams.listAll()) {
    	console.log(stream.name);
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # Iterate through all streams with automatic pagination
    async for stream in basin.list_all_streams():
        print(stream.name)
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // Iterate through all streams with automatic pagination
    iter := basin.Streams.Iter(ctx, nil)
    for iter.Next() {
    	stream := iter.Value()
    	fmt.Println(stream.Name)
    }
    if err := iter.Err(); err != nil {
    	log.Fatal(err)
    }
    ```
  </Tab>

  <Tab title="Rust">
    ```rust theme={null}
    // Iterate through all streams with automatic pagination
    let mut stream = basin.list_all_streams(ListAllStreamsInput::new());
    while let Some(info) = stream.next().await {
        let info = info?;
        println!("{}", info.name);
    }
    ```
  </Tab>
</Tabs>

## Filtering

Paginators accept the same filter options as their single-page list analogs:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    // List streams with a prefix filter
    for await (const stream of basin.streams.listAll({ prefix: "events/" })) {
    	console.log(stream.name);
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # List streams with a prefix filter
    async for stream in basin.list_all_streams(prefix="events/"):
        print(stream.name)
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // List streams with a prefix filter
    iter = basin.Streams.Iter(ctx, &s2.ListStreamsArgs{Prefix: "events/"})
    for iter.Next() {
    	fmt.Println(iter.Value().Name)
    }
    if err := iter.Err(); err != nil {
    	log.Fatal(err)
    }
    ```
  </Tab>

  <Tab title="Rust">
    ```rust theme={null}
    // List streams with a prefix filter
    let input = ListAllStreamsInput::new().with_prefix("events/".parse()?);
    let mut stream = basin.list_all_streams(input);
    while let Some(info) = stream.next().await {
        println!("{}", info?.name);
    }
    ```
  </Tab>
</Tabs>

## Deleted Resources

Paginators automatically filter out resources that are pending deletion. This is useful because delete operations mark resources for deletion, but actual garbage collection happens asynchronously.

To include deleted resources in the results:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    // Include streams that are being deleted
    for await (const stream of basin.streams.listAll({ includeDeleted: true })) {
    	console.log(stream.name, stream.deletedAt);
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # Include streams that are being deleted
    async for stream in basin.list_all_streams(include_deleted=True):
        print(stream.name, stream.deleted_at)
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // Include streams that are being deleted
    iter = basin.Streams.Iter(ctx, &s2.ListStreamsArgs{IncludeDeleted: true})
    for iter.Next() {
    	stream := iter.Value()
    	fmt.Println(stream.Name, stream.DeletedAt)
    }
    if err := iter.Err(); err != nil {
    	log.Fatal(err)
    }
    ```
  </Tab>

  <Tab title="Rust">
    ```rust theme={null}
    // Include streams that are being deleted
    let input = ListAllStreamsInput::new().with_include_deleted(true);
    let mut stream = basin.list_all_streams(input);
    while let Some(info) = stream.next().await {
        let info = info?;
        println!("{} {:?}", info.name, info.deleted_at);
    }
    ```
  </Tab>
</Tabs>
