Skip to main content

A package for generating UML Class diagrams from Python code

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
from dataclasses import dataclass

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


@include_in_uml
@dataclass
class Car:
    _name: str
    _length: float

    def set_name(self, name: str) -> None:
        self._name = name

    def get_name(self) -> str:
        return self._name

    @include_in_uml
    def drive(self):
        pass

    @include_in_uml
    def get_fuel_level(self) -> float:
        pass

    @include_in_uml
    def _turn_off_lights(self) -> None:
        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:

PlantUML UML Image Generated with python pdgen library

@startuml
skinparam dpi 600

class Car {
    - _name : str
    - _length : float
    - _turn_off_lights()
    + drive()
    + get_fuel_level()
}


class Bike {
    + name : str
}

@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.3.2.tar.gz (13.6 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.3.2-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdgen-0.3.2.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Windows/11

File hashes

Hashes for pdgen-0.3.2.tar.gz
Algorithm Hash digest
SHA256 8b486023e102ac22ed82034d729dd6b5cce32923638757baff2501f4eaeded99
MD5 fdba9b0efd761748990d8adbcb5a29e9
BLAKE2b-256 24ae32a6fcb28247d81a20c5544d27929531764061d03b110666baa84cb41850

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdgen-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Windows/11

File hashes

Hashes for pdgen-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88d32b4701753a8d00adf451e62caf7a7f300b6d8e0bcea00e73987d93e34298
MD5 0f735594e1f02a0e6435958ddb0cb350
BLAKE2b-256 be160aaba2373c9e257c7c0267a95f4ca98c5a3ee85bdb56e1a07743b99e1364

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