Skip to content

Instantly share code, notes, and snippets.

@tvogels
Created May 10, 2022 06:39
Show Gist options
  • Save tvogels/e86b06bde411354df507203ede1fa5ad to your computer and use it in GitHub Desktop.
Save tvogels/e86b06bde411354df507203ede1fa5ad to your computer and use it in GitHub Desktop.
Read a Sketch file in Python
import tempfile
from zipfile import ZipFile
import hashlib
import json
zipf = ZipFile("slides.sketch")
with tempfile.TemporaryDirectory() as d:
for file in zipf.infolist():
if file.filename.startswith("pages/"):
outfile = zipf.extract(file.filename, d)
with open(outfile, "r") as fp:
layers = json.load(fp)["layers"]
for layer in layers:
print(layer["name"])
print(hashlib.md5(json.dumps(layer).encode("utf-8")).hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment