pyais
AIS decoder for Python

Version 3.4.0
Oct 2026

pyais

Decode and encode AIS (Automatic Identification System) messages. Pure Python.

AIS is a tracking system used by vessels and coastal stations. Ships broadcast their identity, position, course, and speed over VHF radio. pyais reads these messages from NMEA 0183 sentences and turns them into Python objects.

Installation

$ pip install pyais

Requires Python 3.9+.

Quick start

Decode a single message:

from pyais import decode

msg = decode(b"!AIVDM,1,1,,B,15NG6V0P01G?cFhE`R2IU?wn28R>,0*05")
print(msg.mmsi)    # 367380120
print(msg.lat)     # 37.806948
print(msg.lon)     # -122.404333
print(msg.speed)   # 0.1

Read a file:

from pyais.stream import FileReaderStream

with FileReaderStream("sample.ais") as stream:
    for msg in stream:
        decoded = msg.decode()
        print(decoded.asdict())

Connect to a live TCP feed:

from pyais.stream import TCPConnection

for msg in TCPConnection("153.44.253.27", port=5631):
    decoded = msg.decode()
    print(decoded)

Encode a message:

from pyais.encode import encode_dict

data = {"type": 1, "mmsi": "366053209", "lat": 37.802, "lon": -122.341, "course": 219.3}
encoded = encode_dict(data)
print(encoded[0])

Track vessels:

from pyais import AISTracker
from pyais.stream import FileReaderStream

with FileReaderStream("sample.ais") as stream:
    with AISTracker() as tracker:
        for msg in stream:
            tracker.update(msg)
        for track in tracker.n_latest_tracks(10):
            print(track.mmsi, track.shipname, track.lat, track.lon)

Performance

pyais decodes roughly 270,000 messages per second on CPython (single core, Apple M3). Under PyPy it reaches about 1.2 million messages per second after JIT warmup.