py2puml
py2puml copied to clipboard
Using dataclass_transforms to support attrs, pydantic, etc.
Hi - interesting project. UML is currently underestimate, IMO it gives great overviews.
I just wanted to point out to dataclass transforms - I believe it would allow to treat Pydantic, attrs, or Django models like dataclasses with little additional coding.
thank you @mcgfeller for pointing out this PEP. So just to make sure I understood the purpose of your message correctly: are you encouraging me to follow the status of this PEP so that I can implement UML documentation from any solution that follows the dataclass-transforms convention?
Or had you other ideas in mind?
and do you have any ideas about how this specification evolve? The changelog stopped a year ago.
Dear @lucsorel - exactly: If you ever wanted to support Pydantic or attrs as an alternative to dataclasses as the source for the UML documentation, following these specs may be the easiest way. Very few changes might be required; in fact, I already get quite nice results from using py2puml on Pydantic models.
The specs were already adopted in Pydantic release v1.9.0 (2021-12-31) and attrs 21.1.0 (2021-05-06). It is supported by Pyright; hence Pylance and VS Code provide type checking and code completion for these alternatives to dataclasses.
I just realized it is also officially PEP 681.
Hi both, great to see that there is already a topic for this. To add some more info as well as a related but different request for ORM support:
- Pydantic seems to work for me just fine - not sure if that required specific work or came baked in with some other approach similarly to dataclasses.
- SQLAlchemy does not seem to be working currently. All the class definitions have no attributes unfortunately. I might have a look at how to implement that if I find the time, since I presume that SQLAlchemy would also be a desired addition in functionality.
Has there been any previous work or thoughts on adding SQLAlchemy support? @lucsorel
hi @Baukebrenninkmeijer
Has there been any previous work or thoughts on adding SQLAlchemy support?
There has been no previous work or thoughts about supporting SQLAlchemy classes, only because I have not used this framework and nobody asked for them :smiley: So the topic is open: my initial goal with py2puml
was to document the business domain of an application, so it would make sense to support a business domain being persisted with SQLAlchemy.
A first step towards supporting SQLAlchemy would be to create a fake business domain model to support, with the different kinds of relationships between the classes (1-1 composition, 1-n association, inheritance maybe, etc.). I have no idea about how a SQLAlchemy domain model is designed, so doing that for me with code snippets would help.
Maybe in a separate issue dedicated to SQLAlchemy? What do you think?
@lucsorel Great to hear. Much value to be added then :). A separate issue might indeed be best suited, I'll create one.