Registry / serialization / bpylist2

bpylist2

JSON →
library4.1.1pypypi✓ verified 85d ago

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 bpylist2
INSTALL
IMPORT
SIG · BPYLIST2
B
bpylist2
serializationpythonv4.1.1
Install
1.5s avg
Import
48ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.051s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.045s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

archiver
from bpylist2 import archiver
The main entry point for archiving and unarchiving NSKeyedArchiver data.
DataclassArchiver
from bpylist2.archive_types import DataclassArchiver
Used as a base class for custom Python dataclasses to be archived/unarchived.

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.

from bpylist2 import archiver import io # An object to archive my_object = {'foo': 'bar', 'some_array': [1, 2, 3, 4], 'nested': {'key': 'value'}} # Archive the object into bytes archived_data = archiver.archive(my_object) print(f"Archived data (first 50 bytes): {archived_data[:50]}...") # Unarchive the bytes back into an object unarchived_object = archiver.unarchive(archived_data) print(f"Unarchived object: {unarchived_object}") # Verify round-trip assert my_object == unarchived_object print("Archiving and unarchiving successful!")
Debug
Known issues
gotchaWhen working with plain binary `.plist` files (not NSKeyedArchiver), `bpylist2` is not the correct tool. It will likely raise `UnarchiveError`.
fix
For standard binary plists, use Python's built-in `plistlib` module (`import plistlib`) instead of `bpylist2.archiver`.
affects: All versions
gotchaTo archive or unarchive custom Python objects (that are not standard types like dicts, lists, strings, numbers), you must either implement `encode_archive` and `decode_archive` static methods on your class or inherit from `bpylist2.archive_types.DataclassArchiver`.
fix
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`.
affects: All versions
gotchaWhen unarchiving a `NSKeyedArchiver` file containing custom Cocoa classes (not standard `NSString`, `NSArray`, etc.), `bpylist2` needs to know how to map these Cocoa classes to Python classes.
fix
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`).
affects: All versions
Errors
Common errors & fixes
AttributeError: 'MyCustomClass' object has no attribute 'encode_archive'
You are attempting to archive an instance of a custom Python class without having properly defined the archiving interface for it.
fix
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.
bpylist2.archiver.UnarchiveError: Unknown class: 'SomeCustomCocoaClass'
The NSKeyedArchiver archive contains a custom Apple Cocoa class ('SomeCustomCocoaClass' in this example) that `bpylist2` does not have a registered Python class mapping for.
fix
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.
bpylist2.archiver.UnarchiveError: Invalid magic string: 'bplist00' expected
This error typically occurs when you are trying to unarchive a file that is not a valid NSKeyedArchiver format, but rather a standard binary plist, or a corrupted file.
fix
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.
Upgrade
Version history
4.1.1latest on PyPI · released Sep 11, 2023
Audit
Dependencies
pythonrequiredRequired for execution, with specific plistlib handling for Python < 3.8.
Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
bpylist2 — pip install bpylist2 · libregistry