On this page
  1. plistlib
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Reading & Updating a macOS .plist File Safely
  7. Gotchas & Boundaries
  8. Common Functions
  9. Classes & Objects
  10. Constants & Attributes

plistlib

Prev: platform | Up: stdlib_module | Next: poplib
Rel: csv, configparser, tomllib, netrc
Ref: docs.python.org — plistlib
Tags: #public #python3 #stdlib


Import

import plistlib

Overview

Reads and writes Apple Property List (.plist) files in both XML (FMT_XML) and binary (FMT_BINARY) formats (loads, dumps, load, dump). Essential for macOS automation—inspecting Info.plist app bundles, LaunchAgents definitions, and macOS preferences cleanly with zero external dependencies.

Quick Start

import plistlib

data = {"CFBundleIdentifier": "com.wispsy.demo", "LSUIElement": True, "Version": 1}
xml_bytes = plistlib.dumps(data, fmt=plistlib.FMT_XML)
assert plistlib.loads(xml_bytes) == data

bin_bytes = plistlib.dumps(data, fmt=plistlib.FMT_BINARY)
assert plistlib.loads(bin_bytes) == data

Implementation Walkthrough

1. Reading & Updating a macOS .plist File Safely

Both load() and dump() require binary file handles ("rb" / "wb"):

from pathlib import Path
import plistlib
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    p = Path(tmp) / "com.example.agent.plist"
    config = {"Label": "com.example.agent", "ProgramArguments": ["/usr/bin/true"]}
    with p.open("wb") as fh:
        plistlib.dump(config, fh, fmt=plistlib.FMT_XML)

    with p.open("rb") as fh:
        loaded = plistlib.load(fh)
    assert loaded["Label"] == "com.example.agent"

Gotchas & Boundaries

Common Functions

Classes & Objects

Constants & Attributes

Linked from

Related notes