title: Retrieve hash for commit in a python script from a bitbucket server
body: <p>I would like to know if it is possible to retrieve the hash of a commit in a Python script.</p>
  <p>For a given script, I can easily determine the hash of a blob by using the simple formula and code as e.g:</p>
  <pre><code>from sys import argv
  from hashlib import sha1
  from cStringIO import StringIO
  
  class githash(object):
      def __init__(self):
          self.buf = StringIO()
  
      def update(self, data):
          self.buf.write(data)
  
      def hexdigest(self):
          data = self.buf.getvalue()
          h = sha1()
          h.update(&quot;blob %u\0&quot; % len(data))
          h.update(data)
  
          return h.hexdigest()
  
  def githash_data(data):
      h = githash()
      h.update(data)
      return h.hexdigest()
  
  def githash_fileobj(fileobj):
      return githash_data(fileobj.read())
  
  
  if __name__ == '__main__':
      for filename in argv[1:]:
          fileobj = file(filename)
          print(githash_fileobj(fileobj))
  </code></pre>
  <p><a href="https://gist.github.com/msabramo/763200" rel="nofollow noreferrer">Source</a></p>
  <p>However, this method of calculating the same hash as git does for a given file doesn't seem to work for a complete commit. The formula described <a href="https://stackoverflow.com/questions/35430584/how-is-the-git-hash-calculated">here</a> by VonC isn't clear to me. Is there a way to either calculate this commit hash in python or retrieve it directly from the bitbucket server?</p>
  <p>Edit: I just discovered <a href="https://github.com/cosmin/stashy" rel="nofollow noreferrer">Stashy</a>. I will look into this.</p>