mattn/go-tflite: a cgo binding that keeps TensorFlow Lite's C API in Go's hands
Go binding for TensorFlow Lite
At a glance
- What is it?
- go-tflite wraps the TensorFlow Lite C API rather than reimplementing an interpreter, so your build depends on libtensorflowlite_c.so and a C API version compatible with the binding. It suits Go services that already ship a .tflite file and want inference in-process.
- Who is it for?
- Adopt go-tflite if your deployment already ships libtensorflowlite_c.so and you want inference inside a Go process without a separate runtime. It is not a pure-Go runtime: check that the TensorFlow Lite C API library and headers are compatible with your chosen binding release and target platform.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 55 days ago.
- What is it written in?
- Mainly Jupyter Notebook, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- mattn/go-tflite323 ★ · +1
| Repository | 2026-09-11 | 2026-11-15 |
|---|---|---|
| mattn/go-tflite | 322 | 323 |
1 Stars in the last 65 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The gap go-tflite fills: Go code that needs to call an existing .tflite file
TensorFlow Lite is distributed as a C library plus a set of language bindings built on top of it. Go is not one of the first-class targets. go-tflite exists to close that gap: it is a cgo binding, which means Go code calls into the TensorFlow Lite C API through libtensorflowlite_c.so instead of through a reimplementation of the interpreter in Go. The README states the scope plainly: go-tflite links against libtensorflowlite_c.so only, so there is no need to build the full TensorFlow library. That single sentence defines the audience. This is for teams that already have a trained model exported to the .tflite format and want to run inference from a Go binary, typically a service or a CLI tool, without standing up a Python process or a separate inference server. The typical caller is a Go backend that owns the request path and does not want a network hop to a model server. The repository also ships an iris.ipynb notebook and a Binder badge so the binding can be tried in a browser without a local install, and the same image is published as ghcr.io/mattn/go-tflite/gophernotes. That is a low-friction way to read the API before committing to a cgo build. What go-tflite is not: a trainer, a model converter, or a pure-Go runtime. If you need to produce the .tflite file itself, that work happens elsewhere.
What the interpreter lifecycle looks like in Go
The README's usage example is short and shows the whole shape of the API. You load a model with tflite.NewModelFromFile, create options with tflite.NewInterpreterOptions, construct an interpreter with tflite.NewInterpreter, call AllocateTensors, write into the input tensor, call Invoke, and read the output tensor. Every one of those constructors returns a value that carries its own Delete method, and the example defers their Delete calls; it checks the model for nil. That pattern is not decoration. These are handles to C-side allocations, and the binding exposes explicit lifetime management rather than relying on a finalizer. If you forget model.Delete() or interpreter.Delete(), you leak the underlying TensorFlow Lite objects. The tensor accessors are typed: the example uses input.Float32s() to get a slice it can index into, and GetOutputTensor(0).Float32s()[0] to read the result. The example model is a sine approximation, and the input is converted with float64(1.2) * math.Pi / 180.0 before being stored as a float32. That detail is worth noting: the binding hands you the underlying slice, so you are responsible for writing values in the layout the model expects. The snippet does not check tensor shape or the status returned by `AllocateTensors` and `Invoke`; production code should validate both before using the output. The README also points to the _example directory for more examples, which is where you would look for anything beyond the single-input, single-output case.
Building libtensorflowlite_c.so and pointing cgo at it
The project's current README says CI builds and tests against TensorFlow v2.17.1 and that other recent versions may work when their C API is compatible. Check the documentation for the binding version you actually select, since requirements can change between releases.
The project publishes prebuilt buildkits containing the C API library and headers for several Linux, macOS and Windows targets. It also documents building the library from TensorFlow sources with Bazel or CMake. The CMake route includes XNNPACK in the library; applications using its XNNPACK delegate need the documented `xnnpack_builtin` build tag.
When headers or libraries are outside standard locations, set `CGO_CFLAGS` to the header include directory and `CGO_LDFLAGS` to the library directory. On Linux, the runtime loader may also need `LD_LIBRARY_PATH` or an appropriate system library configuration. Build a repository example to test linking, then load a `.tflite` model file separately at runtime. Edge TPU support requires the additional delegate libraries and headers described in the README.
The cgo toolchain is the adoption cost, not the API
The Go code in the README is a dozen lines. The build is the hard part. Three separate things have to line up: the version of the TensorFlow Lite C library, the include path in CGO_CFLAGS, and the link path in CGO_LDFLAGS. Get the version wrong and you are linking against an API the binding does not match. The current README identifies TensorFlow v2.17.1 as the version exercised in CI and advises checking C API compatibility for other versions. This also means your build is not portable by default. A Go binary that links a shared object is not the same as a static Go binary you can copy to another machine. The README's own instructions put the library in /usr/local/lib, a system-wide path, which tells you what the deployment model looks like: the shared object ships alongside the binary, or is installed on the host. If your team's whole reason for choosing Go is single-binary deployment with no runtime dependencies, this binding works against that goal. The Edge TPU path adds another shared object and another header set, so the deployment surface grows again. None of this is a defect in the binding. It is the direct consequence of choosing to call the C API rather than reimplement it, and the trade is explicit: you get the upstream interpreter's behaviour instead of a partial Go rewrite. Retest the binding and application when changing either the C library or the Go binding, particularly across C API changes.
Where calling into cgo is the wrong answer
If your model runs comfortably in a Go process with no C dependency, a pure-Go inference path avoids the shared-object problem entirely. The clearest example is the class of models that are just arithmetic over float32 slices: small regressions, fixed-shape classifiers, or the sine model in the README. Writing that forward pass in Go is a few dozen lines, it compiles to a static binary, and it never has to be rebuilt because a C library changed its ABI. The difference in approach is not performance, it is dependency shape. go-tflite gives you the TensorFlow Lite interpreter, its kernel implementations, and its delegate support, at the cost of a cgo build and a compatible shared library. A hand-written Go forward pass gives you a static binary and no version coupling, at the cost of supporting only the operators you implement. For anything with convolutions, quantization, or a model you did not design yourself, the hand-written route stops being reasonable quickly, and that is exactly when go-tflite becomes the better choice. A team also needs a compatible C library for its deployment platform. Prebuilt buildkits may avoid a local TensorFlow build on supported targets; otherwise the README documents Bazel and CMake routes. Check the available artifacts and your deployment constraints before adopting the binding.
Licence, releases, and what you inherit
go-tflite is MIT licensed, which is permissive and imposes few obligations on the binding's own source. That covers the Go code in this repository. It does not cover TensorFlow Lite itself, which you build and link separately, or the Edge TPU libraries from google-coral/edgetpu, which have their own terms. If you distribute a binary that links libtensorflowlite_c.so, the licence that matters for that shared object is the one attached to the TensorFlow Lite build you produced, not the MIT licence on the binding. This is not legal advice; check the terms of the components you actually ship. On release cadence, the repository shows v1.0.7 and v1.0.6 in August 2026 and v1.0.5 tagged buildkit-20240529 in May 2024, so the version tags do not map cleanly onto a fixed schedule. Pin a specific tag rather than tracking the default branch if reproducibility matters to you. The primary language listed for the repository is Jupyter Notebook, which reflects the iris.ipynb notebook and the Binder setup rather than the binding itself; the Go source and the cgo layer are what you compile. That mismatch is worth knowing before you judge the project by its language breakdown.
Editorial conclusion
Adopt go-tflite if your deployment already ships libtensorflowlite_c.so and you want inference inside a Go process without a separate runtime. It is not a pure-Go runtime: check that the TensorFlow Lite C API library and headers are compatible with your chosen binding release and target platform. Before writing application code, install a compatible prebuilt buildkit or build the C library, configure cgo paths if needed, and build an example. Load the separate `.tflite` model file at runtime as shown in the README.
Frequently asked questions
What is go-tflite and what does it need to build?
go-tflite is a Go binding for the TensorFlow Lite C library. It links against one shared library and does not require the full TensorFlow framework, and it needs cgo, a Go toolchain, and the C library's headers. Continuous integration builds and tests against one named version of TensorFlow, and the readme says other recent versions work as long as the C interface stays compatible.
Is TensorFlow Lite free, and does go-tflite add any cost?
The binding is released under the MIT licence, and the readme describes no paid component, no hosted service, and no usage limit. The build path is entirely local: a prebuilt archive of headers and the C library, or a build from the TensorFlow source tree. The accelerated delegate libraries ship in the prebuilt archives for Linux and macOS, and the accelerator support requires libraries installed separately from a hardware vendor's repository.
How do I install the TensorFlow Lite C library for go-tflite?
Each release ships an archive of headers and the C library for five targets, and the readme shows extracting it into the system prefix and refreshing the linker cache on Linux. Alternatively you can run the repository's own build script to produce those archives for a different TensorFlow version, or build the C library with cmake from a TensorFlow source checkout. There is also a plain makefile in the repository root, which the readme says is not regularly tested.
Does go-tflite support the XNNPACK delegate, and what is the build tag for?
Yes, and the tag exists because of how the delegate is packaged. The delegate has no shared library target upstream, so the repository's build script adds one. The prebuilt archives for Linux and macOS ship the delegate as a separate library, while the cmake route compiles it into the main shared object, which is why programs built that way are told to use a specific tag so that only the main library is linked.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/mattn-go-tflite)Star history chart for your README
[](https://hysenlabs.com/projects/mattn-go-tflite)Was this useful?