title: Tensorflow: How to write op with gradient in python?
body: <p>I would like to write a TensorFlow op in python, but I would like it to be differentiable (to be able to compute a gradient).</p>
  
  <p>This question asks how to write an op in python, and the answer suggests using py_func (which has no gradient): <a href="https://stackoverflow.com/questions/37924071/tensorflow-writing-an-op-in-python">Tensorflow: Writing an Op in Python</a></p>
  
  <p>The TF documentation describes how to add an op starting from C++ code only: <a href="https://www.tensorflow.org/versions/r0.10/how_tos/adding_an_op/index.html" rel="nofollow noreferrer">https://www.tensorflow.org/versions/r0.10/how_tos/adding_an_op/index.html</a></p>
  
  <p>In my case, I am prototyping so I don't care about whether it runs on GPU, and I don't care about it being usable from anything other than the TF python API.</p>