This page covers a complete Python client that connects to the keychain-auth daemon over Unix domain sockets on macOS and Linux, and via Windows Named Pipes on Windows. You will learn how to enforceDocumentation Index
Fetch the complete documentation index at: https://theseventeen-2abbdf80.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
FD_CLOEXEC using fcntl, handle the pywin32 dependency on Windows, send newline-terminated JSON requests, and handle daemon error responses.
Full client implementation
The following is a complete Python client you can copy into your project and adapt with your service name and request payloads.Key sections explained
Platform detection
The This single check drives the entire transport difference. The rest of the class is symmetric —
_connect method checks sys.platform to branch between Unix and Windows connection logic:send_request applies the same sys.platform == "win32" check when choosing between win32file calls and raw socket I/O.Unix socket connection with FD_CLOEXEC enforcement
On macOS and Linux, the client creates a standard The existing flags are read with
AF_UNIX socket then immediately sets the FD_CLOEXEC flag using fcntl. Python’s socket module does not set this flag by default.F_GETFD first so that only FD_CLOEXEC is added, leaving any other descriptor flags intact. The flag is set before connect() to avoid any window where the descriptor could be inherited.The client selects the socket path based on the platform: on macOS it uses ~/Library/Application Support/keychain-auth/agent.sock; on Linux it uses $XDG_RUNTIME_DIR/keychain-auth/agent.sock (falling back to ~/.cache/keychain-auth/agent.sock):Windows Named Pipe via pywin32
On Windows, the client opens the Named Pipe using The
win32file.CreateFile from the pywin32 library. The pipe path is always \\.\pipe\keychain-auth.ImportError catch provides a clear message when pywin32 is absent:On Windows you must install the
pywin32 package before using this client: pip install pywin32. The win32file and win32pipe modules it provides are the only supported way to interact with Windows Named Pipes from Python.Sending JSON requests (newline-terminated)
Every request is a JSON object serialized to a single line and terminated with On Unix, the full payload is sent with On Windows, it is written to the pipe handle with Both paths encode the string as UTF-8 bytes before transmission.
\n. The daemon’s parser requires this terminator to detect the end of the message.sendall to guarantee all bytes are written:win32file.WriteFile:Parsing the response and error handling
The client reads chunks in a loop until it receives a newline, then splits on After parsing, the Callers should catch
\n and decodes only the first line:status field is checked. Any non-"success" status raises a RuntimeError that includes the daemon’s reason code, giving callers a machine-readable error string:RuntimeError and inspect the message for reason codes such as unregistered_binary_pending_approval or service_not_allowed to produce actionable user-facing messages.