Skip to content

Adding Draw.io's native XML shape libraries#123

Merged
ibirothe merged 9 commits intoMerrimanInd:mainfrom
neerpatel:add-shapes-from-xml
Jan 28, 2026
Merged

Adding Draw.io's native XML shape libraries#123
ibirothe merged 9 commits intoMerrimanInd:mainfrom
neerpatel:add-shapes-from-xml

Conversation

@neerpatel
Copy link
Copy Markdown
Contributor

This pull request introduces comprehensive support for importing and using Draw.io's native XML shape libraries (mxlibrary format), enabling users to leverage third-party icon sets (such as Azure, AWS, and Google Cloud) directly in their diagrams. The documentation has been updated to explain the new features, and example scripts have been added to demonstrate usage. Robust error handling and improved messaging have been implemented to help users diagnose issues when working with external libraries.

New Features: External Shape Library Support

  • Added register_mxlibrary and load_mxlibrary functions to the drawpyo API, allowing registration and loading of Draw.io XML shape libraries from local files or URLs. These libraries can now be used seamlessly with object_from_library. [1] [2] [3]
  • Enhanced error handling and messaging in format_as_library_object to provide clear feedback when libraries or shapes are missing, and to warn about incomplete shape definitions. [1] [2]

Documentation Improvements

  • Updated README.md and docs/usage/shape_libs.md to explain how to import, register, and use mxlibrary files, including sample code and guidance on error handling and finding shape names. [1] [2] [3]
  • Added a "Key Features" section to docs/index.md highlighting new capabilities such as external library support.

Example Scripts

  • Added etc/development scripts/create_azure_diagram.py and etc/development scripts/test_mxlibrary_import.py as reference scripts demonstrating how to register, import, and use external shape libraries in diagrams. [1] [2]

…or handling

- Implemented `register_mxlibrary` function to register external shape libraries.
- Added `load_mxlibrary` function with improved error handling for file and URL sources.
- Enhanced `parse_mxlibrary` to return errors for invalid shapes and JSON parsing issues.
- Updated documentation to reflect new functionality and usage examples.
- Created tests for loading libraries, error handling, and registering libraries.
- Add example of importing external shape libraries to README
- Add Key Features section to docs/index.md highlighting new capabilities
- Showcase Azure icons as practical example
@ibirothe
Copy link
Copy Markdown
Collaborator

Thank you for your effort and spending time working on Drawpyo.
I see a couple of issues related to this PR, that may or may not be related to the
usage of AI-driven development. If you want to turn this contribution in something,
that really fits the project, here are a couple of thoughts on where human adjustment
would improve project fit.

  1. Print logs should be replaced by logging. You can adjust the logging level to give the user full control
    over what they want to see. Also consider, that some of the print statements are duplicates of logging calls
    that are already existing in a more appropriate location (e.g. logging when a file is saved within the write method)

  2. Updates of Readme should be minimal to focus on onboarding rather then explaining all functionality in detail.

  3. Tests should be class-based using pytest.

  4. Tests and example scripts should not use main() functions for better readability.

  5. init files should not contain business logic.

  6. We use black for formatting. Currently 11 files fail the workflow.

  7. Keeping the amount of changed lines minimal and changes concise helps us to simplify reviewing PRs. This
    is crucial in times, where contributors can easily output 1000+ using agents, because we lack the capacity to
    review the amount of AI code and would love to see this process as a part of the contribution.

- Moved the `register_mxlibrary` function from `__init__.py` to a new `library_manager.py` module for better organization.
- Updated the `load_mxlibrary` function to improve error handling and logging.
- Cleaned up whitespace and comments across multiple files for consistency.
- Enhanced integration tests for registering mxlibraries and creating objects from them.
- Added unit tests for parsing and loading mxlibrary files, ensuring robust error handling.
@neerpatel
Copy link
Copy Markdown
Contributor Author

Response to the notes from Discord :

  • The tests are still functional, not class based
  • The documentation is not linked anywhere in mkdocs; have you tried to build the docs and been able to access your page?
  • You are referencing resources outside of the project in your example scripts; is it possible to have a minimal working example that doesn't access anything outside of this repo? I understand that using HTTPS is relevant to the usecase, but we might just point towards our own repo for safety reasons.
  • The logging you are doing in the example script, should be part of the related methods instead. Example: You load a library, but the logging doesn't happen in the loading process, but the example script. That doesn't provide any insight to a user on their own script.
  • You can log "not loaded" errors etc with WARN level
  • Why are you throwing an exception when there is no baseStyle provided? That should be handled by defaulting already? Or not?

Bullet 1 & 3) I removing test_azure_integration.py. And expanding test_mxlibrary_import.py to tests things locally.
Bullet 4) I fixed the logging.
Bullet 5 & 6) I updated the code to throw warnings and I removed the exception when baseStyle isn't provided. It now logs a warning.
Bullet 2) I may need more details on this, because this is what I see when I run the command to serve the docs.
screencapture-127-0-0-1-8000-drawpyo-usage-shape-libs-2026-01-22-15_07_49

@ibirothe ibirothe merged commit d801a7a into MerrimanInd:main Jan 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants