pyTooling.Diagram.Gantt

A Gantt chart: rows of bars on a time scale.

from datetime import datetime, timedelta
from pyTooling.Diagram.Gantt import Diagram, Row, Bar

begin =   datetime(2026, 9, 15, 8, 0)
diagram = Diagram("Nightly build", begin)

row = Row("Compile", parent=diagram)
Bar(begin, begin + timedelta(minutes=4), parent=row)

print(f"{row.Name}: {row.DurationInSeconds} s, beginning {row.BeginSinceOrigin} after the diagram's origin")

Every element knows the Diagram it belongs to and the element containing it, so an offset is answered without a search: a bar reports its begin as a time, as the distance from the diagram’s origin, and as the distance from the row it sits in.

The classes describe a chart; they don’t draw one. A producer of data derives from them and adds what its domain knows - pyTooling.Tracing.Render.GanttLayout builds a diagram from a software execution trace - and a renderer draws what any of them describe.

See also

pyTooling.Tracing.Render

→ A software execution trace as a Gantt chart, and the renderers drawing it.

Classes

  • Bar: A bar of a Gantt chart: a time range within one Row.

  • Row: A row of a Gantt chart: the bars drawn on one line, under one name.

  • Diagram: A Gantt chart: rows of bars, and the origin their offsets are counted from.


Classes

class pyTooling.Diagram.Gantt.Bar[source]

A bar of a Gantt chart: a time range within one Row.

A bar reports its position three ways - as the times themselves (Begin, End), as the distance from the diagram’s origin (BeginSinceOrigin), and as the distance from the row it sits in (BeginSinceParent) - because a chart is drawn on the second and a report usually wants one of the others.

Inheritance

Inheritance diagram of Bar

__init__(begin, end, *, parent)[source]

Initializes a bar and appends it to its row.

Parameters:
  • begin (datetime) – Begin of the bar.

  • end (datetime) – End of the bar, which may equal the begin but must not precede it.

  • parent (Row) – The row the bar sits in.

Raises:
  • ValueError – If parameter ‘begin’, ‘end’ or ‘parent’ is None.

  • TypeError – If parameter ‘begin’ or ‘end’ is not of type datetime.

  • TypeError – If parameter ‘parent’ is not of type Row.

  • ValueError – If the end precedes the begin.

Return type:

None

_parent: Row

The row this bar sits in.

_diagram: Diagram

The diagram this bar belongs to.

_begin: datetime

Begin of the bar.

_end: datetime

End of the bar.

property Parent: Row

Read-only property to access the row this bar sits in (_parent).

Returns:

The row.

property Diagram: Diagram

Read-only property to access the diagram this bar belongs to (_diagram).

Returns:

The diagram.

property Begin: datetime

Read-only property to access the begin of the bar (_begin).

Returns:

The time the bar begins.

property End: datetime

Read-only property to access the end of the bar (_end).

Returns:

The time the bar ends.

property Duration: timedelta

Read-only property to return the length of the bar.

Returns:

The length from the bar’s begin to its end.

property DurationInSeconds: float

Read-only property to return the length of the bar as a number.

Returns:

The length in seconds.

property BeginSinceOrigin: timedelta

Read-only property to return how long after the diagram’s origin the bar begins.

Returns:

The distance from the origin to the bar’s begin.

property EndSinceOrigin: timedelta

Read-only property to return how long after the diagram’s origin the bar ends.

Returns:

The distance from the origin to the bar’s end.

property BeginSinceOriginInSeconds: float

Read-only property to return how long after the diagram’s origin the bar begins, as a number.

Returns:

The distance from the origin to the bar’s begin, in seconds.

property EndSinceOriginInSeconds: float

Read-only property to return how long after the diagram’s origin the bar ends, as a number.

Returns:

The distance from the origin to the bar’s end, in seconds.

property BeginSinceParent: timedelta

Read-only property to return how long after its row the bar begins.

Returns:

The distance from the row’s begin to the bar’s begin, which is zero for the row’s earliest bar.

property EndSinceParent: timedelta

Read-only property to return how long after its row’s begin the bar ends.

Returns:

The distance from the row’s begin to the bar’s end.

classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[…, Any], tuple[Attribute, …]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

Returns:

Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.

__setstate__(state: dict[str, Any]) None

Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.

Parameters:

state (dict[str, Any]) – Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If the given state misses a slot or carries an unexpected one.

Return type:

None

class pyTooling.Diagram.Gantt.Row[source]

A row of a Gantt chart: the bars drawn on one line, under one name.

A row spans its bars: it begins with its earliest bar and ends with its latest, whether or not they touch.

Inheritance

Inheritance diagram of Row

__init__(name, *, parent)[source]

Initializes a row without bars and appends it to its diagram.

Parameters:
  • name (str) – Name of the row.

  • parent (Diagram) – The diagram the row belongs to.

Raises:
Return type:

None

_parent: Diagram

The diagram this row belongs to.

_name: str

Name of the row, which labels it in a chart.

_bars: list[Bar]

The bars of this row, in the order they were added.

property Parent: Diagram

Read-only property to access the diagram this row belongs to (_parent).

Returns:

The diagram.

property Diagram: Diagram

Read-only property to access the diagram this row belongs to (_parent), which is what contains it.

Returns:

The diagram.

property Name: str

Read-only property to access the name of the row (_name).

Returns:

The name.

property Bars: tuple[Bar, ...]

Read-only property to return the bars of this row (_bars).

Returns:

The bars, in the order they were added.

property Begin: datetime

Read-only property to return the begin of the row’s earliest bar.

Returns:

The time the row begins.

Raises:

DiagramError – If the row has no bars.

property End: datetime

Read-only property to return the end of the row’s latest bar.

Returns:

The time the row ends.

Raises:

DiagramError – If the row has no bars.

property Duration: timedelta

Read-only property to return the length of the row.

Returns:

The length from the row’s begin to its end, gaps between its bars included.

Raises:

DiagramError – If the row has no bars.

property DurationInSeconds: float

Read-only property to return the length of the row as a number.

Returns:

The length in seconds, gaps between its bars included.

Raises:

DiagramError – If the row has no bars.

property BeginSinceOrigin: timedelta

Read-only property to return how long after the diagram’s origin the row begins.

Returns:

The distance from the origin to the row’s begin.

Raises:

DiagramError – If the row has no bars.

property EndSinceOrigin: timedelta

Read-only property to return how long after the diagram’s origin the row ends.

Returns:

The distance from the origin to the row’s end.

Raises:

DiagramError – If the row has no bars.

property BarCount: int

Read-only property to return the number of bars.

Returns:

Number of bars.

IterateBars()[source]

Returns an iterator to iterate the bars of this row.

Return type:

Iterator[Bar]

Returns:

Iterator to iterate all bars, in the order they were added.

__len__()[source]

Returns the number of bars in this row.

Return type:

int

Returns:

Number of bars.

__iter__()[source]

Returns an iterator to iterate the bars of this row.

Return type:

Iterator[Bar]

Returns:

Iterator to iterate all bars, in the order they were added.

classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[…, Any], tuple[Attribute, …]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

Returns:

Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.

__setstate__(state: dict[str, Any]) None

Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.

Parameters:

state (dict[str, Any]) – Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If the given state misses a slot or carries an unexpected one.

Return type:

None

class pyTooling.Diagram.Gantt.Diagram[source]

A Gantt chart: rows of bars, and the origin their offsets are counted from.

The origin is stated rather than derived, because the scale a chart is drawn on usually begins before its first bar - a pipeline starts before its first job does.

Inheritance

Inheritance diagram of Diagram

__init__(title, origin)[source]

Initializes a diagram without rows.

Parameters:
  • title (str) – Title of the diagram.

  • origin (datetime) – The time offsets are counted from.

Raises:
Return type:

None

_title: str

Title of the diagram.

classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[…, Any], tuple[Attribute, …]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

Returns:

Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.

__setstate__(state: dict[str, Any]) None

Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.

Parameters:

state (dict[str, Any]) – Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If the given state misses a slot or carries an unexpected one.

Return type:

None

_origin: datetime

The time offsets are counted from.

_rows: list[Row]

The rows of this diagram, in the order they were added.

property Title: str

Read-only property to access the title of the diagram (_title).

Returns:

The title.

property Origin: datetime

Read-only property to access the time offsets are counted from (_origin).

Returns:

The origin.

property Rows: tuple[Row, ...]

Read-only property to return the rows of this diagram (_rows).

Returns:

The rows, in the order they were added.

property RowCount: int

Read-only property to return the number of rows.

Returns:

Number of rows.

IterateRows()[source]

Returns an iterator to iterate the rows of this diagram.

Return type:

Iterator[Row]

Returns:

Iterator to iterate all rows, in the order they were added.

__len__()[source]

Returns the number of rows in this diagram.

Return type:

int

Returns:

Number of rows.

__iter__()[source]

Returns an iterator to iterate the rows of this diagram.

Return type:

Iterator[Row]

Returns:

Iterator to iterate all rows, in the order they were added.