{"id":28005,"library":"ocpsvg","title":"ocpsvg","description":"A Python library for parsing, manipulating, and rendering SVG (Scalable Vector Graphics) files with support for OCP (Open Canvas Protocol) extensions. Version 0.6.0, active development with no fixed release cadence.","status":"active","version":"0.6.0","language":"python","source_language":"en","source_url":"https://github.com/ocpng/ocpsvg","tags":["svg","vector-graphics","ocp","xml"],"install":[{"cmd":"pip install ocpsvg","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"XML parsing of SVG files","package":"lxml","optional":false},{"reason":"CSS selector support for element selection","package":"cssselect","optional":false}],"imports":[{"note":"Primary class for loading and manipulating SVG documents","wrong":"","symbol":"SVG","correct":"from ocpsvg import SVG"}],"quickstart":{"code":"from ocpsvg import SVG\n\n# Load an SVG file\nsvg = SVG.from_file('example.svg')\n\n# Access SVG elements (using CSS selectors)\nrect = svg.cssselect('rect')[0]\nprint(rect.attrib)\n\n# Modify attributes\nrect.set('fill', 'blue')\n\n# Get the XML string\nprint(svg.tostring())","lang":"python","description":"Load an SVG file, select an element via CSS, modify its attribute, and output the updated XML."},"warnings":[{"fix":"Use svg.tostring() instead of print(svg) to serialize XML.","message":"SVG.from_file() returns an SVG object, not a string. Use .tostring() to get the XML string, not str() or repr().","severity":"gotcha","affected_versions":"all"},{"fix":"Remember that the returned elements are standard lxml elements; use .set() and .get() for attributes.","message":"CSS selectors via cssselect() return a list of lxml elements, not SVG-specific objects. Direct attribute manipulation on returned elements works fine.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Ensure you have version 0.6.0 or later: pip install --upgrade ocpsvg. Then use: from ocpsvg import SVG","cause":"Wrong import path or older version without 'SVG' class.","error":"ImportError: cannot import name 'SVG' from 'ocpsvg'"},{"fix":"Correct: from ocpsvg import SVG; svg = SVG.from_file(...). Wrong: import ocpsvg; svg = ocpsvg.SVG.from_file(...) - not wrong but less explicit.","cause":"Trying to use 'ocpsvg' as a class instead of importing the SVG class.","error":"TypeError: 'module' object is not callable"},{"fix":"Ensure the file path is correct and contains valid SVG XML.","cause":"Passing an empty string or non-XML file to SVG.from_file().","error":"lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}