0

How can I parse .sketch files generated by sketch - mac application?

I know that psd_tools can be used to parse .psd files generated in Adobe Photoshop.

3
  • Unforunately, googling "python sketch" doesn't give anything useful. Unless you're looking for a laugh... :-)
    – alexis
    Sep 6, 2015 at 0:30
  • That's true for sure :D
    – Bhartendu
    Sep 6, 2015 at 9:21
  • Sketch support CocoaScript plugin. You can make a plugin and export sketch contents.
    – Nickolas
    Mar 23, 2016 at 15:18

3 Answers 3

6

I don't have any experience with Sketch, but I downloaded a sample .sketch file and it turned out to be an "SQLite 3.x database". This means you can open it with python's sqlite3 module.

As it happens I had some code lying around that I wrote to inspect another sqlite database, so I took a look: It contains a metadata table and a "payload" table (called metadata and payload, respectively), both of which have just name and value columns. However, the payload table has just one row, and in both tables the values seem to be containers in some other format I don't recognize. So although sqlite3 is the file format, it appears that it is just the outer layer of the onion.

9
  • Well that's a start. Thanks a lot. Will look into it and update my findings here as soon as I can.
    – Bhartendu
    Sep 6, 2015 at 14:07
  • Hey! I cross checked the info that you gave and I think you hit the spot. The data in payload table and in the metadata table are of blob format. A Binary Large OBject (BLOB) is basically a collection of binary data stored as a single entity in a database management system, typically images, audio or any other multimedia file and in this case image layers. I think it can be easily parsed into json format. I am marking your answer as the correct one. Cheers and thanks for pointing me in the right direction!
    – Bhartendu
    Sep 6, 2015 at 17:37
  • Glad to hear it! And thanks for the follow-up information. If you get working code that can convert the file to json (and maybe back), please consider posting it here. You can expect others to have the same question in the future.
    – alexis
    Sep 6, 2015 at 18:13
  • Yeah sure, will do. As soon as I am done writing the script will post the github link here!
    – Bhartendu
    Sep 7, 2015 at 9:05
  • Any news about hacking .sketch files? Mar 8, 2016 at 14:40
1

Edit: The new sketch file format (> 43) is super friendly. It's actually a zip folder in which you have the assets and json files which describe the contents. http://sketchplugins.com/d/87-new-file-format-in-sketch-43

2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Jul 30, 2017 at 22:16
  • @lu.koerfer thanks you, I have fixed my answer. btw, I understood the problem after Petter explained it.
    – Amirc
    Jul 30, 2017 at 22:18
0

Especially as I am unfamiliar with Sketch I do not know of any equivalents to psd_tools. However, this question might help you. Otherwise, you might need to create your own parser.

1
  • Thanks for the help, but what I am looking for is a module specifically in python to parse the .sketch file data not to convert it. Have been searching on internet for a while now but have come across only framerJs which is in coffeescript.
    – Bhartendu
    Sep 5, 2015 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.