Client

noclick.Client(
    api_key=None, base_url=None, *, timeout=60.0, max_retries=3, backoff=0.5,
    max_backoff=8.0, headers=None
)

Connection settings for the platform API.

Most code never builds one: the module-level default reads NOCLICK_API_KEY and NOCLICK_API_URL (inside a deployed app without a key, its deployment's own credential, NOCLICK_DEPLOYMENT_TOKEN). Pass client= to any constructor or classmethod to use another account or endpoint. api_key may be a function (sync or async) returning the bearer; it is called on every attempt, so a refreshing token stays current.

Parameters
api_keyApiKey | Nonedefault None
base_urlstr | Nonedefault None
timeoutfloatdefault 60.0
max_retriesintdefault 3
backofffloatdefault 0.5
max_backofffloatdefault 8.0
headersdict[str, str] | Nonedefault None
  • Works as a context manager: with or async with.
Usage

Use a second account by passing its client as client=:

other = noclick.Client(api_key="nk_live_other")
users = noclick.User.list(client=other)

Tune retries and timeouts, and close the connections when the block ends:

with noclick.Client(api_key="nk_live_other", timeout=30, max_retries=5) as other:
    print(noclick.User.list(client=other, limit=10))

When your key comes from a secret store that rotates it, pass the function that reads it:

client = noclick.Client(api_key=read_noclick_key)   # called before every attempt
Attributes
api_key
base_url
timeoutfloat
max_retriesint
backofffloat
max_backofffloat
in_appbool

Whether this client signs in as a deployed app's own code (its deployment's credential), where from_name resolves names in the app's own namespace for the environment it runs in.

for_sessionclassmethod

noclick.Client.for_session(session, *, base_url=None, **kwargs) -> Client

Build a client that authenticates with a user session (a noclick.Session or its nk_sess_... token). Every call acts for the session's user with the session's scopes; the same as noclick.Client(api_key=token).

Parameters
sessionAnyrequired
base_urlstr | Nonedefault None
**kwargsAny
Returns
Client

A client for that session, on the session's own API endpoint unless you pass base_url.

Usage
user = noclick.User.from_id("user_42")
session = user.session(["agents"], ttl_s=3600)
as_ana = noclick.Client.for_session(session)
agents = noclick.Agent.list(client=as_ana)   # Ana's agents and the shared ones, nothing else

aclose

client.aclose() -> None

Close the connection pool opened on the current event loop.

Usage

In a long-lived async app, close the client when you shut down:

await noclick.default_client().aclose()

close

client.close() -> None

Close the pool the blocking API uses.

Usage
client = noclick.Client(api_key="nk_live_other")
users = noclick.User.list(client=client, limit=10)
client.close()

request

client.request(
    method, path, *, json=None, content=None, params=None, user=...,
    idempotency_key=None, timeout=None, binary=False
) -> Any

Send one API call. content sends raw bytes instead of JSON.

Writes carry an Idempotency-Key (generated unless given) that is reused on every retry, so a retried POST can't do the work twice.

Parameters
methodstrrequired
pathstrrequired
jsonAnydefault None
contentbytes | Nonedefault None
paramsdict[str, Any] | Nonedefault None
userAny

Who the call acts for. Defaults to the user set by noclick.as_user (none: the account itself).

(defaults to the current user)
idempotency_keystr | None

Makes a retried create safe: the same key returns the first result. Generated when omitted.

(default None)
timeoutfloat | Nonedefault None
binarybooldefault False
Returns
Any

The response's decoded JSON (None for an empty body), or its raw bytes with binary=True. An error response raises its noclick.Error instead.

Usage

Call an endpoint directly, with the client's key, retries and errors. It is async only:

client = noclick.default_client()
page = await client.request("GET", "/v1/users", params={"limit": 5}, user=None)
print([row["id"] for row in page["data"]])

Pass your own idempotency_key to make a write safe to repeat across processes:

client = noclick.default_client()
user = await client.request(
    "POST", "/v1/users", json={"id": "user_42"}, user=None, idempotency_key="signup-user_42",
)

console_url

client.console_url(section, object_id) -> str | None

Link an object (in operations, agents or users) to its developer console page.

Parameters
sectionstrrequired
object_idstrrequired
Returns
str | None

The page's URL, or None when this client doesn't talk to the hosted API.

Usage

Operations, agents and users have a console_url of their own. Build one from an id you stored:

url = noclick.default_client().console_url("operations", "3b9e0f6a-1c2d-4e5f-8a9b-0c1d2e3f4a5b")

configure

noclick.configure(api_key=None, base_url=None, **kwargs) -> Client

Replace the default client, e.g. noclick.configure(api_key="nk_live_...").

Parameters
api_keyApiKey | Nonedefault None
base_urlstr | Nonedefault None
**kwargsAny
Returns
Client

The new default client, which every call without client= now uses.

Usage
noclick.configure(api_key="nk_live_...", timeout=30, max_retries=5)
users = noclick.User.list(limit=10)   # uses the new default

default_client

noclick.default_client() -> Client

Get the client used when no client= is given, built from the environment on first use.

Returns
Client

The shared default client: the one configure last set, else one built from NOCLICK_API_KEY and NOCLICK_API_URL.

Usage
client = noclick.default_client()
print(client.base_url)   # https://api.noclick.com unless NOCLICK_API_URL says otherwise

__version__

noclick.__version__ = '0.2.0'

This client's version.

DEFAULT_BASE_URL

noclick.DEFAULT_BASE_URL = 'https://api.noclick.com'

The hosted API; NOCLICK_API_URL (or base_url=) points a client elsewhere.

CONSOLE_BASE_URL

noclick.CONSOLE_BASE_URL = 'https://noclick.com/dashboard/developers'

Where the hosted API's objects are shown (only for the hosted base URL).