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_umldecorator. - 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:
diagram_new.png: A UML diagram image.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 {
+ __init__(name: str)
}
class Car {
+ __init__(name: str, make: str, model: 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdgen-0.2.0.tar.gz.
File metadata
- Download URL: pdgen-0.2.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b45b2327402f00f4ecb326a5c9a4036d9250b1208bad1359d02537adb66bb469
|
|
| MD5 |
38e2250691e8f635e7da74908fb17e65
|
|
| BLAKE2b-256 |
ef4a1e9a956721b321d81fbebb7c5a9f33e7d19030516dc7e4c47ea875ee1e86
|
File details
Details for the file pdgen-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pdgen-0.2.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf44014a982b7769c4007edb431891dd83fed661e3977382442d1cc64747fa12
|
|
| MD5 |
79458ec283f8b42d9da4258706ebee38
|
|
| BLAKE2b-256 |
309f6c0f4a502585cead1dd739d98d37a2208229bcebaa38ae8bc51177438956
|