Python library for the NMEA 0183 protcol
Clone or download
Pull request Compare This branch is 1 commit ahead, 24 commits behind Knio:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


pynmea2 is a python library for the NMEA 0183 protocol

pynmea2 is based on pynmea by Becky Lewis

The pynmea2 homepage is located at


pynmea2 is compatable with Python 2.7 and Python 3.3

Build Status Coverage Status Code Health


The recommended way to install pynmea2 is with pip:

pip install pynmea2

PyPI version


You can parse individual NMEA sentences using the parse() function, which takes a string containing a NMEA 0183 sentence and returns a NMEASentence object. Note that the leading '$' is optional and trailing whitespace is ignored when parsing a sentence.


>>> import pynmea2
>>> msg = pynmea2.parse("$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D")
>>> msg
<GGA(timestamp=datetime.time(18, 43, 53), lat='1929.045', lat_dir='S', lon='02410.506', lon_dir='E', gps_qual='1', num_sats='04', horizontal_dil='2.6', altitude=100.0, altitude_units='M', geo_sep='-33.9', geo_sep_units='M', age_gps_data='', ref_station_id='0000')>

The NMEASentence object has different properties, depending on its sentence type. The GGA message has the following properties:

>>> msg.timestamp
datetime.time(18, 43, 53)
>>> msg.lat_dir
>>> msg.lon
>>> msg.lon_dir
>>> msg.gps_qual
>>> msg.num_sats
>>> msg.horizontal_dil
>>> msg.altitude
>>> msg.altitude_units
>>> msg.geo_sep
>>> msg.geo_sep_units
>>> msg.age_gps_data
>>> msg.ref_station_id

Additional properties besides the ones explicitly in the message data may also exist.

For example, latitude and longitude properties exist as helpers to access the geographic coordinates as python floats (DD, "decimal degrees") instead of the DDDMM.MMMM ("Degrees, minutes, seconds") format used in the NMEA protocol. latitude_minutes, latitude_seconds, longitude_minutes, and longitude_seconds are also supported and allow easy creation of differently formatted location strings.

>>> msg.latitude
>>> msg.longitude
>>> '%02d°%07.4f′' % (msg.latitude, msg.latitude_minutes)
>>> '%02d°%02d′%07.4f″' % (msg.latitude, msg.latitude_minutes, msg.latitude_seconds)


You can create a NMEASentence object by calling the constructor with talker, message type, and data fields:

>>> msg = pynmea2.GGA('GP', 'GGA', ('184353.07', '1929.045', 'S', '02410.506', 'E', '1', '04', '2.6', '100.00', 'M', '-33.9', 'M', '', '0000'))

and generate a NMEA string from a NMEASentence object:

>>> str(msg)


pynmea2 can also process streams of NMEA sentences like so, by feeding chunks of data manually:

streamreader = pynmea2.NMEAStreamReader()
while 1:
    data =
    for msg in
        print msg

or given a file-like device, automatically:

    streamreader = pynmea2.NMEAStreamReader(input)
    while 1:
        for msg in
            print msg