Skip to content

rembish/fit

Repository files navigation

fit

Read and write Garmin FIT (Flexible and Interoperable Data Transfer) files from Python.

FIT is a binary format designed for sport, fitness, and health devices. It is compact, interoperable, and extensible — any FIT-compliant device can interpret a FIT file from any other FIT-compliant device.

Installation

python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

Or use the Makefile:

make install

Usage

Reading a FIT file

from fit import FitFile

with FitFile.open("path/to/activity.fit") as f:
    for message in f:
        print(message)

Copying a FIT file

from fit import FitFile

with FitFile.open("path/to/source.fit") as src:
    with FitFile.open("path/to/copy.fit", mode="w") as dst:
        dst.copy(src)

Creating a new FIT file

from fit.files.activity import ActivityFile
from fit.messages.common import FileCreator

fnew = ActivityFile.create("path/to/new.fit")
fnew.append(FileCreator(software_version=100))
fnew.write()
fnew.close()

Reading from a stream

from io import BytesIO
from fit import FitFile

data = open("path/to/activity.fit", "rb").read()
with FitFile.open(BytesIO(data)) as f:
    for message in f:
        print(message)

Development

make install     # create .venv and install all dev dependencies
make format      # run black
make lint        # run ruff
make typecheck   # run mypy
make test        # run pytest with coverage
make tox         # run tests across Python 3.9, 3.10, 3.12
make clean       # remove build artefacts and the virtualenv

License

BSD 3-Clause — see LICENSE.

About

Python FIT filetype SDK

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors