Dict

Dicts: a key-value store for small state that code and agents share.

seen = noclick.Dict.from_name("processed-orders", create_if_missing=True)
if "o_1841" not in seen:
    seen["o_1841"] = {"status": "refunded"}
print(seen.increment("refunds-today"))

Keys are strings and values are JSON (a dict, list, string, number, bool or None), never pickled, so a value your Python code writes reads the same from TypeScript, an agent or the console. A dict works like Python's own: d[key], d[key] = value, key in d, del d[key], len(d) and iterating its keys, plus expiry (ttl_s), locks (put_if_absent) and atomic counters (increment). Each of those reads or writes the API, so the .aio forms of get, put and pop are how async code does the same.

class Dict

A key-value store: string keys, JSON values, optional expiry per key. get, put, has, remove and size are what Python writes as d[key], d[key] = value, key in d, del d[key] and len(d); each is a call to the API, so two processes see each other's writes at once. Dict.fromName("processed-orders", { createIfMissing: true }) is lazy. There's no Dict.get(id), since get reads a key: Dict.fromId(id).hydrate() loads one.

Attributes
idstring
namestring
keyCountnumber | null

How many keys it holds, as of the last load; size() reads it fresh.

sizeBytesnumber | null

The size of its keys and values as JSON.

usedByUsedBy[]

The apps that bind it.

regionRegionName | null

The region it keeps its data in, fixed when it was created.

userIdstring | null
createdAtDate | null
consoleUrlstring | null

This dict in the developer console (null off the hosted API).

createstatic

static create(
  name: string,
  options?: CallOptions & PlacementOptions,
): Promise<Dict>

Create a dict, unique by name per user (a taken name throws Conflict with existingId). region keeps its keys there for good: us-east only for now (another, or a default elsewhere, throws InvalidRequest).

Parameters
namestringrequired
options.regionRegionName

Where it runs or keeps its data (regions()); omitted, your account's default region.

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The new dict, empty.

fromNamestatic

static fromName(
  name: string,
  options?: CallOptions & PlacementOptions & { createIfMissing?: boolean },
): Dict

A lazy reference to the dict called name; with createIfMissing it's created on first use.

Parameters
namestringrequired
options.createIfMissingboolean
options.regionRegionName

Where it runs or keeps its data (regions()); omitted, your account's default region.

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

A dict that loads (or is created) on first use. Nothing is sent yet.

fromIdstatic

static fromId(dictId: string, options?: CallOptions): Dict

A lazy reference by id; await Dict.fromId(id).hydrate() loads it now.

Parameters
dictIdstringrequired
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
Returns

A dict that loads the first time you use it. Nothing is sent yet.

liststatic

static list(options?: ReadOptions & { limit?: number }): Promise<Dict[]>

The current user's dicts (or those userFilter covers), newest first.

Parameters
options.limitnumber

Return at most this many.

options.userFilterUserFilter

Which users the read covers (user_id query), instead of acting as one (user).

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

Every matching dict, newest first, fetched page by page.

listPagestatic

static listPage(options?: ReadOptions & PageOptions): Promise<Page<Dict>>

One page of dicts; pass nextCursor back as cursor.

Parameters
options.cursorstring | null

The next_cursor of the page before; omit it for the first page.

options.limitnumber

Return at most this many.

options.userFilterUserFilter

Which users the read covers (user_id query), instead of acting as one (user).

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

A page whose data holds the dicts and whose next_cursor is None on the last page.

get

get(key: string): Promise<T | undefined>

A key's value, or undefined when it's missing or expired (a stored null reads as null).

Parameters
keystringrequired
Returns

The value as the JSON it was stored as, or default.

keys

keys(options?: DictListOptions & { limit?: number }): Promise<string[]>

The keys in order (or those starting with prefix), fetched page by page.

Parameters
options.limitnumber

Return at most this many.

options.prefixstring
Returns

Every matching key (or the first limit), fetched page by page.

items

items(options?: DictListOptions & { limit?: number }): Promise<DictItem[]>

The keys and their values, in key order (or those starting with prefix), with each key's expiry.

Parameters
options.limitnumber

Return at most this many.

options.prefixstring
Returns

A DictItem per key (or for the first limit): it unpacks as key, value and also carries expires_at, updated_at and size_bytes.

itemsPage

itemsPage(options?: DictListOptions & PageOptions): Promise<Page<DictItem>>

One page of items in key order; pass nextCursor back as cursor.

Parameters
options.cursorstring | null

The next_cursor of the page before; omit it for the first page.

options.limitnumber

Return at most this many.

options.prefixstring
Returns

A page whose data holds DictItems and whose next_cursor is None on the last page.

put

put(key: string, value: unknown, options?: DictWriteOptions): Promise<void>

Write a key. With ttlS it expires then; without, it stays until removed (and loses any expiry).

Parameters
keystringrequired
valueunknownrequired
options.ttlSnumber

putIfAbsent

putIfAbsent(
  key: string,
  value: unknown,
  options?: DictWriteOptions,
): Promise<boolean>

Write a key only if it isn't there, atomically: of any number of callers racing, exactly one wins. A lock (with ttlS, so a crashed holder's lock frees itself) or a run-once check. Whether this call wrote it.

Parameters
keystringrequired
valueunknownrequired
options.ttlSnumber
Returns

True if this call wrote it, False if the key was already there.

increment

increment(
  key: string,
  options?: DictWriteOptions & { by?: number },
): Promise<number>

Add by (default 1, may be negative) to a counter, atomically; a missing key starts at 0. ttlS sets its expiry only when this call creates it. The value after the increment.

Parameters
keystringrequired
options.ttlSnumber
options.bynumberdefault 1
Returns

The counter's value after this increment.

update

update(
  items: Readonly<Record<string, unknown>> | ReadonlyMap<string, unknown>,
  options?: DictWriteOptions,
): Promise<void>

Write up to 1,000 keys in one call, all or none; ttlS applies to each.

Parameters
itemsReadonly<Record<string, unknown>> | ReadonlyMap<string, unknown>required
options.ttlSnumber

pop

pop(key: string): Promise<T | undefined>

Remove a key and return its value, or undefined if it wasn't there.

Parameters
keystringrequired
Returns

The value the key held, or default.

remove

remove(key: string): Promise<boolean>

Remove a key; whether it was there. (delete() deletes the whole dict.)

Parameters
keystringrequired
Returns

Whether the key was there to remove.

clear

clear(): Promise<Operation>

Remove every key; the dict stays, empty. Its operation's undo() puts back what it removed.

Returns

The clear's operation: undo() puts back every key it removed that nothing has written since.

history

history(key?: string, options?: { limit?: number }): Promise<DictChange[]>

Its writes of the last 30 days, newest first, each with the value it replaced; key keeps one key's.

Parameters
keystring
options.limitnumber

Return at most this many.

Returns

Each change.

restoreChange

restoreChange(change: DictChange | string): Promise<void>

Put the key back as change found it: the value it replaced, or gone, when the change created the key. A value that has expired since throws Conflict.

Parameters
changeDictChange | stringrequired

export

export(): Promise<Operation<ExportBundle>>

Export every key as it stands at one moment, as JSON Lines: one {"key", "value", "expires_at"} per line, in key order. wait() resolves to an ExportBundle: a zip at url holding the file.

Returns

An operation whose wait() gives an ExportBundle: a zip at url holding the file.

delete

delete(): Promise<TrashItem>

Delete the dict and every key in it: it goes to the trash, restorable for 30 days. A dict an app binds throws Conflict. Returns its TrashItem: restore() puts it back, keys and all.

Returns

Its TrashItem: restore() puts it back, keys and all.

hasTypeScript only

has(key: string): Promise<boolean>

Whether the key is there (and hasn't expired).

Parameters
keystringrequired

sizeTypeScript only

size(): Promise<number>

How many keys it holds, read now.

DictItem

interface DictItem

One key of a dict as items() reads it: its value, when it expires (null if it doesn't), when it was last written and the size of its value as JSON.

Attributes
keystring
valueunknown
expiresAtDate | null
updatedAtDate | null
sizeBytesnumber | null
rawJsonObject

The response JSON exactly as the API sent it.

DictChange

interface DictChange

One write to a dict, from its history: op is created (the key was new), changed or deleted, and previous the value it replaced (null for a new key). A key changed again within a minute adds none, so a busy key keeps one a minute.

Attributes
idstring
keystring
op"created" | "changed" | "deleted"
previousunknown
previousExpiresAtDate | null
atDate | null
rawJsonObject

The response JSON exactly as the API sent it.