pyMDG
Overview
The problem with most model driven generation is that tools force the modeller to effectively "code up" the output representation of the artifact being generated in an output specific, non-reusable model. It always ends up being simpler just to actually code up the end result.
pyMDGs goal is to use a logical model as the source, then combine with business rules to output physical level artifacts (code, schema, documentation etc). Current version supports Sparx DB (including sqlite which is the '.qea' native file format for Sparx v16+) or diagrams.net XML.
A single logical model is rich enough to generate API schemas, DB schemas, POJOs, Python Data classes etc.
The tool parses your models into generic UML classes (see metamodel below) which are then passed to jinja2 templates for generation.
My current favorite generation recipie is Hasura for a GraphQL API and generating DB migrations via Django. See the tutorial here: HasuraTutorial and check the example config in sample_recipies/sparxdb/config-sparxdb-graphql.yaml
Quickstart and docs can be found here: readthedocs
Test
Testing (powershell):
.\test.ps1
Testing (unittest):
python -m unittest
Generate
To generate code call the generate script and pass in the recipe folder. A sample recipe folder is provided in the github repo:
python mdg-tool.py generate ./sample_recipe/drawio/config-drawio-django.yaml
Or once installed into site-packages execute:
mdg-tool generate <my/config.yaml>
See the sample_recipe configs for examples
Limitations
Most templates have a limit of single inheritance and no chained inheritance (a is a specialisation of b which is a specialisation of c). The results of this are unknown.
Sparx EA XMI (versions earlier than V16) Export Process
The UML parser expects a specific package hierarchy, please see the sample EA file.
- In Sparx select the domain root node (e.g. Model/Sample )
- Select the publish tab at the top
- Select Publish As... from top menu
- Set export type as XMI 2.1
- Optionally select 'Export Diagrams', 'Generate Diagram Images' and PNG format
- Export to folder where you want to generate from
Note: Sparx V16+ does not need to be exported. The parser uses native SQLite file format which is the same schema as database repositories.
Draw.io Export Process
The UML parser expects a specific package layout which mimics the Sparx hierarchy, please see the sample files.
- In the web editor select Export As -> XML
- Uncheck 'Compressed'
Wiki documentation upload
If your generation recipe has created a file for your wiki (Confluence) then an uploader utilitity can be used. This assumes that you have done the XMI export from Sparx EA with export diagrams and generate diagram images. To generate a confluence token please see: https://confluence.atlassian.com/cloud/api-tokens-938839638.html
python mdg/confluence.py {your email} {your confluence token} {confluence page id} {path to images} {doc filename}
Nomenclature:
This diagram shows all the features and how to model in UML
Sample model
Metamodel
This diagram shows the internal classes which are passed to the templates during generation.
Build the docs
Install sphinx
> cd pyMDG
> sphinx-apidoc -o docs\source mdg
> cd docs
> make html
Metadata
Release files for pymdg 1.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymdg-1.2.6.tar.gz | 76.8 kB | With provenance | Details for pymdg-1.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymdg-1.2.6-py3-none-any.whl | Python 3 | none | any | Details for pymdg-1.2.6-py3-none-any.whl |
Total release size: 170.7 kB
Release files / pymdg-1.2.6.tar.gz
| Download URL | pymdg-1.2.6.tar.gz |
|---|---|
| Size | 76.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54a7346abf401eb9fec654138ed96c350aa39a69c12536e14f8fba3b947bde3d
|
|
BLAKE2b-256 checksum How to use checksums |
6448b66d1d630d36981b56d003726bd1901b6e48dac8d9932d0473424984dad4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2025.
Transparency logRelease files / pymdg-1.2.6-py3-none-any.whl
| Download URL | pymdg-1.2.6-py3-none-any.whl |
|---|---|
| Size | 93.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44f998c9c7946f2860e0f70fefa61035fb884bd06004e7401d6e741a407d119f
|
|
BLAKE2b-256 checksum How to use checksums |
84c789fd67eb5f86470e5bc3761f2bcfe213e126969b3556b62b9bb34ae6d8c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2025.
Transparency logSecurity for pymdg 1.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pymdg-1.2.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.