API keys

envless.keys.iterate()

Stream API keys one at a time

def iterate(
    *,
    limit: int | None = None,
    offset: int | None = None,
    search: str | None = None,
    order: str | None = None,
    timeout: float | None = None,
) -> Iterator[KeyResource]

Returns an iterator that yields keys individually and fetches the next page only once the current one is drained. Breaking out of the loop stops the requests, which makes this the cheapest way to resolve a single prefix to a full row.

The generator defaults to the maximum page size of 100 and clamps anything larger, so limit= only ever makes pages smaller. Since a workspace holds at most 100 live keys, one page normally covers everything.

Creating or revoking keys while you iterate changes the set that offsets are counted against, so a key can be skipped or repeated. Collect the ids you care about first, then act on them after the loop has finished.

Example

from envless import envless

for key in envless.keys.iterate():
    if key['prefix'] == 'ev_sk_9fQ2xa':
        print(key['id'], key['scopes'], key['projectIds'])
        break

Parameters

ParameterTypeRequiredDescription
limitintNoPage size per request, capped at 100 and defaulting to 100.
offsetintNoRow the walk starts at, advancing by the number of items each page returns.
searchstrNoCase insensitive substring match against name and prefix.
orderstrNoDefaults to name, which sorts A to Z. Pass asc for oldest first or desc for newest first on createdAt.
timeoutfloatNoSeconds each attempt of this call may take, the response body included, before it raises EnvlessNetworkError with is_timeout set. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

Iterator[KeyResource] yielding one key per step.

Reads the keys collection. list returns one page as a dict with items and pagination, list_all collects every page into a list, and iterate yields one item at a time, fetching the next page only when the loop reaches it. On AsyncEnvless, iterate is an async iterator for async for.

Worth knowing

  • The generator is lazy, so no request is sent until you start consuming it.
  • Yielded rows carry prefix and never secret, so scanning cannot recover a lost credential.

Required scopes

keys:read

Underlying endpoint

GET /keys

Request and response schema, every error code, and a live playground.

In TypeScript

envless.keys.iterate()

The same method in @goenvless/sdk, with the same request, retries and errors.