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
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
- __init__(begin, end, *, parent)[source]
Initializes a bar and appends it to its row.
- Parameters:
- Raises:
ValueError – If parameter ‘begin’, ‘end’ or ‘parent’ is None.
TypeError – If parameter ‘begin’ or ‘end’ is not of type
datetime.ValueError – If the end precedes the begin.
- Return type:
None
- 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
Noneto 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:
- 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:
- 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
- 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 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.
- 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
Noneto 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:
- 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:
- 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
- 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
Noneto 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:
- 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:
- 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.