API reference¶
The public surface of apwlib: everything importable from the package root,
plus the two blessed modules apwlib.pinwindow and apwlib.diagnostics.
Generated from the source.
The facade¶
ApplePasswords ¶
ApplePasswords(
socket_path: str | Path | None = None,
auto_start: bool = True,
pin_provider: Callable[[], str] | None = None,
)
Read and write Apple Passwords (iCloud Keychain) via a managed daemon.
The daemon (a headless browser hosting the iCloud Passwords extension) is auto-started
on first use as a detached singleton and reused thereafter; use Daemon for
explicit lifecycle control. Pairing needs a one-time PIN: if pin_provider is given,
an unpaired request transparently pairs (pops the macOS dialog, calls
pin_provider(), retries); otherwise it raises NotPairedError.
Pass auto_start=False to require an already-running daemon.
get_password ¶
get_password(
url: str, username: str | None = None
) -> list[PasswordEntry]
Password entries for a site, optionally restricted to username.
save_password ¶
Create or update a credential.
Daemon control¶
Daemon ¶
The connection to the background daemon: transport, lifecycle, and pairing.
ApplePasswords manages one internally (auto-start, auto-pair); construct your
own only for explicit lifecycle control — it backs apwcli daemon
start/stop/status/pair.
start ¶
Ensure a daemon is running with its bridge connected.
A no-op when one is already reachable — except with an explicit browser,
which needs a fresh daemon and raises instead (use restart). Otherwise
spawns one — after waiting out a stopping daemon's singleton lock, so stop
immediately followed by start works. browser applies to that daemon only
(it is not persisted). Raises DaemonStartError if the bridge does not come
up, and ApwError when no supported browser is installed.
restart ¶
Stop any running daemon and start a fresh one (raises like start).
status ¶
status() -> DaemonStatus
Report daemon reachability, bridge connectivity, and pairing (does not auto-start).
When running, also reports browser (the managed browser's name) and
browser_pid (its process id); both are None otherwise.
request_challenge ¶
Ask the extension to display the macOS pairing PIN.
Returns once the handshake is ready for the PIN, so verify_challenge
can be called immediately. Raises if the daemon/extension can't pair at all.
verify_challenge ¶
Submit the PIN and block until pairing settles; True once paired.
False means the helper rejected the PIN (reported the moment the handshake collapses) or the attempt timed out daemon-side.
DaemonStatus ¶
Bases: TypedDict
The shape of Daemon.status; keeps its two return paths in sync.
Entries¶
PasswordEntry
dataclass
¶
PasswordEntry(
username: str,
domain: str,
password: str | None = None,
title: str | None = None,
sites: list[str] = list(),
high_level_domain: str | None = None,
)
OTPEntry
dataclass
¶
PIN window¶
request_pin ¶
Pop the PIN window and return the six digits the user typed.
css replaces the window's stylesheet (falling back to
~/.apwlib/pinwindow.css, then the bundled default). Raises
NotPairedError when no supported browser is installed, the window is
closed without a code, or nobody answers within timeout.
Diagnostics¶
run_checks ¶
Diagnose the setup chain; does not auto-start the daemon.
Check
dataclass
¶
One diagnostic result. hint says how to fix it (empty when ok).
Errors¶
ApwError ¶
ApwError(status: Status | int, message: str | None = None)
Bases: Exception
Base error carrying a protocol Status.
SessionError ¶
DaemonNotRunningError ¶
NotPairedError ¶
DaemonStartError ¶
ServerError ¶
Status ¶
Bases: IntEnum