Skip to main content

Minimal, fast NMEA 2000 single-frame PGN decoder

Project description

pylibnmea2k

Minimal, fast NMEA 2000 single-frame PGN decoder for Python.

Decodes Yacht Devices YDWG-02 text format:

HH:MM:SS.mmm R 0xCANID DD DD DD DD DD DD DD DD

Returns typed dataclasses. No dependencies beyond the standard library.

Install

pip install pylibnmea2k

Usage

import pylibnmea2k

# Stateless
msg = pylibnmea2k.decode(line)

# Stateful wrapper (same interface)
decoder = pylibnmea2k.Decoder()
msg = decoder.decode(line)

decode() returns a typed dataclass or None if the PGN is unsupported or fields are not available.

Supported PGNs

PGN Name Key fields
127245 Rudder position_deg
127250 Vessel Heading hdg_deg
127251 Rate of Turn rot_rad_s
127257 Attitude yaw_deg, pitch_deg, roll_deg
127505 Fluid Level level_pct, capacity_l, fluid_type
127508 Battery Status voltage_v, current_a, temp_k
128259 Speed Through Water stw_kn
128267 Water Depth depth_m, offset_m
129025 Position Rapid Update lat, lon
129026 COG & SOG Rapid Update cog_deg, sog_kn
129033 Date / Time date_days, time_s
129283 Cross Track Error xte_m
130306 Wind speed_ms, angle_deg, reference
130310 Outside Environmental Params water_temp_k, air_temp_k, pressure_hpa
130311 Environmental Parameters temp_k, humidity_pct, pressure_hpa

Fast-packet (multi-frame) PGNs are not currently supported.

Result types

All dataclasses include pgn, priority, and source fields. Optional fields are float | NoneNone means the device reported "not available".

msg = pylibnmea2k.decode(line)
if isinstance(msg, pylibnmea2k.CogSog):
    print(f"COG {msg.cog_deg:.1f}°  SOG {msg.sog_kn:.1f} kn")

if isinstance(msg, pylibnmea2k.Wind):
    ref = ["True(N)", "Magnetic", "Apparent", "True(boat)", "True(water)"][msg.reference]
    print(f"Wind {msg.speed_ms:.1f} m/s at {msg.angle_deg:.1f}° ({ref})")

Performance

Struct-based decoding with no library dependencies. On a typical ARM Cortex-A7 at 650 MHz, decoding a matching PGN takes ~30–45 µs; discarding a non-matching frame takes ~0.5 µs.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylibnmea2k-0.2.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylibnmea2k-0.2.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file pylibnmea2k-0.2.2.tar.gz.

File metadata

  • Download URL: pylibnmea2k-0.2.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylibnmea2k-0.2.2.tar.gz
Algorithm Hash digest
SHA256 87194877e1dfea8fa08ac628cd195e994e3f81c46dc81bce9dd85a243b458e09
MD5 15581997ea2d4a5205d9e5da48b9c7b9
BLAKE2b-256 e9d5ffe752f5d0f74a93c7ec62812e18a5b127c777e5fea173fec4db1894f22d

See more details on using hashes here.

File details

Details for the file pylibnmea2k-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pylibnmea2k-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylibnmea2k-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f11929218851ba048619fbbb47ef0052ce8f81ef33a74dbcc7e83d3f8faf5a2
MD5 6503d309a20f5f4a2c5d993494da78a0
BLAKE2b-256 4c47c4c4a4843f5978228025a9713bf95c50b7bb1470a6af88141eb65f7e8b63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page