1

I have been using scour and it works well. I would like to use it inside a Python app instead of a cli. I would like the output to be the same as when I run the following command on CMD:

scour -i input.svg -o output.svgz --enable-viewboxing --enable-id-stripping \ --enable-comment-stripping --shorten-ids --indent=none

Can't find any documentation how to call this function inside a python application

Randomizer
  • 385
  • 3
  • 16
  • like this? https://stackoverflow.com/questions/89228/calling-an-external-command-in-python – Robert Longson Jul 24 '18 at 22:08
  • No, I need the output to be a file-like object and not a real file as I am uploading it to a CDN. – Randomizer Jul 26 '18 at 02:20
  • What is a file-like object? Why can't you post process the file into whatever you need? – Robert Longson Jul 26 '18 at 06:15
  • a file-like class. Like Bytes-IO or String-IO. I Don't want the output to be an actual file. I want it to come out as a string so I could upload it directly to my AWS S3 Bucket. Uploading the actual file instead of a file that is stored in memory creates an unnecessary throughput in a very time critical environment. – Randomizer Jul 26 '18 at 10:00

1 Answers1

1

In the scour download, there is a testscour.py that you could use to see how you can access scour from within the code instead over the cli.

When I was finally solving my mostly similar scour problem, I did it like this:

from scour import scour
import re

with open(svg_file, 'r') as f
    svg = f.read() 

scour_options = scour.sanitizeOptions(options=None) # get a clean scour options object
scour_options.remove_metadata = True # change any option you like
clean_svg = scour.scourString(svg, options = scour_options) # use scour
Anderas
  • 418
  • 5
  • 11