bpylist2 is a Python library for parsing and generating NSKeyedArchiver archives, an Apple proprietary serialization format for Cocoa objects. It is a fork of the original `Marketcircle/bpylist` project, maintained to be more responsive to contributions. While it specializes in NSKeyedArchiver, it also includes a bundled `plistlib` compatible with Python 3.8 for older Python versions, though for standard binary plists, the `stdlib` `plistlib` is recommended. The current version is 4.1.1, released in September 2023.
pip install bpylist2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic workflow of archiving a Python dictionary into `NSKeyedArchiver` format bytes and then unarchiving it back. This covers the most common use case for standard Python types.
For standard binary plists, use Python's built-in `plistlib` module (`import plistlib`) instead of `bpylist2.archiver`.
For custom classes, define `encode_archive(obj, archive)` and `decode_archive(archive)` static methods. Alternatively, use a dataclass and inherit `from bpylist2.archive_types import DataclassArchiver`.
Register a mapping using `archiver.update_class_map({'CocoaClassName': PythonClass})`, where `PythonClass` is your custom Python class capable of decoding the data (e.g., using `DataclassArchiver` or custom `decode_archive`).Ensure your custom class `MyCustomClass` either inherits from `bpylist2.archive_types.DataclassArchiver` (if it's a dataclass) or implements `encode_archive(obj, archive)` and `decode_archive(archive)` as static methods.
Define a corresponding Python class (e.g., `MyPythonClass`) that can handle the structure of 'SomeCustomCocoaClass', and then register it using `archiver.update_class_map({'SomeCustomCocoaClass': MyPythonClass})` before attempting to unarchive.Verify that the file is indeed an `NSKeyedArchiver` archive. If it's a regular binary plist, use Python's standard `plistlib` module instead. If it's expected to be `NSKeyedArchiver`, check the file's integrity.