TensorFlow APIs for Various Languages

Monday March 20, 2017

You couldn't be blamed for thinking that TensorFlow is a Python package. And a lot of TensorFlow functionality is unique to Python. But the core of TensorFlow—the part of TensorFlow that most truly is TensorFlow—is the distributed runtime ("TensorFlow Distributed Execution Engine") and Python is just one way to talk to it.

TensorFlow three-tier diagram

(Image from the TensorFlow Dev Summit 2017 keynote.)

The runtime itself is written in C++, but it has APIs ("frontends") in many languages.


C

The only TensorFlow APIs with any official stability are the C API and (parts of) the Python API.

TensorFlow suggests that you use the C API if you are making a TensorFlow API for some other language. Lots of programming languages have mechanisms for connecting with C. In a very real sense the TensorFlow C API exists so that other APIs can be built.

There are a number of non-Python languages with TensorFlow APIs but for the most part I will consider them "deploy only" ("inference only") and largely ignore them.

C programming language


C++

The C++ API is "exposed through header files in tensorflow/cc" and C++ is the language that the TensorFlow runtime is written in, but the C++ API is still marked as experimental and has fewer features than are accessible via the Python API. It may be where you want to be for some deploy scenarios.

As a possibly interesting historical note, the MapReduce paper was another place where the world saw Google (and Jeff Dean) making something cool with C++. Yahoo! (and others) eventually implemented those concepts in Java, as Hadoop. Google seems to continue to do a lot of work in C++.

C++ programming language


Java

Possibly recognizing Java's presence in industry, TensorFlow now has a Java API.

Java programming language


Go

Go is a Google programming language, and so it seems appropriate that there is a Go API for TensorFlow.

Go programming language


Rust

Rust is a neat language, and it has a TensorFlow api too (docs).

Rust programming language


Haskell

Haskell is not a language I would have guessed would have a TensorFlow API, but it does (docs).

Haskell programming language


C

Also C#!

C#


Julia

Also Julia!

Julia


Python

Python is where the action is. TensorFlow's Python API documentation is headed simply "All symbols in TensorFlow" and it really does seem to be that TensorFlow functionality is prototyped in Python and then moved into the C++ core:

Python was the first client language supported by TensorFlow and currently supports the most features. More and more of that functionality is being moved into the core of TensorFlow (implemented in C++) and exposed via a C API.

The Python API is so rich, you'll have to choose which levels of Python API you'll want to use.

Python programming language


R

The R TensorFlow API made by RStudio takes a different approach than the APIs that use TensorFlow's C API to connect with TensorFlow. The R API (on github) wraps the entire Python API. This is not exactly what the TensorFlow project recommends, but it gives R users access to all the features in the Python API, which would be quite a lot of work to replicate using only the C API.

R programming language


Thanks to Kevin Ushey for directing me to the right venue, and to @jjallaire and @pourzanj for an illuminating discussion about the R TensorFlow API.

I'm working on Building TensorFlow systems from components, a workshop at OSCON 2017.