Skip to main content

The data model for UML Diagrams

Project description

CircleCI PyPI version Maintenance

forthebadge made-with-python

Introduction

This project provides a Python data model for creating and manipulating UML diagrams. It's the foundational data model for the UML Shapes module.

Installation

It is recommended to use a virtual environment for installing Python packages.

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate

# Install the package
pip install umlmodel

Usage

Programmatic Usage

The umlmodel library allows you to create UML elements like classes, interfaces, and use cases programmatically. Here are some examples:

Creating a Class

To create a simple class, instantiate the Class object:

from umlmodel.Class import Class

modelClass: Class = Class(name='MyClass')

print(modelClass.name)

Adding Fields to a Class

You can add fields (attributes) to a class. Fields have a name, type, visibility, and an optional default value.

from umlmodel.Class import Class
from umlmodel.Field import Field
from umlmodel.FieldType import FieldType
from umlmodel.enumerations.Visibility import Visibility

# Create a class
modelClass: Class = Class(name='MyClass')

# Create fields
field1: Field = Field(name='my_string',
               type=FieldType('str'),
               visibility=Visibility.PUBLIC,
               defaultValue='"hello"')
field2:Field = Field(name='_my_private_int',
               type=FieldType('int'),
               visibility=Visibility.PRIVATE)

# Add fields to the class
modelClass.fields.append(field1)
modelClass.fields.append(field2)

# The string representation of a field is useful
print(field1)
print(field2)

Adding Methods to a Class

Methods can be added to a class, including parameters and return types.

from umlmodel.Class import Class
from umlmodel.Method import Method
from umlmodel.Parameter import Parameter
from umlmodel.ParameterType import ParameterType
from umlmodel.ReturnType import ReturnType
from umlmodel.enumerations.Visibility import Visibility

# Create a class
modelClass: Class = Class(name='MyClass')

# Create a method
method: Method = Method(name='my_method', visibility=Visibility.PUBLIC)

# Add a parameter
parameter: Paraeter = Parameter(name='value', type=ParameterType('int'), defaultValue='0')
method.addParameter(parameter)

# Set a return type
method.returnType = ReturnType('bool')

# Add the method to the class
modelClass.methods.append(method)

# Print the method signature
print(method.methodWithParameters())

Written by Humberto A. Sanchez II <mailto@Humberto.A.Sanchez.II@gmail.com>, (C) 2025

Note

For all kind of problems, requests, enhancements, bug reports, etc., please drop me an e-mail.


Humberto's Modified Logo

I am concerned about GitHub's Copilot project

I urge you to read about the Give up GitHub campaign fromthe Software Freedom Conservancy.

While I do not advocate for all the issues listed there I do not like that a company like Microsoft may profit from open source projects.

I continue to use GitHub because it offers the services I need for free. But, I continue to monitor their terms of service.

Any use of this project's code by GitHub Copilot, past or present, is done without my permission. I do not consent to GitHub's use of this project's code in Copilot.

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

umlmodel-3.4.1.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

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

umlmodel-3.4.1-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file umlmodel-3.4.1.tar.gz.

File metadata

  • Download URL: umlmodel-3.4.1.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for umlmodel-3.4.1.tar.gz
Algorithm Hash digest
SHA256 dc340b76ac0e7c6f00ad4c6c1fb17a0ed87cbed89bccfe3ed6da3e9a57cf7b13
MD5 5730a8d1ae1e18cac793cb9a6f0223a9
BLAKE2b-256 5be6b3715d66691476782e2520049590a4c353c2ca99d6e4f2b85a9d3e75f0c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for umlmodel-3.4.1.tar.gz:

Publisher: python-publish.yml on hasii2011/umlmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file umlmodel-3.4.1-py3-none-any.whl.

File metadata

  • Download URL: umlmodel-3.4.1-py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for umlmodel-3.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2e39aa906ccf020ddbd7fff1c19e5fe2647c9e7b5700f4300e596df461f0860
MD5 d24344d0738975f52db228f143a93fff
BLAKE2b-256 672a604c6a6b6eaf0f403512256fdaf98e9234c6e7d3f9fca7750d5d7477dcac

See more details on using hashes here.

Provenance

The following attestation bundles were made for umlmodel-3.4.1-py3-none-any.whl:

Publisher: python-publish.yml on hasii2011/umlmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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