inkex.command module

This API provides methods for calling Inkscape to execute a given Inkscape command. This may be needed for various compiling options (e.g., png), running other extensions or performing other options only available via the shell API.

Best practice is to avoid using this API except when absolutely necessary, since it is resource-intensive to invoke a new Inkscape instance.

However, in any circumstance when it is necessary to call Inkscape, it is strongly recommended that you do so through this API, rather than calling it yourself, to take advantage of the security settings and testing functions.

exception inkex.command.CommandNotFound[source]

Bases: OSError

Command is not found

exception inkex.command.ProgramRunError[source]

Bases: ValueError

Command returned non-zero output

inkex.command._call(program, *args, **kwargs)[source]
inkex.command.call(program, *args, **kwargs)[source]

Generic caller to open any program and return its stdout.

stdout = call(‘executable’, arg1, arg2, dash_dash_arg=’foo’, d=True, …)

Will raise ProgramRunError() if return code is not 0.

  • return_binary - Should stdout return raw bytes (default: False)

  • stdin - The string or bytes containing the stdin (default: None)

  • All other arguments converted using to_args(…) function.

inkex.command.inkscape(svg_file, *args, **kwargs)[source]

Call Inkscape with the given svg_file and the given arguments, see call()

inkex.command.inkscape_command(svg, select=None, verbs=())[source]

Executes a list of commands, a mixture of verbs, selects etc.

inkscape_command(‘<svg…>’, (‘verb’, ‘VerbName’), …)

inkex.command.is_inkscape_available()[source]

Return true if the Inkscape executable is available.

inkex.command.take_snapshot(svg, dirname, name='snapshot', ext='png', dpi=96, **kwargs)[source]

Take a snapshot of the given svg file.

Resulting filename is yielded back, after generator finishes, the file is deleted so you must deal with the file inside the for loop.

inkex.command.to_arg(arg, oldie=False)[source]

Convert a python argument to a command line argument

inkex.command.to_args(prog, *positionals, **arguments)[source]

Compile arguments and keyword arguments into a list of strings which Popen will understand.

Parameters

prog – Program executable prepended to the output.

Arguments
  • (str) – String added as given

  • (tuple) – Ordered version of Kwyward Arguments, see below

Keyword Arguments
  • name (str) – Becomes --name="val"

  • name (bool) – Becomes --name

  • name (list) – Becomes --name="val1"

  • n (str) – Becomes -n=val

  • n (bool) – Becomes -n

Returns

Returns a list of compiled arguments ready for Popen.

Return type

list[str]

inkex.command.which(program)[source]

Attempt different methods of trying to find if the program exists.

inkex.command.write_svg(svg, *filename)[source]

Writes an svg to the given filename