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.
NoneNone60.030.58.0None- Works as a context manager:
withorasync with.
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| api_key | ||
| base_url | ||
| timeout | float | |
| max_retries | int | |
| backoff | float | |
| max_backoff | float | |
| in_app | bool | Whether this client signs in as a deployed app's own code (its deployment's credential), where
|
for_sessionclassmethod
noclick.Client.for_session(session, *, base_url=None, **kwargs) -> ClientBuild 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).
NoneA client for that session, on the session's own API endpoint unless you pass base_url.
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 elseaclose
client.aclose() -> NoneClose the connection pool opened on the current event loop.
In a long-lived async app, close the client when you shut down:
await noclick.default_client().aclose()close
client.close() -> NoneClose the pool the blocking API uses.
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
) -> AnySend 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.
NoneNoneNoneWho the call acts for. Defaults to the user set by noclick.as_user (none: the account itself).
Makes a retried create safe: the same key returns the first result. Generated when omitted.
None)NoneFalseThe response's decoded JSON (None for an empty body), or its raw bytes with binary=True.
An error response raises its noclick.Error instead.
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 | NoneLink an object (in operations, agents or users) to its
developer console page.
The page's URL, or None when this client doesn't talk to the hosted API.
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) -> ClientReplace the default client, e.g. noclick.configure(api_key="nk_live_...").
NoneNoneThe new default client, which every call without client= now uses.
noclick.configure(api_key="nk_live_...", timeout=30, max_retries=5)
users = noclick.User.list(limit=10) # uses the new defaultdefault_client
noclick.default_client() -> ClientGet the client used when no client= is given, built from the environment on first use.
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).