InstructionLibrary Module

Instructions have many attributes that do not need to be specified in each knitting pattern set.

This module provides the functionality to load default values for instructions from various locations.

class knittingpattern.InstructionLibrary.InstructionLibrary[source]

Bases: object

This library can be used to look up default specification of instructions.

The specification is searched for by the type of the instruction.

Returns:the specification for instruction_type

See also



Create a new InstructionLibrary without arguments.

Use load to load specifications.


list of weak references to the object (if defined)


Add an instruction specification

Parameters:specification – a specification with a key knittingpattern.Instruction.TYPE

See also



Convert the specification into an instruction

Parameters:specification – a specification with a key knittingpattern.Instruction.TYPE

The instruction is not added.

Returns:a loader that can be used to load specifications
Return type:knittingpattern.Loader.JSONLoader

A file to load is a list of instructions in JSON format.

        "type" : "knit",
        "another" : "attribute"
        "type" : "purl"

The types loaded in this library.

Returns:a list of types, preferably as string
Return type:list
class knittingpattern.InstructionLibrary.DefaultInstructions[source]

Bases: knittingpattern.InstructionLibrary.InstructionLibrary

The default specifications for instructions ported with this package

INSTRUCTIONS_FOLDER = 'instructions'

the folder relative to this module where the instructions are located


Create the default instruction library without arguments.

The default specifications are loaded automatically form this package.

Returns:a default instruction library
Return type:DefaultInstructions


The return value is mutable and you should not add new instructions to it. If you would like to add instructions to it, create a new DefaultInstructions instance.