API documentation#

class plantuml_sequence.Diagram(file_like: TextIO, title: str | None = None, hide_footboxes: bool = False, hide_unlinked: bool = False, teoz_rendering: bool = False)#

Core sequence diagram object

Create the object and use it as a contextmanager. This ensures that the @startuml and @enduml commands are written correctly.

with open("my-diagram.puml", "w") as f, Diagram(f) as diagram:
   diagram.message("Alice", "Bob", "Hello World!")
activate_lifeline(participant: Participant | str, color: str | None = None) Self#

Activate the lifeline of participant

Parameters:
  • participant (Participant | str) – Participant to activate

  • color (str | None, optional) – Color of the active lifeline, defaults to None

Returns:

Sequence diagram instance

Return type:

Self

active_lifeline(participant: Participant | str, color: str | None = None, destroy: bool = False) Generator[Self, None, None]#

Contextmanager to activate the lifeline of a participant

Parameters:
  • participant (Participant | str) – Participant to activate

  • color (str | None, optional) – Color of the active lifeline, defaults to None

  • destroy (bool, optional) – Whether to destroy or deactivate the lifeline at the end of the context, defaults to False

Yield:

Sequence diagram instance

Return type:

Iterator[collections.abc.Generator[Self, None, None]]

arrow_style(arrow_style: str) Generator[Self, None, None]#

Contextmanager to temporarily change the arrow style used in the diagram.

The arrow style can be changed in several ways:

  • add a final x to denote a lost message

  • use \ or / instead of < or > to have only the bottom or top part of the arrow

  • repeat the arrow head (for example, >> or //) head to have a thin drawing

  • use -- instead of - to have a dotted arrow

  • add a final o at arrow head

  • use bidirectional arrow <->

autonumber(start: int | None = None, increment: int | None = None) Self#

Enable auto numbering for messages

Parameters:
  • start (int | None, optional) – Initial number, defaults to None which means 1

  • increment (int | None, optional) – Increment per message, defaults to None which means 1

autonumber_resume(increment: int | None = None) Self#

Resume previously stopped auto numbering with an optional new increment

Parameters:

increment (int | None, optional) – New increment to use, defaults to None

Returns:

Sequence diagram instance

Return type:

Self

autonumber_stop() Self#

Stop auto numbering for messages

blank_line() Self#

Write a blank line to the file

deactivate_lifeline(participant: Participant | str) Self#

Deactivate the lifeline of participant

Parameters:

participant (Participant | str) – Participant to activate

Returns:

Sequence diagram instance

Return type:

Self

delay(msg: str | None = None) Self#

Indicate a delay in the diagram

Parameters:

msg (str | None, optional) – Message to add to the delay, defaults to None

Returns:

Sequence diagram instance

Return type:

Self

destroy_lifeline(participant: Participant | str) Self#

Deactivate the lifeline of participant

Parameters:

participant (Participant | str) – Participant to activate

Returns:

Sequence diagram instance

Return type:

Self

divider(msg: str | None = None) Self#

Insert a divider or separator to divide the diagram into logical steps

Parameters:

msg (str | None) – Add a message to the separator

Returns:

Sequence diagram instance

Return type:

Self

enduml() Self#

Write the @enduml command to the file

message(participant1: Participant | str | None, participant2: Participant | str | None, msg: str | None = None, *, arrow_style: str | None = None, note: str | None = None, note_shape: Literal['default', 'rectangle', 'hexagon'] = 'default', note_position: Literal['left', 'right'] = 'right', note_background_color: str | None = None) Self#

Create a message between participant1 and participant2

Parameters:
  • participant1 (Participant | str | None) – Participant left of the arrow

  • participant2 (Participant | str | None) – Participant right of the arrow

  • msg (str | None, optional) – Message to send between participant1 and participant2, defaults to None

  • arrow_style (str | None, optional) – Override the arrow style to use, could be used for colored arrows, defaults to None

  • note (str | None, optional) – Note to add left or right of the message, defaults to None

  • note_shape (NoteShape, optional) – Shape of the note to add to the message, defaults to “default”

  • note_position (MessageNotePosition, optional) – Position of the note relative to the message, defaults to “right”

  • note_background_color (str, optional) – Background color of the note relative to the message, defaults to None

Returns:

Sequence diagram object for chaining

Return type:

Self

newpage(title: str | None = None) Self#

Split the diagram into multiple pages

Parameters:

title (str | None, optional) – Description of the page, defaults to None

Returns:

Sequence diagram instance

Return type:

Self

note_across(msg: str, shape: Literal['default', 'rectangle', 'hexagon'] = 'default', background_color: str | None = None) Self#

Create a note across all participants

Parameters:
  • msg (str) – Message of the note

  • shape (NoteShape, optional) – Shape of the note, defaults to “default”

  • background_color (str | None, optional) – Background color of the note, defaults to None

Returns:

Sequence diagram instance

Return type:

Self

participant_note(participants: Sequence[Participant | str] | Participant | str, msg: str, shape: Literal['default', 'rectangle', 'hexagon'] = 'default', position: Literal['over'] | Literal['left', 'right'] = 'over', background_color: str | None = None) Self#

Place a note relative to a participant

Warning

Notes can only placed over multiple participants. Otherwise an exception will be raised.

Parameters:
  • participants (collections.abc.Sequence[ParticipantOrName] | ParticipantOrName) – Participant or sequence of participant definitions

  • msg (str) – Message of the note

  • shape (NoteShape, optional) – Shape of the note, defaults to “default”

  • position (ParticipantNotePosition, optional) – Position of the note relative to the participant, defaults to “over”

  • background_color (str | None, optional) – Background color of the note, defaults to None

Raises:

ValueError – Raised if a note should be placed left or right of multiple participants

Returns:

Sequence diagram instance

Return type:

Self

participants_box(title: str | None = None, background_color: str | None = None) Generator[Self, None, None]#

Create a contextmanager which will create a box around some participants

Parameters:
  • title (str | None, optional) – Title of the box, defaults to None

  • background_color (str | None, optional) – Background color of the box, defaults to None

Yield:

Sequence diagram instance

Return type:

Iterator[collections.abc.Generator[Self, None, None]]

space(num_pixels: int | None = None) Self#

Indicate some spacing in the diagram

Parameters:

num_pixels (int | None, optional) – Number of pixels to use for the spacing, defaults to None

Returns:

Sequence diagram instance

Return type:

Self

startuml() Self#

Write the @startuml command to the file