Pure-Python decoder for Shearwater's Petrel Native Format (PNF) dive logs
Project description
pnf
A pure-Python decoder for Shearwater's Petrel Native Format (PNF), the on-device log format used by Shearwater's Petrel-family dive computers (Petrel, Perdix, Teric, Nerd, Peregrine, and successors).
Shearwater Cloud can export your dives to XML, CSV, or its own SQLite database.
The XML and CSV are lossy: they drop channels the computer actually recorded,
including GF99, the deco ceiling, per-sample battery voltage and percentage, and
the "@+5" prediction. The SQLite export keeps the real thing: each dive is
stored as a compressed native-format blob. pnf decodes those blobs.
No dependencies, standard library only, Python 3.9+.
pip install pnf
Usage
Point it at a Shearwater Cloud "Export Database" file (dive_data.db):
import pnf
for log_id, dive in pnf.decode_database("dive_data.db"):
h = dive.header
print(f"{h['computer_model']} #{h['computer_serial']:X}: "
f"{h['max_depth_m']} m, {len(dive.samples)} samples")
for s in dive.samples:
if s.gf99 is not None:
print(f" t={s.t_s:.0f}s depth={s.depth_m}m gf99={s.gf99} "
f"ceiling={s.ceiling_m}m battery={s.battery_v}V")
Or decode a single sw-pnf blob you already have:
dive = pnf.decode(blob)
What you get
decode() returns a Dive with:
header— a dict of dive configuration: gases, gradient factors, deco model, water density, atmospheric pressure, sample interval, computer serial / model / firmware, GNSS entry/exit fix (on computers that log it), and verbatim copies of the raw config records.samples— a list ofSample, one per log interval (typically every 10 s), each with depth, temperature, TTS, next-stop depth, NDL, average and per-cell ppO2, CNS, GF99, deco ceiling, battery voltage and percentage, gas fractions, setpoint, wireless-air-integration tank pressures, SAC, the decoded status/mode bits (including CCR solenoid-fired count), and the "@+5" prediction. Channels the computer did not record areNone.gases— the ten programmed gases (O2/He, open- vs closed-circuit, enabled).events— info-event records.unknown_records— every record type this decoder does not interpret, kept verbatim as(type_key, seq, raw_bytes). Shearwater's own desktop parser also leaves several record types (tissue snapshots, validity maps, surface ppO2, button pushes, DiveCAN events) undecoded;pnfpreserves them rather than discarding them, so a future decoder can revisit them.
Under the DCIEM deco model, sample bytes 24-25 encode a safe-ascent depth
instead of a ceiling / GF99 pair; pnf decodes them to safe_ascent_depth_m
and leaves ceiling_m / gf99 as None. See SPEC.md for details.
The format
SPEC.md documents the container, the record types, and every byte of the dive-sample record, with the provenance of each field.
Provenance and scope
This is independent reverse engineering for interoperability: reading dive
logs you own, in Python, without going through Shearwater Cloud. The documented
sample fields follow the layout in
libdivecomputer's
shearwater_predator_parser.c. The remaining fields were identified by
observation across real dives and cross-checked against Shearwater Cloud's own
outputs (its XML export and its per-dive EndGF99 summary), then reconciled for
naming and edge cases such as the DCIEM branch.
pnf is not affiliated with or endorsed by Shearwater Research, contains no
Shearwater code, and does not redistribute any Shearwater software. Format facts
(byte offsets and field meanings) are not code. If you want a maintained,
officially-supported path, Shearwater offers a developer program.
Validated against Perdix 2 and Petrel 3 logs. The sample record layout is stable across native-format versions, but other models may populate fields this decoder has not seen. If a dive decodes wrong, open an issue with the blob; that is exactly the data that improves the decoder.
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pnf-0.1.0.tar.gz.
File metadata
- Download URL: pnf-0.1.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c965e5dc5a2b3a4dd4b2ec7d7e1ecc53f4742c0ff42f9493777e3269c901350f
|
|
| MD5 |
5df9bffe63222f3877f866875e8b14cd
|
|
| BLAKE2b-256 |
0d15d79a56da0e13f8859de4f4a3e26e302b6c2a9cec3b8f6809afb3dd08320b
|
File details
Details for the file pnf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pnf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af94451fdc6136c15727ba298f30e3fe3b830f9d5b5534a20aef6c6b499f2d7a
|
|
| MD5 |
08137ae22372da2b0d4b7e063d338c3f
|
|
| BLAKE2b-256 |
c821d5b170604ee59a98f1ef37525f29efd3027ee4099c72f9e695110ab33dcf
|