Reference

SDKs for Python and Node.js

Python and Node.js clients for PassKeel's local API, how to install them today, and how they find the API, open profiles and report errors.

PassKeel has two client libraries for the local API, one for Python and one for Node.js. Both are generated from the API’s OpenAPI description, so every endpoint is a method, and the common ones also have short names.

Python (package passkeel) Node.js (package passkeel)
Runtime Python 3.9 or later, standard library only Node.js 18 or later, no runtime dependencies
Styles PassKeel (synchronous) and AsyncPassKeel (asyncio) PassKeel (promises); ES module and CommonJS builds with TypeScript types
Typing Typed (py.typed); request bodies as TypedDicts TypeScript interfaces for request bodies and queries

Installing

The SDKs are not published on PyPI or npm yet. Until they are, contact us and we’ll send you the package files, or call the HTTP API directly: it is fully described at http://127.0.0.1:50325/openapi.json.

With the package files:

# Python: install the source folder or the wheel you received
pip install ./passkeel-python

# Node.js: install the packed tarball you received
npm install ./passkeel-0.1.0.tgz

You don’t need to download a browser for Playwright or Puppeteer: PassKeel brings its own browser, and the SDKs connect to it. Install playwright-core (Node.js) or puppeteer-core rather than the full packages if you want to skip the browser download.

Finding the API and authenticating

The SDKs look for the API in this order:

  1. the base_url (Python) or baseUrl (Node.js) you pass,
  2. the PASSKEEL_API_URL environment variable,
  3. the port you pass,
  4. the PASSKEEL_PORT environment variable,
  5. the default port, 50325.

The API key comes from api_key / apiKey, or from the PASSKEEL_API_KEY environment variable. Create a key in Settings > API keys in the app.

# Windows (Command Prompt)
set PASSKEEL_API_KEY=pk_...your key...
# PowerShell
$env:PASSKEEL_API_KEY = "pk_...your key..."

Method names

Every operation is a method named after the API’s operation ID, for example post_profiles_id_open in Python and postProfilesIdOpen in Node.js. The everyday ones also have short names:

Python Node.js Endpoint
list_profiles listProfiles GET /v1/profiles
create_profile createProfile POST /v1/profiles
get_profile getProfile GET /v1/profiles/{id}
update_profile updateProfile PATCH /v1/profiles/{id}
delete_profile deleteProfile DELETE /v1/profiles/{id} (to the trash)
open_profile openProfile POST /v1/profiles/{id}/open
close_profile closeProfile POST /v1/profiles/{id}/close
profile_status profileStatus GET /v1/profiles/{id}/status
list_proxies listProxies GET /v1/proxies
list_windows, arrange_windows listWindows, arrangeWindows /v1/windows

Opening a profile

The safest pattern opens a profile, gives you its connection details and closes it again (saved and synced) when your code finishes, even after an error.

Python

from passkeel import PassKeel
from playwright.sync_api import sync_playwright

pk = PassKeel()
profile = pk.create_profile({"name": "Shop DE 0042"})

with pk.session(profile["id"], headless=True) as s, sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(**s.playwright_connect_args())
    page = browser.contexts[0].new_page()
    page.goto("https://example.com")
    print(page.title())
    browser.close()   # only disconnects; leaving the block closes the profile

The session object gives the connection details for each tool:

  • s.playwright_connect_args() for chromium.connect_over_cdp(**...),
  • s.puppeteer_connect_options() for pyppeteer-style clients (browserWSEndpoint, defaultViewport),
  • s.selenium_remote_url() for webdriver.Remote(command_executor=...).

With asyncio, use AsyncPassKeel and async with pk.session(...).

Node.js

import { PassKeel } from 'passkeel';
import { chromium } from 'playwright-core';

const pk = new PassKeel();
await pk.withProfile(profileId, { headless: true }, async (s) => {
  const browser = await chromium.connectOverCDP(s.playwright.endpointURL);
  const page = await browser.contexts()[0].newPage();
  await page.goto('https://example.com');
  console.log(await page.title());
  await browser.close(); // only disconnects; withProfile closes the profile
});

s.puppeteer is ready for puppeteer.connect(s.puppeteer) and s.selenium.serverUrl for Selenium’s new Builder().usingServer(...).

openProfile / open_profile returns the same object without closing the profile afterwards; automation(id) returns it for a profile that is already open. Open options are the API’s: in Node.js headless, skipProxyCheck, offline, keepVisibleWhenCovered and pin; in Python the same as keyword arguments in snake_case (headless=, skip_proxy_check=, offline=, keep_visible_when_covered=, pin=).

Complete examples for each tool, in both languages, are in Connect Puppeteer, Playwright or Selenium.

Arranging windows

pk.arrange_windows(ids, "grid", monitor=0, columns=3, gap=8)
pk.arrange_windows(ids, "cascade", step=40)
pk.arrange_windows(ids, "resize", width=1280, height=800)

grid tiles the windows on one monitor, cascade offsets them, and resize gives them all the same size without moving them.

Errors

Error answers raise typed exceptions. All are subclasses of PassKeelError and carry status, code, message, body and details (the whole error object).

Status Exception Typical cause
400, 422 ValidationError Invalid request; for 422 keel_exited, details["exit"] has the browser’s exit code, message and fix
401 AuthError Missing or wrong API key
403 ForbiddenError Plan limit, licence or team role; a locked profile without its PIN
404 NotFoundError Unknown profile, proxy or other object
409 ConflictError already_open, not_open, busy, sync_locked
429 RateLimitError Too many requests; wait retry_after (Python) or retryAfter (Node.js) seconds
5xx ServerError An error inside PassKeel; a support bundle helps us
none PassKeelConnectionError PassKeel isn’t running, or it listens on another port
from passkeel import PassKeel, ConflictError

try:
    pk.open_profile(profile_id)
except ConflictError as e:
    if e.code == "already_open":
        print("Already open; reusing it")

Events

The SDKs don’t wrap the event WebSocket, so they stay free of dependencies. Connect to ws://127.0.0.1:<port>/v1/events?key=<api key> with any WebSocket client; each message is one JSON event. See Events.