Extra models
Model classes provide structured configuration for chart elements and features.
Annotations
Column Format
- class datawrapper.charts.models.ColumnFormat(*, column: Annotated[str, MinLen(min_length=1)], type: Literal['auto', 'text', 'number', 'date'] = 'auto', ignore: bool = False, number_prepend: str = '', number_append: str = '', number_divisor: NumberDivisor | int | str = 0, number_format: DateFormat | NumberFormat | str = '-')[source]
Bases:
BaseModelA data class for the Datawrapper API’s ‘column_format’ attribute.
- classmethod validate_number_divisor(v: NumberDivisor | int | str) NumberDivisor | int | str[source]
Validate number_divisor is a valid value.
Accepts NumberDivisor enum values or raw API values (int or str).
- column: str
“The name of the data column for the line”
- ignore: bool
Whether to ignore the column
- model_config = {'json_schema_extra': {'examples': [{'column': 'sales', 'ignore': False, 'number-append': '', 'number-prepend': '$', 'type': 'number'}]}, 'populate_by_name': True, 'strict': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- number_append: str
What to append after the number
- number_divisor: NumberDivisor | int | str
Number divisor for scaling values (use NumberDivisor enum or raw API values)
- number_format: DateFormat | NumberFormat | str
Number/date format for the column (use DateFormat or NumberFormat enum or raw format strings)
- number_prepend: str
What to prepend before the number
- type: Literal['auto', 'text', 'number', 'date']
The data type of the column
- class datawrapper.charts.models.ColumnFormatList(*, formats: list[ColumnFormat] = <factory>)[source]
Bases:
BaseModelA wrapper for a list of ColumnFormat objects that handles API serialization.
The Datawrapper API expects column-format as a dictionary where column names are keys and format configs are values. This model handles the conversion between the user-friendly list format and the API’s dict format.
- classmethod convert_from_dict_or_list(data: Any) dict[str, Any][source]
Convert dict format (from API) or list format to internal structure.
Handles three input formats: 1. Dict with ‘formats’ key (already in correct format) 2. Dict without ‘formats’ key (API format - column names as keys) 3. List of ColumnFormat objects or dicts (direct list format)
- serialize_to_dict() dict[str, dict[str, Any]][source]
Serialize to API format (dict with column names as keys).
Converts the internal list format to the dictionary format expected by the Datawrapper API, filtering out default values.
- formats: list[ColumnFormat]
The list of column format configurations
- model_config = {'json_schema_extra': {'examples': [{'formats': [{'column': 'sales', 'number-prepend': '$', 'type': 'number'}, {'column': 'date', 'type': 'date'}]}]}, 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Line Configuration
- class datawrapper.charts.line.Line(*, column: str, title: str = '', interpolation: LineInterpolation | str = 'linear', width: LineWidth | str = 'style1', dash: LineDash | str | None = None, colorKey: bool = False, directLabel: bool = False, bgStroke: bool = False, symbols: LineSymbol | None = None, valueLabels: LineValueLabel | None = None, connectMissingPoints: bool = False)[source]
Bases:
BaseModelConfigure a line on a Datawrapper line chart.
- classmethod deserialize_model(line_name: str, line_config: dict) dict[str, Any][source]
Deserialize API line config to Line initialization dict.
- Parameters:
line_name – The column name for this line
line_config – The line configuration from the API
- Returns:
Dictionary that can be used to initialize a Line instance
- classmethod validate_dash(v: LineDash | str | None) LineDash | str | None[source]
Validate dash is a valid value.
Accepts LineDash enum values, raw API string values, or None.
- classmethod validate_interpolation(v: LineInterpolation | str) LineInterpolation | str[source]
Validate that interpolation is a valid LineInterpolation value.
- classmethod validate_width(v: LineWidth | str) LineWidth | str[source]
Validate width is a valid value.
Accepts LineWidth enum values or raw API string values.
- static serialize_model(line: Line) dict[str, Any][source]
Serialize a Line instance to API format.
- Parameters:
line – The Line instance to serialize
- Returns:
Dictionary in the API’s expected format
- color_key: bool
Whether or not to show in the color key
- column: str
The name of the data column for the line
- connect_missing_points: bool
Whether or not to connect missing points
- dash: LineDash | str | None
The dashing of the line (use LineDash enum or raw API values)
- direct_label: bool
Whether or not to show a direct label for the line in the right hand margin
- interpolation: LineInterpolation | str
The interpolation method to use when drawing lines
- model_config = {'populate_by_name': True, 'strict': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- outline: bool
Line outline
- symbols: LineSymbol | None
Symbols to display on the line (None = disabled, object = enabled)
- title: str
The title to display in tooltips and legends
- value_labels: LineValueLabel | None
The value labels for the line (None = disabled, object = enabled)
- width: LineWidth | str
The width of the line (use LineWidth enum or raw API values)
- class datawrapper.charts.line.LineSymbol(*, enabled: bool = True, shape: SymbolShape | str = 'circle', style: SymbolStyle | str = 'fill', on: SymbolDisplay | str = 'last', size: int | float = 6, opacity: int | float = 1.0)[source]
Bases:
BaseModelConfigure the symbols for an individual line on a Datawrapper line chart.
Note: The presence of this object implies symbols are enabled. The enabled field is automatically set to True and should not be set to False.
- classmethod validate_enabled(v: bool) bool[source]
Validate that enabled is not explicitly set to False.
- enabled: bool
Whether or not to show symbols (automatically set to True when object exists)
- model_config = {'populate_by_name': True, 'strict': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- on: SymbolDisplay | str
Where to show the symbols
- opacity: int | float
The opacity of the symbols between 0 and 1
- shape: SymbolShape | str
The shape of the symbol
- size: int | float
The size of the symbols
- style: SymbolStyle | str
The style of the symbol
- class datawrapper.charts.line.LineValueLabel(*, enabled: bool = True, last: bool = False, first: bool = False, showCircles: bool = False, maxInnerLabels: int = 0)[source]
Bases:
BaseModelConfigure the value labels for an individual line on a Datawrapper line chart.
Note: The presence of this object implies value labels are enabled. The enabled field is automatically set to True and should not be set to False.
- classmethod validate_enabled(v: bool) bool[source]
Validate that enabled is not explicitly set to False.
- enabled: bool
Whether to show the value labels (automatically set to True when object exists)
- first: bool
Whether to show the first value label
- last: bool
Whether to show the last value label
- max_inner_labels: int
The maximum number of inner value labels to show
- model_config = {'populate_by_name': True, 'strict': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- show_circles: bool
Whether to show circles at automatically drawn inner value labels