Skip to main content

A Python package for generating UML diagrams from Python code using PlantUML.

Project description

PDGen

PDGen is a Python library for generating UML diagrams from Python code using PlantUML. It simplifies UML generation by allowing you to annotate your classes and methods directly in your code, and then generates a UML diagram based on these annotations.

Features

  • Simple Annotations: Mark classes and methods to include in your UML diagram using the @include_in_uml decorator.
  • PlantUML Integration: Generates UML diagrams in PlantUML format.
  • Customizable Output: Save your diagram as an image and optionally output the UML text.

Installation

Install PDGen via pip:

pip install pdgen

Quick Start

Here’s how you can use PDGen to generate a UML diagram:

import logging
from pathlib import Path

# Configure logging to see debug output
logging.basicConfig(level=logging.DEBUG)

from pdgen import include_in_uml, generate_diagram

@include_in_uml
class Vehicle:
    def __init__(self, name: str):
        self.name = name

@include_in_uml
class Car(Vehicle):
    def __init__(self, name: str, make: str, model: str):
        self.make = make
        self.model = model
        super().__init__(name)

    @include_in_uml
    def drive(self):
        pass

    @include_in_uml
    def park(self):
        pass


if __name__ == '__main__':
    # Generate a UML diagram
    generate_diagram(Path("diagram_new.png"), Path("diagram_new.txt"))

Output

The above script generates:

  1. diagram_new.png: A UML diagram image.
  2. diagram_new.txt: The PlantUML source text for the diagram.

Example UML Diagram

The generated UML diagram includes the annotated classes and methods:

@startuml
skinparam dpi 600

class Vehicle {
    name: str
}

class Car {
    name: str
    model: str
    make: str
    drive()
    park()
}

Vehicle <|-- Car
@enduml

API Reference

@include_in_uml

A decorator used to mark classes or methods for inclusion in the UML diagram.

generate_diagram(output_path: Path, uml_text_path: Path)

Generates a UML diagram and optionally saves the PlantUML source.

  • output_path: Path to save the generated UML diagram (e.g., PNG format).
  • uml_text_path: Path to save the PlantUML source text.

Logging

PDGen uses Python's logging module to output debug information. You can configure the logging level in your script for better insights into the generation process.

import logging
logging.basicConfig(level=logging.DEBUG)

Contributing

Contributions are welcome!

License

This project is licensed under the MIT License. See the LICENSE file for details.

Links

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

pdgen-0.2.1.tar.gz (183.0 kB view details)

Uploaded Source

Built Distribution

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

pdgen-0.2.1-py3-none-any.whl (189.5 kB view details)

Uploaded Python 3

File details

Details for the file pdgen-0.2.1.tar.gz.

File metadata

  • Download URL: pdgen-0.2.1.tar.gz
  • Upload date:
  • Size: 183.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pdgen-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f4350b47b4aa49fa0717f4dd79fc4e0bd6a091590a0e845306fbd2b6c24e98e9
MD5 3f8db194a5e4ed6e53efda48db7e0f9e
BLAKE2b-256 28ae00895494b1aa0951101ff7af23ced9e33539f7f7c48c22123fd55fbf5fdf

See more details on using hashes here.

File details

Details for the file pdgen-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pdgen-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 189.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pdgen-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d4bd68e7c265cc6100138ba73012a8035d8fe4e880c05d742cb856cdc78b404
MD5 5e78656188a235e57795c6ab60ff8b89
BLAKE2b-256 8976676b892f2980d9c7f2fbd4146c28a444dc9de0d1606f0ec006d89e110c7b

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