Skip to content

connect() and auth

How connect() picks a credential is explained in the authentication guide.

connect

connect(profile: str | None = None, *, secret_key: str | None = None, jwt: str | None = None, api_host: str | None = None, license: str | None = None, interactive: bool | None = None, validate: bool = True, sandbox: bool | None = None, spec: Literal['auto', 'bundled'] | None = None, rate_limit: float | None = 10.0, concurrency: int = 10, timeout: float = DEFAULT_TIMEOUT, log_http: bool | None = None, transport: BaseTransport | None = None, verify: bool | str = True, proxy: str | None = None) -> T3Client

Find a credential and return a validated T3Client.

Parameters:

Name Type Description Default
profile str | None

Saved profile to use. Defaults to T3_PROFILE, then the config's default profile.

None
secret_key str | None

Use this secret key. Wins over everything else.

None
jwt str | None

Use this JWT.

None
api_host str | None

T3 API base URL. Defaults to T3_API_HOST, then the profile's, then https://api.trackandtrace.tools.

None
license str | None

Default license for calls that need one. Defaults to T3_LICENSE, then the profile's, except in the sandbox, where only this argument counts.

None
interactive bool | None

False never prompts; True always may. By default it prompts only in a terminal or Jupyter.

None
validate bool

Check the credential with GET /v2/auth/whoami.

True
sandbox bool | None

Exchange the credential for a Metrc sandbox JWT. Defaults to T3_SANDBOX (1, true, yes or on). In the sandbox, T3_LICENSE and the profile's license are ignored, since a production license there returns no rows rather than an error.

None
spec Literal['auto', 'bundled'] | None

"bundled" pins the spec that ships with the package. Defaults to T3_SPEC, then "auto".

None
rate_limit float | None

Requests per second across all threads. None disables it.

10.0
concurrency int

Threads used to fetch collection pages.

10
timeout float

Request timeout in seconds.

DEFAULT_TIMEOUT
log_http bool | None

Log every request and response at DEBUG, with secrets masked. Defaults to T3_LOG_HTTP.

None
transport BaseTransport | None

An httpx2 transport to use instead of the network.

None
verify bool | str

TLS verification, as in httpx2.

True
proxy str | None

Proxy URL, as in httpx2.

None

Raises:

Type Description
AuthRequired

no credential and no terminal to ask in.

AuthError

the credential was rejected.

SecretKeys

SecretKeys(client: T3Client)

client.secret_keys: manage the account's secret keys.

list

list() -> list[dict[str, Any]]

Every secret key on the account, with isEnabled, isManaged and lastUsedAt.

create

create(hostname: str, username: str, password: str, email: str | None = None, otp_seed: str | None = None) -> str

Create a secret key and return it. See create_secret_key.

rotate

rotate(key: str, *, password: str, username: str | None = None, hostname: str | None = None, email: str | None = None, otp_seed: str | None = None) -> dict[str, Any]

Update the Metrc credentials behind a key after a password, email or OTP change.

The key value doesn't change. username and hostname default to the profile's, then to whoami.

delete

delete(key: str) -> dict[str, Any]

Delete a key. Managed keys can't be deleted (the server answers 403).

Profile dataclass

Profile(name: str, api_host: str = DEFAULT_HOST, metrc_hostname: str | None = None, username: str | None = None, license: str | None = None, credential: CredentialKind | None = None)

A saved login. Secrets aren't stored here; see Store.

SecretKeyAuth

SecretKeyAuth(key: str)

Bases: Auth

Sends a T3 secret key in the X-T3-API-Key header.

BearerAuth

BearerAuth(token: str)

Bases: Auth

Sends a JWT in the Authorization: Bearer header.

expires_at property

expires_at: datetime | None