PyAIS
raw JSON → 3.0.0 verified Fri May 01 auth: no python
A Python library for decoding and encoding AIS (Automatic Identification System) messages used in maritime navigation. Current version 3.0.0 (released 2024) with ~35% faster performance, requires Python >=3.9. No regular release cadence; version 2.x was stable for years.
pip install pyais Common errors
error ModuleNotFoundError: No module named 'pyais.decode' ↓
cause Importing decode as a submodule instead of top-level function.
fix
Use 'from pyais import decode'.
error AttributeError: 'AISSentence' object has no attribute 'bit_array' ↓
cause Using deprecated attribute from v2.x. In v3.0.0, 'bit_array' was renamed to 'bv'.
fix
Replace 'bit_array' with 'bv'.
error TypeError: decode() missing 1 required positional argument: 'sentence' ↓
cause Calling decode on a list or forgetting to pass the sentence string.
fix
Ensure you pass a single NMEA sentence string to decode().
Warnings
breaking v3.0.0 renamed AISSentence.bit_array to AISSentence.bv and Payload.from_bitarray() to Payload.from_vector(), Payload.to_bitarray() to Payload.to_bytes(). Code using old names will break. ↓
fix Replace .bit_array with .bv, .from_bitarray() with .from_vector(), .to_bitarray() with .to_bytes().
breaking v3.0.0 removed the bitarray dependency; replaced with custom bit_vector. Imports like 'from bitarray import bitarray' may not work for pyais internals. ↓
fix Do not rely on bitarray for pyais objects; use pyais's built-in bit vector.
deprecated NonPrintableCharacterException has been deprecated in v3.0.0 and may be removed in future. ↓
fix Catch generic Exception or use pyais's custom exceptions; avoid relying on NonPrintableCharacterException.
gotcha decode() can raise pyais.exceptions.DecodingError if the message is malformed or checksum fails. New users may not handle exceptions. ↓
fix Wrap decode() in try/except or validate checksum separately using pyais.checksum.
Imports
- decode wrong
from pyais.decode import decodecorrectfrom pyais import decode - AISSentence wrong
from pyais.messages import AISSentencecorrectfrom pyais import AISSentence - Payload wrong
from pyais.payload import Payloadcorrectfrom pyais import Payload
Quickstart
from pyais import decode
# NMEA 0183 AIS message string
msg = "!AIVDM,1,1,,A,133m@ogP00PD;88MD5MTDww@2D7k,0*46"
decoded = decode(msg)
print(decoded)
print(decoded.asdict())