set_instance
Stores the Enterprise license key on this machine — or removes it. Works without sign-in.
On this page
Signature
cat.set_instance(license_key: str, logging_level: LoggingLevel = None) -> None
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
license_key |
str | required | The key to store. An empty string, whitespace or None removes the stored key. |
logging_level |
LoggingLevel | None |
cat.LoggingLevel member; used only when this is the first call of the process. See Logging. |
What it does
Writes the key to %APPDATA%\CAT\.catconfig (~/.config/CAT/.catconfig on Linux), the file that identifies this installation and is shared by every CAT tool on the machine. It does not sign in — a key can be installed on a machine that has no portal access and no token. Setting a key is how the Enterprise plan is activated; once a valid key is stored, every function works offline and CAT_PORTAL_TOKEN is no longer read. The key takes effect immediately for the next call.
A key can also come from the CAT_LICENSE_KEY environment variable, and that one wins: while it is set, the key stored here is not used. This function still stores what you give it, and raises a UserWarning saying the stored key takes effect only once the variable is removed — unless you stored exactly the key the variable holds, which changes nothing and says nothing. See Apply a license key.
The key is checked before it is stored: a genuine CAT key is stored even when it is expired or not yet valid (what it unlocks is decided at every use, and a future key starts working the day its window opens); anything that is not a CAT key — a typo, a truncated paste — is refused and the stored key is left unchanged.
Returns
None.
Raises
ValueError: The license key was not set. <reason> when the key is not a CAT key. Removing a key never fails.
Every other function — the ones that do run the sign-in and plan check — raises justcatit.LicenseKeyVariableError when CAT_LICENSE_KEY is set but holds no key CAT can use. get_instance() and set_instance() are exempt, so a wrong variable can always be inspected and a key can still be stored.
Examples
# activate the Enterprise plan on this machine
cat.set_instance("your-license-key")
print(cat.get_instance().LicenseKey)
# go back to no key (sign-in with CAT_PORTAL_TOKEN applies again)
cat.set_instance("")
Related
- Introduction — session model, logging, .NET objects, exceptions, sign-in. (sign-in, plans and the license key)
get_instance— see what is stored.- Get CAT license · Apply a license key · Compare plans.