knit-script


Nameknit-script JSON
Version 0.1.33 PyPI version JSON
download
home_pagehttps://mhofmann-khoury.github.io/knit_script/
SummaryKnit Script is a domain specific programming language for writing v-bed knitting machine instructions. The language is loosely based on conventions from Python 3 but includes support for controlling a knitting machine. The code is interpreted into knitout which can then be processed into instructions for different types of knitting machines.
upload_time2025-08-21 19:47:41
maintainerMegan Hofmann
docs_urlNone
authorMegan Hofmann
requires_python<3.13,>=3.11
licenseMIT
keywords knit machine knit textile northeastern act lab fabrication knit script domain specific language dsl
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # knit-script

[![PyPI - Version](https://img.shields.io/pypi/v/knit-script.svg)](https://pypi.org/project/knit-script)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/knit-script.svg)](https://pypi.org/project/knit-script)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Code style: MyPy](https://img.shields.io/badge/type_checker-mypy-blue.svg)](https://mypy-lang.org/)
[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

A high-level domain-specific programming language for writing V-bed knitting machine instructions.
KnitScript provides an intuitive, Python-like syntax for creating complex knitting patterns while automatically generating optimized knitout code for machine execution.

## ๐Ÿงถ Overview

KnitScript is a domain-specific programming language designed to make knitting machine programming accessible and intuitive.
While traditional knitout requires low-level instruction management, KnitScript provides:

- **High-level abstractions** for common knitting patterns
- **Automatic optimization** of needle operations and carriage passes
- **Python-like syntax** familiar to programmers
- **Multi-sheet support** for complex fabric structures
- **Comprehensive error handling** with detailed diagnostics

The language compiles to standard knitout format, making it compatible with any machine that supports the knitout specification.

## ๐Ÿš€ Key Features

### Language Design
- โœ… **Python-inspired syntax** with knitting-specific extensions
- โœ… **Variable scoping** with local, global, and function scopes
- โœ… **Control flow** including loops, conditionals, and functions
- โœ… **Module system** for code organization and reuse

### Knitting Capabilities
- ๐Ÿงถ **Automatic gauge management** for multi-sheet knitting
- ๐Ÿ“ **Sheet peeling and organization** for complex fabric structures
- ๐Ÿ”„ **Carrier management** with automatic activation/deactivation
- ๐ŸŽฏ **Direction-aware operations** with optimal carriage pass planning

### Development Experience
- ๐Ÿ› **Comprehensive error messages** with line numbers and context
- ๐Ÿ“Š **Execution analysis** with timing and resource usage
- ๐Ÿ“š **Standard library** with common knitting operations

### Machine Integration
- ๐Ÿ–ฅ๏ธ Built on [virtual-knitting-machine](https://pypi.org/project/virtual-knitting-machine/) for simulation
- ๐Ÿ“ค Generates standard [knitout](https://textiles-lab.github.io/knitout/knitout.html) output
- ๐Ÿ”ง Supports Shima Seiki Whole Garment knitting machines
- ๐Ÿ“ˆ Creates [knit-graphs](https://pypi.org/project/knit-graphs/) for fabric analysis

## ๐Ÿ“ฆ Installation

### From PyPI (Recommended)
```bash
pip install knit-script
```

### From Test-PyPi
If you wish to install an unstable release from test-PyPi, note that this will have dependencies on PyPi repository.
Use the following command to gather those dependencies during install.
```bash
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ knitout-interpreter
```

### From Source
```bash
git clone https://github.com/your-username/knit-script.git
cd knit-script
pip install -e .
```

### Development Installation
```bash
git clone https://github.com/your-username/knit-script.git
cd knit-script
pip install -e ".[dev]"
pre-commit install
```

## ๐Ÿƒโ€โ™‚๏ธ Quick Start

### Basic Pattern Creation
```knitscript
width = 10; // Basic variable declaration
with Carrier as c1:{ // Carrier is a reserved variable used to set the active working carrier in the code.
  in Leftward direction:{  // Directed Carriage pass statements are used to specify the direction of multiple needle operations.
    tuck Front_Needles[0::width]; // tucks are applied to a given list of needles on the front bed.
  }
  in reverse direction:{ // the reverse keyword is used to keep track of the relative direction of the carriage.
    tuck Front_Needles[1:width];
  }
  for _ in range(10):{ // python functions like range can be used as they would in python code.
    in reverse direction:{
      knit Loops; // Loops variables keep track of the current set of needles holding stitches.
    }
  }
}
cut c1; // The cut operation will outhook the given carrier.
```
```python
"""Convert a simple KnitScript pattern to knitout"""
from knit_script import knit_script_to_knitout

# Convert to knitout
knit_graph, machine = knit_script_to_knitout( pattern="stockinette.ks", out_file_name="stockinette.k", pattern_is_filename=False)
```

### Patterns with Arguments from Python
```knitscript
with Carrier as c1:{ // Carrier is a reserved variable used to set the active working carrier in the code.
  in Leftward direction:{  // Directed Carriage pass statements are used to specify the direction of multiple needle operations.
    tuck Front_Needles[0::width]; // tucks are applied to a given list of needles on the front bed.
  }
  in reverse direction:{ // the reverse keyword is used to keep track of the relative direction of the carriage.
    tuck Front_Needles[1:width];
  }
  for _ in range(height):{ // python functions like range can be used as they would in python code.
    in reverse direction:{
      knit Loops; // Loops variables keep track of the current set of needles holding stitches.
    }
  }
}
cut c1; // The cut operation will outhook the given carrier.
```
```python
"""Convert a simple KnitScript pattern to knitout"""
from knit_script import knit_script_to_knitout

# Convert to knitout
knit_graph, machine = knit_script_to_knitout( pattern="stockinette.ks", out_file_name="stockinette.k", pattern_is_filename=False,
                                              width=10, height=10)
```
Variables from the python environment can be directly loaded into the file, allowing for parameterized runs of the code.


## Language Features

#### Common Python Types
You can create common variables of the basic types of pythons using basic syntax.
```knitscript
width = 20; // ints
height = 10.5; // floats
yarn_color = "blue"; // string
is_finished = True; // bools
pattern_list = [2, 4, 2, 4]; // lists
pattern_dict = {"a": 1, "b": 2}; // dictionaries
```
#### Functions
You can create functions similar to those in Python. Functions include arguments which can have defined defaults.
```knitscript
def alt_tuck_cast_on(width = 10):{
    in Leftward direction:{
      tuck Front_Needles[0::width];
    }
    in reverse direction:{
      tuck Front_Needles[1:width];
    }
}

with Carrier as c1:{
  alt_tuck_cast_on(12); // call to function like a python function
}
```

### Machine Integration

#### Automatic Carrier Management
Changing the "Carrier" variable will declare what carrier or carrier set is being used by subsequent operations.
There is no need to specify inhooks to bring in carriers, if the active carrier is not already inhooked, it will be inhooked when it is next used.
```knitscript
Carrier = c1;
```

Carriers do need to manually be released. Calling "releasehook;" will release any carrier on the yarn-inserting-hook. If there is no hooked carrier, this is a safe no-op.
```knitscript
with Carrier as c1:{
  alt_tuck_cast_on(12);
  releasehook; // The carrier is relaeased if it is in on the yarn inserting hook
}
```

#### Direction and Racking Control
```knitscript
# Direction control
direction = rightward
knit direction  # Uses current direction

# Racking for transfers
racking = 1.0
xfer front_needles 2 right to back
```

#### Multi-Sheet Gauge Support
Sheets and Gauges are used for automatic support of layered knitting where each sheet has loops kept in their own relative layer order.

For example, it can be a useful way to create a ribbed tube without tracking transfers needed to keep the back and front of the tube untangled.
```knitscript
with Carrier as c1, Gauge as 2:{ // set the working gauge to 2 sheets
  With Sheet as s0: { // localize knitting operations to only the first sheet of fabric
    in Leftward direciton:{ // set up the rib pattern on the front of the tube.
      knit Front_Needles[0:width:2];
      knit Back_Needles[1:width:2];
    }
  }
  With Sheet as s1: { // The loops in this sheet will, by default, fall behind those in s0.
    in reverse direciton:{ // directions are not specific to a sheet, but the whole program
      knit Front_Needles[0:width:2]; // these needles will not overlap those in sheet s0.
      knit Back_Needles[1:width:2];
    }
  }
  for _ in range(height):{
    with Sheet as s0:{
      in reverse direction:{ knit Loops;} // these will only be the loops on s0.
    }
    with Sheet as s1:{
      in reverse direction: {knit Loops;} // these will only be the loops on s1
    }
  }
}
```

The relative position of sheets are controlled by their layer at each needle.
For example, we can divide this tube at the halfway point using a push statement.
```knitscript
with Carrier as c1, Gauge as 2:{ // set the working gauge to 2 sheets
  With Sheet as s0: { // localize knitting operations to only the first sheet of fabric
    push Front_Needles[0:width/2] to back; // make the first half of this sheet fall behind other sheets in this region.
    in Leftward direciton:{ // set up the rib pattern on the front of the tube.
      knit Front_Needles[0:width:2];
      knit Back_Needles[1:width:2];
    }
  }
  With Sheet as s1: { // The loops in this sheet will fall behind s0 from width/2 and then in front for the remaining needles.
    in reverse direciton:{ // directions are not specific to a sheet, but the whole program
      knit Front_Needles[0:width:2]; // these needles will not overlap those in sheet s0.
      knit Back_Needles[1:width:2];
    }
  }
  for _ in range(height):{
    with Sheet as s0:{
      in reverse direction:{ knit Loops;} // these will only be the loops on s0.
    }
    with Sheet as s1:{
      in reverse direction: {knit Loops;} // these will only be the loops on s1
    }
  }
}
```

## ๐Ÿ“– Language Reference

### Basic Syntax

KnitScript follows Python conventions with knitting-specific extensions:

```knitscript
// Comments are denoted by two back-slashes (like java or javascript).

// Variable assignment
stitch_count = 40
gauge_setting = 14

// String formatting using python style f strings.
print f"Knitting {stitch_count} stitches at gauge {gauge_setting}";

// Containers are indexed or sliced using python style notation
needles = Front_Needles[0:20:2]; // every other needle starting at 0 and up to 19
first_needle = needles[0]
```

### Variables and Scoping

```knitscript
// Local variables in functions
def knit_section(rows):{ // the rows parameter is local to the function scope.
    row_count = 0;
    for i in range(rows):{
        in reverse direction:{
          knit Loops; // machine scope keywords like "reverse" and "Loops" are not localized to the function.
        }
        row_count = row_count + 1;
    }
    return row_count; // functions can return
}

// Machine state variables
Gauge = 2;        // Number of sheets available to work with.
Sheet = 0;        // The sheet to localize operations to.
Carrier = 1;      // Active carrier
Racking = 0.0;    // Bed alignment
```

### Control Flow

```knitscript
// Conditionals
if stitch_count > 20:{ print "first branch";}
else: {print "second branch";}

// While loops
row = 0
while row < total_rows:{
    row += 1
}

// For loops with ranges
for row in range(10):{
    in reverse direction:{
      knit Loops;
    }
}

# For loops with collections
for needle in front_needles:{
  print needle;
}
```

### Machine Operations

```knitscript
# Basic stitching operations
in reverse direction:{ // The given instructions will be executed in the given direction order, regarless of the list order.
  knit knits; // give it a list of needles to knit
  tuck tucks; // give it a list of needles to tuck
  split splits; // give it a list of needles to split
}

# Transfer operations
xfer Front_Loops across to back bed; // transfer all loops on the front bed to the back bed.
xfer Loops across to back bed; // transfer all loops to the back bed if they are not already there.
xfer Front_Loops 2 to Right to back bed; // transfer all loops on the front bed to the back bed with a righward 2 needle offset.
xfer Front_Loops across to sliders; // transfer to sliders on back bed.

# Drop operations
drop Front_Needles[0:5]; // Drop specific needles
drop Back_Loops // Drop all back needles with loops

# Carrier operations
cut 1;  // Cut carrier 1 with an outhook operation
releasehook; // Release yarn hook
```

## ๐Ÿ“š Standard Library

KnitScript includes a standard library which we continue to expand with common functionality such as cast-ons, bind-offs, and helper functions.

## ๐Ÿ“‹ Dependencies

### Runtime Dependencies
- `python` >= 3.9
- `parglare` ^0.18.0 - Parser generator for KnitScript grammar
- `knit-graphs` ^0.0.6 - Knitting graph data structures
- `virtual-knitting-machine` ^0.0.13 - Virtual machine simulation
- `knitout-interpreter` ^0.0.5 - Knitout processing and execution

### Development Dependencies
- `mypy` ^1.0.0 - Static type checking
- `pytest` ^7.0.0 - Testing framework
- `pre-commit` ^3.0.0 - Code quality hooks
- `sphinx` ^5.0.0 - Documentation generation
- `black` ^22.0.0 - Code formatting

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- **McCann et al.** for creating the [Knitout specification](https://textiles-lab.github.io/knitout/knitout.html) that serves as our compilation target.
- **Northeastern University ACT Lab** for supporting this research and development.
- **The knitting community** for inspiration and feedback on language design.
- This work has been supported by the following NSF Grants:
  - 2341880: HCC:SMALL:Tools for Programming and Designing Interactive Machine-Knitted Smart Textiles.
  - 2327137: Collaborative Research: HCC: Small: End-User Guided Search and Optimization for Accessible Product Customization and Design.

## ๐Ÿ“š Related Projects

### Northeastern ACT Lab Knitting Ecosystem
- [knit-graphs](https://pypi.org/project/knit-graphs/) - Knitting graph data structures and analysis
- [virtual-knitting-machine](https://pypi.org/project/virtual-knitting-machine/) - Virtual machine simulation
- [knitout-interpreter](https://pypi.org/project/knitout-interpreter/) - Knitout processing and execution
- [koda-knitout](https://pypi.org/project/koda-knitout/) - Optimization framework for knitout

### CMU Textiles Lab
- [knitout](https://github.com/textiles-lab/knitout) - Original knitout specification and tools
- [knitout-frontend-js](https://github.com/textiles-lab/knitout-frontend-js) - JavaScript knitout frontend

## ๐Ÿ”— Links

- **PyPI Package**: https://pypi.org/project/knit-script/
- **Documentation**: https://mhofmann-khoury.github.io/knit_script/
- **Source Code**: https://github.com/mhofmann-Khoury/knit_script
- **Issue Tracker**: https://github.com/mhofmann-Khoury/knit_script/issues


**Made with โค๏ธ and ๐Ÿงถ by the Northeastern University ACT Lab**

            

Raw data

            {
    "_id": null,
    "home_page": "https://mhofmann-khoury.github.io/knit_script/",
    "name": "knit-script",
    "maintainer": "Megan Hofmann",
    "docs_url": null,
    "requires_python": "<3.13,>=3.11",
    "maintainer_email": "m.hofmann@northeastern.edu",
    "keywords": "knit, machine knit, textile, Northeastern, ACT Lab, fabrication, knit script, domain specific language, DSL",
    "author": "Megan Hofmann",
    "author_email": "m.hofmann@northeastern.edu",
    "download_url": "https://files.pythonhosted.org/packages/03/9b/bb67e0f397ca9a589754630b1a541252707b5c726f752f4190cdfc233a22/knit_script-0.1.33.tar.gz",
    "platform": null,
    "description": "# knit-script\n\n[![PyPI - Version](https://img.shields.io/pypi/v/knit-script.svg)](https://pypi.org/project/knit-script)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/knit-script.svg)](https://pypi.org/project/knit-script)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Code style: MyPy](https://img.shields.io/badge/type_checker-mypy-blue.svg)](https://mypy-lang.org/)\n[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n\nA high-level domain-specific programming language for writing V-bed knitting machine instructions.\nKnitScript provides an intuitive, Python-like syntax for creating complex knitting patterns while automatically generating optimized knitout code for machine execution.\n\n## \ud83e\uddf6 Overview\n\nKnitScript is a domain-specific programming language designed to make knitting machine programming accessible and intuitive.\nWhile traditional knitout requires low-level instruction management, KnitScript provides:\n\n- **High-level abstractions** for common knitting patterns\n- **Automatic optimization** of needle operations and carriage passes\n- **Python-like syntax** familiar to programmers\n- **Multi-sheet support** for complex fabric structures\n- **Comprehensive error handling** with detailed diagnostics\n\nThe language compiles to standard knitout format, making it compatible with any machine that supports the knitout specification.\n\n## \ud83d\ude80 Key Features\n\n### Language Design\n- \u2705 **Python-inspired syntax** with knitting-specific extensions\n- \u2705 **Variable scoping** with local, global, and function scopes\n- \u2705 **Control flow** including loops, conditionals, and functions\n- \u2705 **Module system** for code organization and reuse\n\n### Knitting Capabilities\n- \ud83e\uddf6 **Automatic gauge management** for multi-sheet knitting\n- \ud83d\udcd0 **Sheet peeling and organization** for complex fabric structures\n- \ud83d\udd04 **Carrier management** with automatic activation/deactivation\n- \ud83c\udfaf **Direction-aware operations** with optimal carriage pass planning\n\n### Development Experience\n- \ud83d\udc1b **Comprehensive error messages** with line numbers and context\n- \ud83d\udcca **Execution analysis** with timing and resource usage\n- \ud83d\udcda **Standard library** with common knitting operations\n\n### Machine Integration\n- \ud83d\udda5\ufe0f Built on [virtual-knitting-machine](https://pypi.org/project/virtual-knitting-machine/) for simulation\n- \ud83d\udce4 Generates standard [knitout](https://textiles-lab.github.io/knitout/knitout.html) output\n- \ud83d\udd27 Supports Shima Seiki Whole Garment knitting machines\n- \ud83d\udcc8 Creates [knit-graphs](https://pypi.org/project/knit-graphs/) for fabric analysis\n\n## \ud83d\udce6 Installation\n\n### From PyPI (Recommended)\n```bash\npip install knit-script\n```\n\n### From Test-PyPi\nIf you wish to install an unstable release from test-PyPi, note that this will have dependencies on PyPi repository.\nUse the following command to gather those dependencies during install.\n```bash\npip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ knitout-interpreter\n```\n\n### From Source\n```bash\ngit clone https://github.com/your-username/knit-script.git\ncd knit-script\npip install -e .\n```\n\n### Development Installation\n```bash\ngit clone https://github.com/your-username/knit-script.git\ncd knit-script\npip install -e \".[dev]\"\npre-commit install\n```\n\n## \ud83c\udfc3\u200d\u2642\ufe0f Quick Start\n\n### Basic Pattern Creation\n```knitscript\nwidth = 10; // Basic variable declaration\nwith Carrier as c1:{ // Carrier is a reserved variable used to set the active working carrier in the code.\n  in Leftward direction:{  // Directed Carriage pass statements are used to specify the direction of multiple needle operations.\n    tuck Front_Needles[0::width]; // tucks are applied to a given list of needles on the front bed.\n  }\n  in reverse direction:{ // the reverse keyword is used to keep track of the relative direction of the carriage.\n    tuck Front_Needles[1:width];\n  }\n  for _ in range(10):{ // python functions like range can be used as they would in python code.\n    in reverse direction:{\n      knit Loops; // Loops variables keep track of the current set of needles holding stitches.\n    }\n  }\n}\ncut c1; // The cut operation will outhook the given carrier.\n```\n```python\n\"\"\"Convert a simple KnitScript pattern to knitout\"\"\"\nfrom knit_script import knit_script_to_knitout\n\n# Convert to knitout\nknit_graph, machine = knit_script_to_knitout( pattern=\"stockinette.ks\", out_file_name=\"stockinette.k\", pattern_is_filename=False)\n```\n\n### Patterns with Arguments from Python\n```knitscript\nwith Carrier as c1:{ // Carrier is a reserved variable used to set the active working carrier in the code.\n  in Leftward direction:{  // Directed Carriage pass statements are used to specify the direction of multiple needle operations.\n    tuck Front_Needles[0::width]; // tucks are applied to a given list of needles on the front bed.\n  }\n  in reverse direction:{ // the reverse keyword is used to keep track of the relative direction of the carriage.\n    tuck Front_Needles[1:width];\n  }\n  for _ in range(height):{ // python functions like range can be used as they would in python code.\n    in reverse direction:{\n      knit Loops; // Loops variables keep track of the current set of needles holding stitches.\n    }\n  }\n}\ncut c1; // The cut operation will outhook the given carrier.\n```\n```python\n\"\"\"Convert a simple KnitScript pattern to knitout\"\"\"\nfrom knit_script import knit_script_to_knitout\n\n# Convert to knitout\nknit_graph, machine = knit_script_to_knitout( pattern=\"stockinette.ks\", out_file_name=\"stockinette.k\", pattern_is_filename=False,\n                                              width=10, height=10)\n```\nVariables from the python environment can be directly loaded into the file, allowing for parameterized runs of the code.\n\n\n## Language Features\n\n#### Common Python Types\nYou can create common variables of the basic types of pythons using basic syntax.\n```knitscript\nwidth = 20; // ints\nheight = 10.5; // floats\nyarn_color = \"blue\"; // string\nis_finished = True; // bools\npattern_list = [2, 4, 2, 4]; // lists\npattern_dict = {\"a\": 1, \"b\": 2}; // dictionaries\n```\n#### Functions\nYou can create functions similar to those in Python. Functions include arguments which can have defined defaults.\n```knitscript\ndef alt_tuck_cast_on(width = 10):{\n    in Leftward direction:{\n      tuck Front_Needles[0::width];\n    }\n    in reverse direction:{\n      tuck Front_Needles[1:width];\n    }\n}\n\nwith Carrier as c1:{\n  alt_tuck_cast_on(12); // call to function like a python function\n}\n```\n\n### Machine Integration\n\n#### Automatic Carrier Management\nChanging the \"Carrier\" variable will declare what carrier or carrier set is being used by subsequent operations.\nThere is no need to specify inhooks to bring in carriers, if the active carrier is not already inhooked, it will be inhooked when it is next used.\n```knitscript\nCarrier = c1;\n```\n\nCarriers do need to manually be released. Calling \"releasehook;\" will release any carrier on the yarn-inserting-hook. If there is no hooked carrier, this is a safe no-op.\n```knitscript\nwith Carrier as c1:{\n  alt_tuck_cast_on(12);\n  releasehook; // The carrier is relaeased if it is in on the yarn inserting hook\n}\n```\n\n#### Direction and Racking Control\n```knitscript\n# Direction control\ndirection = rightward\nknit direction  # Uses current direction\n\n# Racking for transfers\nracking = 1.0\nxfer front_needles 2 right to back\n```\n\n#### Multi-Sheet Gauge Support\nSheets and Gauges are used for automatic support of layered knitting where each sheet has loops kept in their own relative layer order.\n\nFor example, it can be a useful way to create a ribbed tube without tracking transfers needed to keep the back and front of the tube untangled.\n```knitscript\nwith Carrier as c1, Gauge as 2:{ // set the working gauge to 2 sheets\n  With Sheet as s0: { // localize knitting operations to only the first sheet of fabric\n    in Leftward direciton:{ // set up the rib pattern on the front of the tube.\n      knit Front_Needles[0:width:2];\n      knit Back_Needles[1:width:2];\n    }\n  }\n  With Sheet as s1: { // The loops in this sheet will, by default, fall behind those in s0.\n    in reverse direciton:{ // directions are not specific to a sheet, but the whole program\n      knit Front_Needles[0:width:2]; // these needles will not overlap those in sheet s0.\n      knit Back_Needles[1:width:2];\n    }\n  }\n  for _ in range(height):{\n    with Sheet as s0:{\n      in reverse direction:{ knit Loops;} // these will only be the loops on s0.\n    }\n    with Sheet as s1:{\n      in reverse direction: {knit Loops;} // these will only be the loops on s1\n    }\n  }\n}\n```\n\nThe relative position of sheets are controlled by their layer at each needle.\nFor example, we can divide this tube at the halfway point using a push statement.\n```knitscript\nwith Carrier as c1, Gauge as 2:{ // set the working gauge to 2 sheets\n  With Sheet as s0: { // localize knitting operations to only the first sheet of fabric\n    push Front_Needles[0:width/2] to back; // make the first half of this sheet fall behind other sheets in this region.\n    in Leftward direciton:{ // set up the rib pattern on the front of the tube.\n      knit Front_Needles[0:width:2];\n      knit Back_Needles[1:width:2];\n    }\n  }\n  With Sheet as s1: { // The loops in this sheet will fall behind s0 from width/2 and then in front for the remaining needles.\n    in reverse direciton:{ // directions are not specific to a sheet, but the whole program\n      knit Front_Needles[0:width:2]; // these needles will not overlap those in sheet s0.\n      knit Back_Needles[1:width:2];\n    }\n  }\n  for _ in range(height):{\n    with Sheet as s0:{\n      in reverse direction:{ knit Loops;} // these will only be the loops on s0.\n    }\n    with Sheet as s1:{\n      in reverse direction: {knit Loops;} // these will only be the loops on s1\n    }\n  }\n}\n```\n\n## \ud83d\udcd6 Language Reference\n\n### Basic Syntax\n\nKnitScript follows Python conventions with knitting-specific extensions:\n\n```knitscript\n// Comments are denoted by two back-slashes (like java or javascript).\n\n// Variable assignment\nstitch_count = 40\ngauge_setting = 14\n\n// String formatting using python style f strings.\nprint f\"Knitting {stitch_count} stitches at gauge {gauge_setting}\";\n\n// Containers are indexed or sliced using python style notation\nneedles = Front_Needles[0:20:2]; // every other needle starting at 0 and up to 19\nfirst_needle = needles[0]\n```\n\n### Variables and Scoping\n\n```knitscript\n// Local variables in functions\ndef knit_section(rows):{ // the rows parameter is local to the function scope.\n    row_count = 0;\n    for i in range(rows):{\n        in reverse direction:{\n          knit Loops; // machine scope keywords like \"reverse\" and \"Loops\" are not localized to the function.\n        }\n        row_count = row_count + 1;\n    }\n    return row_count; // functions can return\n}\n\n// Machine state variables\nGauge = 2;        // Number of sheets available to work with.\nSheet = 0;        // The sheet to localize operations to.\nCarrier = 1;      // Active carrier\nRacking = 0.0;    // Bed alignment\n```\n\n### Control Flow\n\n```knitscript\n// Conditionals\nif stitch_count > 20:{ print \"first branch\";}\nelse: {print \"second branch\";}\n\n// While loops\nrow = 0\nwhile row < total_rows:{\n    row += 1\n}\n\n// For loops with ranges\nfor row in range(10):{\n    in reverse direction:{\n      knit Loops;\n    }\n}\n\n# For loops with collections\nfor needle in front_needles:{\n  print needle;\n}\n```\n\n### Machine Operations\n\n```knitscript\n# Basic stitching operations\nin reverse direction:{ // The given instructions will be executed in the given direction order, regarless of the list order.\n  knit knits; // give it a list of needles to knit\n  tuck tucks; // give it a list of needles to tuck\n  split splits; // give it a list of needles to split\n}\n\n# Transfer operations\nxfer Front_Loops across to back bed; // transfer all loops on the front bed to the back bed.\nxfer Loops across to back bed; // transfer all loops to the back bed if they are not already there.\nxfer Front_Loops 2 to Right to back bed; // transfer all loops on the front bed to the back bed with a righward 2 needle offset.\nxfer Front_Loops across to sliders; // transfer to sliders on back bed.\n\n# Drop operations\ndrop Front_Needles[0:5]; // Drop specific needles\ndrop Back_Loops // Drop all back needles with loops\n\n# Carrier operations\ncut 1;  // Cut carrier 1 with an outhook operation\nreleasehook; // Release yarn hook\n```\n\n## \ud83d\udcda Standard Library\n\nKnitScript includes a standard library which we continue to expand with common functionality such as cast-ons, bind-offs, and helper functions.\n\n## \ud83d\udccb Dependencies\n\n### Runtime Dependencies\n- `python` >= 3.9\n- `parglare` ^0.18.0 - Parser generator for KnitScript grammar\n- `knit-graphs` ^0.0.6 - Knitting graph data structures\n- `virtual-knitting-machine` ^0.0.13 - Virtual machine simulation\n- `knitout-interpreter` ^0.0.5 - Knitout processing and execution\n\n### Development Dependencies\n- `mypy` ^1.0.0 - Static type checking\n- `pytest` ^7.0.0 - Testing framework\n- `pre-commit` ^3.0.0 - Code quality hooks\n- `sphinx` ^5.0.0 - Documentation generation\n- `black` ^22.0.0 - Code formatting\n\n## \ud83d\udcc4 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## \ud83d\ude4f Acknowledgments\n\n- **McCann et al.** for creating the [Knitout specification](https://textiles-lab.github.io/knitout/knitout.html) that serves as our compilation target.\n- **Northeastern University ACT Lab** for supporting this research and development.\n- **The knitting community** for inspiration and feedback on language design.\n- This work has been supported by the following NSF Grants:\n  - 2341880: HCC:SMALL:Tools for Programming and Designing Interactive Machine-Knitted Smart Textiles.\n  - 2327137: Collaborative Research: HCC: Small: End-User Guided Search and Optimization for Accessible Product Customization and Design.\n\n## \ud83d\udcda Related Projects\n\n### Northeastern ACT Lab Knitting Ecosystem\n- [knit-graphs](https://pypi.org/project/knit-graphs/) - Knitting graph data structures and analysis\n- [virtual-knitting-machine](https://pypi.org/project/virtual-knitting-machine/) - Virtual machine simulation\n- [knitout-interpreter](https://pypi.org/project/knitout-interpreter/) - Knitout processing and execution\n- [koda-knitout](https://pypi.org/project/koda-knitout/) - Optimization framework for knitout\n\n### CMU Textiles Lab\n- [knitout](https://github.com/textiles-lab/knitout) - Original knitout specification and tools\n- [knitout-frontend-js](https://github.com/textiles-lab/knitout-frontend-js) - JavaScript knitout frontend\n\n## \ud83d\udd17 Links\n\n- **PyPI Package**: https://pypi.org/project/knit-script/\n- **Documentation**: https://mhofmann-khoury.github.io/knit_script/\n- **Source Code**: https://github.com/mhofmann-Khoury/knit_script\n- **Issue Tracker**: https://github.com/mhofmann-Khoury/knit_script/issues\n\n\n**Made with \u2764\ufe0f and \ud83e\uddf6 by the Northeastern University ACT Lab**\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Knit Script is a domain specific programming language for writing v-bed knitting machine instructions. The language is loosely based on conventions from Python 3 but includes support for controlling a knitting machine. The code is interpreted into knitout which can then be processed into instructions for different types of knitting machines.",
    "version": "0.1.33",
    "project_urls": {
        "Documentation": "https://mhofmann-khoury.github.io/knit_script/",
        "Homepage": "https://mhofmann-khoury.github.io/knit_script/",
        "Repository": "https://github.com/mhofmann-Khoury/knit_script"
    },
    "split_keywords": [
        "knit",
        " machine knit",
        " textile",
        " northeastern",
        " act lab",
        " fabrication",
        " knit script",
        " domain specific language",
        " dsl"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5dc27feb08c2e289a3435aaf32923cc674e8dc6f26ff49e7fcb5433f13b77bb9",
                "md5": "b482885584f1eaeee056fdae20a24f0a",
                "sha256": "ed1ea6d8d03dd8c995c139f22ab67aa03dc3f47a99c9db54c677c0e63d0f1ea0"
            },
            "downloads": -1,
            "filename": "knit_script-0.1.33-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b482885584f1eaeee056fdae20a24f0a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.11",
            "size": 169850,
            "upload_time": "2025-08-21T19:47:39",
            "upload_time_iso_8601": "2025-08-21T19:47:39.963794Z",
            "url": "https://files.pythonhosted.org/packages/5d/c2/7feb08c2e289a3435aaf32923cc674e8dc6f26ff49e7fcb5433f13b77bb9/knit_script-0.1.33-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "039bbb67e0f397ca9a589754630b1a541252707b5c726f752f4190cdfc233a22",
                "md5": "5fd22e9f94364e2ad8964e82f0a8546b",
                "sha256": "3b49e0ab35153e36ce7bd149cadc106bdb7f201936b8930913b1a209253d1984"
            },
            "downloads": -1,
            "filename": "knit_script-0.1.33.tar.gz",
            "has_sig": false,
            "md5_digest": "5fd22e9f94364e2ad8964e82f0a8546b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.11",
            "size": 122034,
            "upload_time": "2025-08-21T19:47:41",
            "upload_time_iso_8601": "2025-08-21T19:47:41.032089Z",
            "url": "https://files.pythonhosted.org/packages/03/9b/bb67e0f397ca9a589754630b1a541252707b5c726f752f4190cdfc233a22/knit_script-0.1.33.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-21 19:47:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mhofmann-Khoury",
    "github_project": "knit_script",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "knit-script"
}
        
Elapsed time: 3.00405s