Skip to content


Repository files navigation

What is KnitScript?

KnitScript is a computer language that helps you design knitting patterns more easily. In KnitScript, patterns are composed of sub-patterns that let you describe which textures go where and how big those textures should be, instead of working at the level of individual stitch-by-stitch instructions. Of course, you can also define patterns by writing out the stitches row-by-row, so you aren't limited to the textures that come with KnitScript.

This KnitScript program describes a pattern with stockinette stitch, seed stitch, ribbing, and the slipped waves texture in each of the four corners, surrounded by a garter stitch border:

pattern squares
  fill (slippedWaves, 8, 8), fill (stst, 8, 8).
  fill (seed, 8, 8), fill (rib (1, 1), 8, 8).

show (standalone (garterBorder (squares, 4, 2)))

Running this program gives you these instructions that you can use to knit the pattern:

WS: CO 20. (20 sts)
RS: K 20. (20 sts)
rep from ** 4 times
RS: K 20. (20 sts)
WS: K 2, [K, SL] 4, P 8, K 2. (20 sts)
RS: K 20. (20 sts)
WS: K 2, [SL, K] 4, P 8, K 2. (20 sts)
rep from ** 2 times
RS: K 2, [K, P] 4, [K, P] 4, K 2. (20 sts)
WS: K 2, [P, K] 4, [K, P] 4, K 2. (20 sts)
rep from ** 4 times
RS: K 20. (20 sts)
rep from ** 4 times
RS: *BO; rep from * to end. (0 sts)

And knitting from the instructions gives you this. :)

Photo of the pattern after being knit

KnitScript verifies that every pattern is correct. If the pattern runs out of stitches, has too many stitches left over, or uses a stitch incorrectly, KnitScript will tell you what the problem is.

Read the KnitScript tutorial and watch the demo video to learn more, and download the KnitScript editor for Windows or Mac to start creating your own patterns. For more information, see the language reference page.

Further Reading

KnitScript started as a student project in the spring of 2019 for CSE 402, a class at the University of Washington about domain-specific languages. You can read our reports and poster slides here:

KnitScript was inspired by other knitting languages like Purl, KP and Knitting Visualizer.

Source Code

To run KnitScript using the source code in this repository, you need:

  • Python 3.7 or later
  • ANTLR 4
    • Either antlr4 or antlr should be in your PATH. This should happen automatically if you install ANTLR using Homebrew on Mac or Chocolatey on Windows.
    • The antlr4-python3-runtime package should be installed using pip.

Before running KnitScript for the first time, or after changing the KnitScript.g4 grammar file, run python build.

To run a KnitScript program, run python -m knitscript <filename>. If you run python develop, you can also run KnitScript programs using knitscript <filename>.


KnitScript is an open source project that is released under the MIT License.


A language for easier design of knitting patterns







No packages published