Skip to main content

vsdx - A python library for processing .vsdx files

Project description

vsdx - A python library for processing Visio .vsdx files

PyPI PyPI - Downloads

pytest Documentation Status

PyPI - Python Version vsdx

.vsdx files can processed in two ways, directly via python code as in example 1 below, or indirectly using a jinja template as in example 2

For quick start documentation please see https://vsdx.readthedocs.io/en/latest/quickstart.html

Example 1 code to find a shape with specific text, remove it, and then save the updated .vsdx file:

from vsdx import VisioFile

filename = 'my_file.vsdx'
# open a visio file
with VisioFile(filename) as vis:
    # get page shapes collection
    shapes = vis.page_objects[0].shapes
    # get shape to remove by its text value
    s = shapes[0].find_shape_by_text('Shape to remove')  # type: VisioFile.Shape
    # remove the shape if found
    if s:
        s.remove()
        # save a new copy
        vis.save_vsdx('shape_removed.vsdx')

Example 2 creating a new vsdx file from a template and context data using jinja.
Note that as vsdx does not lend itself well to ordered statements like {% if something %}my content{% endif %} or {% for x in list_value %}x={{ x }}{% endfor %} this package provides mechanisms to help - refer to tests for more details.

from vsdx import VisioFile

filename = 'my_template_file.vsdx'  # file containing jinja code
context = {'value1': 10, 'list_value': [1,2,3]}  # data for the template
with VisioFile('my_template_file.vsdx') as vis: 
    vis.jinja_render_vsdx(context=context)
    vis.save_vsdx('my_new_file.vsdx')

Please refer to tests/test.py for more usage examples in the form of pytest tests.


Change Log

  • v0.3.5: Added VisioFile.add_page() method and tests
  • v0.3.4: Added VisioFile.remove_page_by_index() method to remove a page, with associated test
  • v0.3.3: Added code of conduct and contributing guides
  • v0.3.2: updated README and updated tests for improved compatibility
  • v0.3.1: add jinja rendering support for if statements, via VisioFile.jinja_render_vsdx() - similar to for loops but using a {% showif statement %} in text of group shape controls whether that group shape is included in vsdx file rendered. Note that the showif statement is replaced with a standard if statement around the group shape prior to rendering. Refer to test.py::test_jinja_if() for an example
  • v0.3.0: update jinja rendering to support for loops, where for statement is at start of group shape text, endfor is automatically inserted before processing. Refer to test.py::test_basic_jinja_loop() for code and test_jinja_loop.vsdx for content.
  • v0.2.10: add VisioFile.jinja_render_vsdx() - applying jinja processing to Shape.text only
  • v0.2.9: check that Page has shapes tag when in shape_copy(), add test to copy shape to new page
  • v0.2.8: find max shape ID in Page before creating Shape in Shape.copy(). Find and load master pages when file is opened, store in VisioFile.master_page_objects and .master_pages
  • v0.2.7: add Shape.copy() method
  • v0.2.6: added Page.get_connectors_between() to get zero or many connectors between two shapes, by shape id or text
  • 0.2.5: Add new Shape properties connected_shapes (list of Shape objects) and connects (list of Connect objects) properties to allow related shapes to be identified (i.e. shapes and connectors) and provide information on the relationship, in new Connect object. Also new properties of shape begin_x/y, end_x/y, plus height/width setters
  • 0.2.4: Added find_replace(old, new) method to Shape and Page classes to recursively replace old with new
  • 0.2.3: Updated tests to output files to an /out folder. Added test vsdx file with compound shape. Updated Shape text getter/setter
  • 0.2.2: Added x & y location setters to Shape, and move(x_delta, y_delta) method - both with related tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vsdx-0.3.5.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vsdx-0.3.5-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file vsdx-0.3.5.tar.gz.

File metadata

  • Download URL: vsdx-0.3.5.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

File hashes

Hashes for vsdx-0.3.5.tar.gz
Algorithm Hash digest
SHA256 383f79509fc1226a325b8b83e080a2e96594ce99b488848e93f06ffe65ed1de6
MD5 ce9f5b920aa608c52c6b27bd9f35415f
BLAKE2b-256 ca5bf4a6327e7494c501abc2d118f71edca9ae01a6563fe2b7656f108cef81e3

See more details on using hashes here.

File details

Details for the file vsdx-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: vsdx-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

File hashes

Hashes for vsdx-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c1104ff8b81433bb1e81bfb1954650560930ec353afbdbba140d66846511bb4a
MD5 f54b978c980502bf1e84abf35c4f78fa
BLAKE2b-256 821ca6a477be21b5c2c12e0ed80b4ead529e561e4731c9ba77c1d4bf96196b94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page