Unfold is implemented in C in here 256. It only performs size/strides modifications, so it can be performed in python without issues.
Also, note that unfold supports backpropagation, so there might be no need to implement it yourself.