import hashlib def sha256(x): return hashlib.sha256(repr(x).encode()).hexdigest() def sha256_file(path): try: with open(path, "rb") as stream: return hashlib.sha256(stream.read()).hexdigest() except FileNotFoundError: return hashlib.sha256(b"").hexdigest()