DocumentationLanyard / Integration reference

Python SDK & pairing.

Connect a desktop application or CLI to Lanyard, request a credential, and manage the identity used for future access.

SDK 0.2.xDesktop protocol v2Python 3.9+
On this page
python -m pip install "lanyard>=0.2.0,<0.3"

Install and open Lanyard desktop on the same computer, unlock the vault, and add a credential. For the example below, choose the API key category and put the provider key in its API_KEY field. The Python package does not install the desktop vault.

Connect once and use the approved result

from lanyard import LanyardClient

client = LanyardClient(
    "My desktop app",
    app_id="com.example.desktop",
)

linked = client.request_link(
    category="api_key",
    reason="Choose an API key for this connection.",
)
target_id = linked["target_id"]  # Save this ID in application preferences.
api_key = linked["data"]["API_KEY"]  # Use this result; do not log it.

request_link() asks the user to choose an item and approve access. It returns the selected item's ID and all its approved fields. Read linked["data"] immediately; calling get_field() directly afterward would make a second request and can show another approval prompt.

Use the credential's actual field names. API_KEY is Lanyard's default API-key field, not a universal name for every item. Handle a missing field in your application instead of assuming a selected item contains it.

Pairing is automatic

You do not need to paste or generate pairing keys in normal Python integration code. On the first request, the SDK loads an existing identity or generates:

  • A random UUID client_id.
  • A cryptographically random 32-byte token, encoded as 43 unpadded base64url characters.

The default store saves this pair through Python keyring, under the service ULIX Lanyard Clients v2, with your app_id as the entry name. Later client instances and application launches reuse it. Every protocol request includes the client ID and token. Lanyard stores a hash of the token when the user approves pairing.

This is a client ID plus a secret bearer token, not an asymmetric public/private signing-key pair. The vault's Cryptographic keys category can separately store generated RSA/Ed25519 keys; those are credential contents, not the pairing mechanism.

Value Purpose Where it belongs
app_name Display name shown in the approval prompt Stable application configuration
app_id SDK lookup key for your saved pairing identity; not sent as authentication Stable application configuration
client_id Random ID sent to the desktop API Saved pairing identity
token Secret proving possession of that identity OS credential store; never logs or command-line arguments
target_id ID of the selected vault item Application preferences; the ID alone grants no access
API_KEY or another returned field The user's actual provider credential Use only where needed; do not log

Keep both app_id and app_name stable. Lanyard checks a known client's stored display name as well as its token. A new app_id creates a different identity; a renamed app_name with an existing identity can be rejected. Coordinate name changes with the user by forgetting the old app in Lanyard and approving it again.

A pairing identifies possession of a token. It does not verify the application's publisher or executable signature. Display names and reasons are supplied by the requesting app.

Read a previously selected item

On a later operation or launch, construct the client with the same app name and app ID, load the saved item ID from your preferences, and request it:

# target_id was saved from the earlier request_link() result.
api_key = client.get_field(target_id, "API_KEY")
# Or request the complete field dictionary:
# fields = client.get_secret(target_id)

Each call is a new access request. Allow once approves only one request. Allow and remember saves an app/item grant; it can skip the prompt for later targeted requests while the vault is unlocked. request_link() still asks the user to select an item, even when another item already has a remembered grant.

The desktop UI can revoke automatic access or forget the paired app. Revocation prevents future automatic requests; it cannot erase a secret already returned to an application. An app may retain a copy, as Skudio does when connecting a provider key. Invalidate a compromised provider key with its provider.

API reference

LanyardClient(app_name, port=None, *, app_id=None,
              session_only=False, credential_store=None)
client.request_link(reason=None, category=None, timeout=300)
client.get_secret(target_id, timeout=300)
client.get_field(target_id, field_name, timeout=300)
  • request_link() returns {"status": "success", "target_id": "...", "data": {"field": "value"}}.
  • get_secret() returns the item's field dictionary. get_field() returns one string, but the protocol still shares the selected item's whole field dictionary with the client. It is not a field-level permission boundary.
  • Categories: api_key, password, license, recovery, env, crypto. Omit the category to allow the user to choose any category.
  • timeout is an integer from 1 to 300 seconds. Requests block the calling thread. In GUI applications, run them on a worker and marshal results back to the UI thread.
  • Omit port for automatic discovery. The SDK reads ~/.lanyard/endpoint.json on each call, including after a desktop restart. An explicitly supplied port stays fixed.

Errors and recovery

Catch LanyardError for SDK failures; input validation can also raise ValueError. A missing key accessed directly in linked["data"] raises Python KeyError.

Error Action
LanyardNotRunningError Start the desktop app or restart it if endpoint discovery is stale.
LanyardAccessDeniedError The user denied access or the saved pairing was rejected. Do not retry automatically in a prompt loop.
LanyardTimeoutError Ask the user to retry the connection when ready to approve it.
LanyardKeyNotFoundError The item was deleted, or get_field() could not find the field. Offer selection of another item.
LanyardUpgradeRequiredError Upgrade the SDK and desktop to compatible protocol-v2 versions.
LanyardError Check the native credential store, protocol response, or reported HTTP status. A busy request queue is reported here.

The SDK suppresses response bodies in its errors because they may contain secrets. Do not add raw response logging around it.

Credential storage and temporary sessions

The default path uses keyring; the SDK has no built-in plaintext-file fallback. Use a secure OS-backed keyring backend. A locked or unavailable keyring causes an error. Linux requires a working, unlocked Secret Service keyring for the desktop vault.

For a temporary client identity held in memory:

temporary_client = LanyardClient("One-off import", session_only=True)

Each new temporary client instance creates a new identity. It cannot reuse a previous instance's saved approvals. Do not use this mode as an automatic fallback for a persistent desktop integration.

An application with its own secure store can pass a CredentialStore implementing load(app_id) -> Credential | None and save(app_id, credential). Credential and CredentialStore are exported from lanyard. Persist both identity fields atomically and reuse the same identity across launches. Credential.token is omitted from repr, but it is still a secret. In-memory stores are suitable for tests, not persistent production pairing.

CLI

python -m lanyard --app "My CLI" --app-id com.example.cli link --category api_key
python -m lanyard --app "My CLI" --app-id com.example.cli get ITEM_UUID --field API_KEY

Replace ITEM_UUID with the returned item ID. Global options, including --timeout and --session-only, go before link or get. The two commands make separate requests. These commands intentionally print approved secrets to stdout; send output to the consuming process and keep it out of logs, recorded terminals, and shell-history substitutions.

Migrating from SDK 0.1

Upgrade the SDK and desktop together. Protocol v2 retires /lanyard-ipc and the old name-only grants. Existing Python method names and return shapes are retained, but the SDK now manages a stored identity. Add a stable app_id, handle native keyring availability, and let the user approve pairing again. Desktop legacy-vault import preserves item/project IDs; it does not carry over the old name-only approvals.

Other languages and scope

The API is local JSON/HTTP for native desktop apps and CLI tools. Ordinary web pages, browser extensions, remote servers, and cloud-hosted applications cannot access a user's desktop vault through it. Python requests use loopback, bypass proxy settings, reject redirects, and limit response reads to 2 MiB.

See the desktop protocol reference or the website integration guide. The repository also contains docs/PAIRING.md, examples/connect.py, and release instructions in docs/RELEASING.md.

Run the tests from the project directory:

python -m unittest discover -s tests -v