inkex.extensions module

A helper module for creating Inkscape effect extensions

This provides the basic generic types of extensions which most writers should use in their code. See below for the different types.

class inkex.extensions.CallExtension(*args, **kwargs)[source]

Bases: inkex.base.TempDirMixin, inkex.extensions.InputExtension

Call an external program to get the output

call(input_file, output_file)[source]

Call whatever programs are needed to get the desired result.

input_ext = 'svg'

But load certainly is, we give a more exact message here


Create the temporary directory

output_ext = 'svg'
class inkex.extensions.ColorExtension[source]

Bases: inkex.extensions.EffectExtension

A standard way to modify colours in an svg document.

_modify_color(name, color)[source]

Pre-process color value to filter out bad colors

_ref_cloned(old_id, new_id, style, name)[source]

Apply some effects on the document or local context

modify_color(name, color)[source]

Replace this method with your colour modifier method

modify_opacity(name, opacity)[source]

Optional opacity modification

process_element(elem, gradients=None)[source]

Process one of the selected elements


Process multiple elements (gradients)

process_none = False
select_all: Tuple[Type[BaseElement], ...] = (<class 'inkex.elements._base.ShapeElement'>,)
class inkex.extensions.EffectExtension[source]

Bases: inkex.base.SvgThroughMixin, inkex.base.InkscapeExtension

Takes the SVG from Inkscape, modifies the selection or the document and returns an SVG to Inkscape.

class inkex.extensions.GenerateExtension[source]

Bases: inkex.extensions.EffectExtension

Does not need any SVG, but instead just outputs an SVG fragment which is inserted into Inkscape, centered on the selection.

container_label = ''
container_layer = False

Generate the transformation for the container group, the default is to return the center position of the svg document or view port.


Return the container the generated elements will go into.

Default is a new layer or current layer depending on the container_layer flag.


Apply some effects on the document or local context


Return an SVG fragment to be inserted into the selected layer of the document OR yield multiple elements which will be grouped into a container group element which will be given an automatic label and transformation.

class inkex.extensions.InputExtension[source]

Bases: inkex.base.SvgOutputMixin, inkex.base.InkscapeExtension

Takes any type of file as input and outputs SVG which Inkscape can read.

Used in functions for Open


Effect isn’t needed for a lot of Input extensions


But load certainly is, we give a more exact message here

class inkex.extensions.OutputExtension[source]

Bases: inkex.base.SvgInputMixin, inkex.base.InkscapeExtension

Takes the SVG from Inkscape and outputs it to something that’s not an SVG.

Used in functions for Save As


Effect isn’t needed for a lot of Output extensions


But save certainly is, we give a more exact message here

class inkex.extensions.RasterOutputExtension[source]

Bases: inkex.base.InkscapeExtension

Takes a PNG from Inkscape and outputs it to another rather format.

document: Union[None, bytes, str, etree]

Not needed since image isn’t being changed

file_io: Optional[IO]

Takes the input stream and creates a document for parsing


Implement raster image saving here from PIL

class inkex.extensions.TemplateExtension[source]

Bases: inkex.extensions.EffectExtension

Provide a standard way of creating templates.


Argument is a string of the form X[unit]xY[unit], default units apply when missing


Creates a template, do not over-ride


Get the size of the new template (defaults to size options)


Can be over-ridden with custom svg loading here

set_namedview(width, height, unit)[source]

Setup the document namedview

size_rex = re.compile('([\\d.]*)(\\w\\w)?x([\\d.]*)(\\w\\w)?')
template_id = 'SVGRoot'
class inkex.extensions.TextExtension[source]

Bases: inkex.extensions.EffectExtension

A base effect for changing text in a document.


Apply some effects on the document or local context

static map_char(char)[source]

Replaceable map_char method for processing each letter

newline = True
newpar = True

Replaceable chardata method for processing the text


Reverse the node text