Documentation#

class texonomy.texonomy.Direction(value)#

An enum wrapping the relative position of an entity in the ERD.

class texonomy.texonomy.ERDiagram(entity: Entity)#

An object representing the entity-relationship diagram.

entities#

The entities in this diagram.

Type:

list of Entity

code#

The LaTeX code that corresponds to all the entities and relationships in this diagram.

Type:

str

add_relationship(rel: Relationship, defining: bool = False) None#

Adds a relationship (and, therefore, another entity) to the ER diagram.

Parameters:
  • rel (Relationship) – The Relationship object corresponding to one anchor entity (already in this diagram) and one new entity to be added to this diagram.

  • defining (bool) – True if this relationship is the defining relationship of a weak entity, False otherwise. Defaults to False.

Raises:

ValueError – If the anchor does not already exist in the diagram.

add_specialization(superclass: Entity, subclass: Entity) None#

Adds a specialization relationship to the ER diagram.

Parameters:
  • superclass (Entity) – The Entity object corresponding to an anchor entity (must already exist in this diagram), from which the subclass will specialize.

  • subclass (Entity) – The Entity object corresponding to a new entity which is a specialization of the superclass entity.

Raises:

ValueError – If the superclass does not exist in the diagram.

to_latex() str#

Generates the LaTeX code associated with this diagram.

Returns:

The LaTeX code, as a string.

Return type:

str

class texonomy.texonomy.Entity(name: str, attributes: List[str], weak: bool = False)#

An object representing an entity in the diagram.

name#

The display name of the entity.

Type:

str

attributes#

A list of this entity’s attributes, which are displayed on the diagram.

Type:

list of str

primary#

The index of the primary key in the attributes list (by default it’s 0).

Type:

int

weak#

True if the entity is weak, False if not.

Type:

bool

__str__() None#

Formats an Entity’s fields in a readable way.

add_attribute(attribute: str) None#

Adds an attribute to the end of the Entity’s attributes list.

Parameters:

attribute (str) – The attribute to be added to the list.

set_primary(attribute: str) None#

Sets the primary key to an existing attribute, referenced by name.

Parameters:

attribute (str) – The name of the attribute to be set as new primary key.

Raises:

ValueError – If attribute does not exist in the Entity’s list of attributes.

to_latex() str#

Generates the LaTeX code associated with this Entity object.

Returns:

The LaTeX code, as a string.

Return type:

str

class texonomy.texonomy.Relationship(anchor: Entity, new_entity: Entity, label: str, cardinality: Tuple[Tuple[int, int], Tuple[int, int]], direction: Direction, attributes: List[str] | None = None)#

An object representing a relationship between two entities in the diagram.

anchor#

The existing entity in the diagram to which the new entity should be attached.

Type:

Entity

new_entity#

The new entity to attach to this diagram.

Type:

Entity

label#

The display label given to this relationship; will be shown on the diagram.

Type:

str

cardinality#

The cardinality of this relationship (e.g., one-to-many).

Type:

Tuple of two Tuple`s of `int

direction#

The relative positioning of the new entity with respect to the anchor entity.

Type:

Direction

attributes#

The attributes attached to this relationship, if any.

Type:

list of str, optional

__str__()#

Formats an Entity’s fields in a readable way.

add_attribute(attribute: str) None#

Adds an attribute to the end of the Relationship’s attributes list.

Parameters:

attribute (str) – The attribute to be added to the list.

attributes_to_latex() str#

Generates the LaTeX code associated with this Relationship’s attributes.

Returns:

The LaTeX code, as a string.

Return type:

str