PropertyValue Objects

Classes:

PropertyValue(**kwargs)

Base class for all Property Values.

TitlePropertyValue([text, id, bold, italic, ...])

Title property value.

RichTextPropertyValue([text, id, bold, ...])

Rich Text Property Value Object.

SelectPropertyValue(name[, color, id, raw])

Initializes a select property value.

MultiSelectPropertyValue(names[, id, raw])

Similar to SelectPropertyValue, but allows for multiple options to be selected.

NumberPropertyValue(number[, id, raw])

Number property value object.

DatePropertyValue(start[, end, timezone, ...])

Date property value object.

FormulaPropertyValue(formula[, id, raw])

Formula property value.

RelationPropertyValue(**kwargs)

CheckboxPropertyValue(checked[, raw])

Checkbox property value object.

class PropertyValue(**kwargs)[source]

Bases: ABC

Base class for all Property Values.

Contains all properties held by the property value.

All Property Values contain a ‘value’ property, which is the python representation of the contained value. E.g. a RichTextPropertyValue contains a ‘value’ property which is just the string plain text value.

This helps to make Property Values easier to edit and manipulate as opposed to having to access the objects manually

Property Values also have a ‘from_json’ class method which can be used to create a new Property Value from a JSON object.

Construct a property value object based on the type required and update attributes using update() method.

# TODO setter for value

Methods:

from_json(json)

Creates a property value from a JSON object.

from_notion(json)

Creates a property value from a JSON object.

update(value)

Updates the property value.

to_json()

Returns the property value as a JSON object.

to_dict()

Returns the property value as a dictionary.

to_notion()

Returns the property value as a dictionary.

Attributes:

notion

Returns the JSON representation of the property value.

value

classmethod from_json(json: Dict) PropertyValue[source]

Creates a property value from a JSON object. :param json: The JSON object

classmethod from_notion(json: Dict)[source]

Creates a property value from a JSON object. Alias for from_json. :param json: The JSON object

property notion

Returns the JSON representation of the property value.

abstract property value: Any
abstract update(value: Any) None[source]

Updates the property value. :param value: The new value

to_json() Dict[source]

Returns the property value as a JSON object.

to_dict() Dict[source]

Returns the property value as a dictionary.

to_notion() Dict[source]

Returns the property value as a dictionary. Alias for to_dict.

class TitlePropertyValue(text: str = '', id=None, bold=False, italic=False, strikethrough=False, underline=False, code=False, color='default', raw=None, **kwargs)[source]

Bases: PropertyValue

Title property value.

Parameters:
  • text (str, optional) – text. Defaults to “”.

  • id (str, optional) – id. Defaults to None.

  • bold (bool, optional) – bold. Defaults to False.

  • italic (bool, optional) – italic. Defaults to False.

  • strikethrough (bool, optional) – strikethrough. Defaults to False.

  • underline (bool, optional) – underline. Defaults to False.

  • code (bool, optional) – code. Defaults to False.

  • color (str, optional) – color. Defaults to “default”.

  • raw (obj, optional) – Used only for json-based initialization. Defaults to None.

Returns:

Title property value object.

Return type:

TitlePropertyValue

Example

>>> title = TitlePropertyValue("Hello World")
>>> title
Hello World
>>> title.to_notion()
{'title': [{'text': {'content': 'Hello World'}}]}
>>> title.bold = True
>>> title.to_notion()
{'title': [{'text': {'content': 'Hello World', 'link': None, 'annotations': {'bold': True, 'italic': False, 'strikethrough': False, 'underline': False, 'code': False, 'color': 'default'}}}]}
>>> title.update("Hello World 2")
>>> title.link_to("https://google.com")

Methods:

update(text, **kwargs)

_summary_: Updates the title property value.

Attributes:

value

Returns the string representation of the title property value.

update(text: str, **kwargs) None[source]

_summary_: Updates the title property value.

Parameters:
  • text (str) – new text to update the title property value with.

  • **kwargs – additional arguments to pass to the Rich Text Object, such as bold, italic, etc.

Example

>>> title = TitlePropertyValue("Hello World")
>>> title
Hello World
>>> title.update("Hello World 2")
>>> title
Hello World 2
property value: str

Returns the string representation of the title property value.

class RichTextPropertyValue(text: Optional[str] = None, id=None, bold=False, italic=False, strikethrough=False, underline=False, code=False, color='default', raw=None)[source]

Bases: PropertyValue

Rich Text Property Value Object.

Parameters:
  • text (str, optional) – Input text to display

  • id (str, optional) – id, defaults to None

  • bold (bool, optional) – bold, defaults to False

  • italic (bool, optional) – italic, defaults to False

  • strikethrough (bool, optional) – strikethrough, defaults to False

  • underline (bool, optional) – underline, defaults to False

  • code (bool, optional) – code, defaults to False

  • color (str, optional) – color, defaults to “default”

  • raw (obj, optional) – object for json intialization, defaults to None

Returns:

RichTextPropertyValue

Return type:

RichTextPropertyValue

Example

>>> rich_text = RichTextPropertyValue("Hello World")
>>> rich_text
Hello World
>>> rich_text.to_notion()
{'rich_text': [{'text': {'content': 'Hello World'}}]}

Methods:

update(text, **kwargs)

Updates the rich text property value.

Attributes:

value

Returns the string representation of the rich text property value.

update(text: Any, **kwargs) None[source]

Updates the rich text property value.

Parameters:
  • text (str) – text to update the rich text property value with.

  • **kwargs – additional arguments to pass to the Rich Text Object, such as bold, italic, etc.

property value: str

Returns the string representation of the rich text property value.

class SelectPropertyValue(name: str, color: Optional[str] = None, id: Optional[str] = None, raw: Optional[Dict] = None)[source]

Bases: PropertyValue

Initializes a select property value.

Parameters:
  • name (str) – name of the select option.

  • color (str, optional) – color option. Defaults to None.

  • id (str, optional) – property_value_id. Defaults to None.

Returns:

Select property value object.

Return type:

SelectPropertyValue

Example

>>> select = SelectPropertyValue("Option 1")
>>> select
Option 1
>>> select.to_notion()
{'select': {'name': 'Option 1'}}

Methods:

update([name, color])

Updates the select property value arguments.

Attributes:

value

Returns the string representation of the select property value.

update(name: Optional[str] = None, color: Optional[str] = None) None[source]

Updates the select property value arguments.

Parameters:
  • name (str, optional) – name of option. Defaults to None.

  • color (str, optional) – color type. Defaults to None.

Example

>>> select = SelectPropertyValue("Option 1")
>>> select
Option 1
>>> select.update("Option 2")
>>> select
Option 2
property value: str

Returns the string representation of the select property value.

class MultiSelectPropertyValue(names: List[str], id=None, raw=None)[source]

Bases: PropertyValue

Similar to SelectPropertyValue, but allows for multiple options to be selected.

Parameters:
  • names (List[str]) – list of names of the select options.

  • colors (List[str], optional) – list of colors of the select options. Defaults to None. Note: currently not supported.

  • id (str, optional) – property_value_id. Defaults to None.

Returns:

MultiSelect property value object.

Return type:

MultiSelectPropertyValue

Example

>>> multi_select = MultiSelectPropertyValue(["Option 1", "Option 2"])
>>> multi_select
['Option 1', 'Option 2']

Methods:

update(names)

Updates the multi_select property value.

Attributes:

value

Returns the string representation of the multi_select property value.

update(names: List[str]) None[source]

Updates the multi_select property value.

Parameters:

names (List[str]) – new list of options to update the multi_select property value with.

property value: str

Returns the string representation of the multi_select property value.

class NumberPropertyValue(number: float, id=None, raw=None)[source]

Bases: PropertyValue

Number property value object.

Create a number object. Either pass in a number or a string that can be converted to a number. Will convert to a float if a string is passed in.

Note

Options such as number format are provided to the parent schema object and not the property value. They apply to the whole database column

Parameters:
  • number (numeric) – number to initialize the number property value with.

  • id (str, optional) – property_value_id. Defaults to None.

Returns:

Number property value object.

Return type:

NumberPropertyValue

Example

>>> number = NumberPropertyValue(1)
>>> number
1
>>> number.to_notion()
{'number': 1.0}

Methods:

update(number)

Updates number object

Attributes:

value

Returns the string representation of the number property value.

update(number) None[source]

Updates number object

Parameters:

number (numeric) – new number

property value: str

Returns the string representation of the number property value.

class DatePropertyValue(start: Union[str, datetime], end: Optional[Union[str, datetime]] = None, timezone: Optional[str] = None, id=None, raw=None)[source]

Bases: PropertyValue

Date property value object.

Notion’s date supports only iso8601 format. The initializer expects either a string or a datetime object. If a string is passed in, no conversion or validation is done.

Parameters:
  • start (str or datetime) – date to initialize the date property value with.

  • end (str or datetime, optional) – end date. Defaults to None.

  • timezone (str, optional) – timezone according to Notion timezone str. Defaults to None. Example: “America/Los_Angeles”

  • id (str, optional) – property_value_id. Defaults to None.

Returns:

Date property value object.

Return type:

DatePropertyValue

Methods:

update([start, end, timezone])

Updates properties of the date property value.

Attributes:

value

update(start: Optional[Union[str, datetime]] = None, end: Optional[Union[str, datetime]] = None, timezone: Optional[str] = None) None[source]

Updates properties of the date property value.

Parameters:
  • start (Union[str, datetime], optional) – start date. Defaults to None.

  • end (Union[str, datetime], optional) – end date. Defaults to None.

  • timezone (str, optional) – timezone. Defaults to None.

property value: str
class FormulaPropertyValue(formula: PropertyValue, id=None, raw=None)[source]

Bases: PropertyValue

Formula property value.

Only accepts a formula attribute, no other attributes are allowed.

Parameters:
  • formula (str) – formula to initialize the formula property value with.

  • id (str, optional) – property_value_id. Defaults to None.

Returns:

Formula property value object.

Return type:

FormulaPropertyValue

Example

>>> formula = FormulaPropertyValue("=1+1")
>>> formula
'=1+1'

Methods:

update(formula)

Updates the formula property value.

Attributes:

value

Returns the string representation of the formula property value.

update(formula: str) None[source]

Updates the formula property value.

Parameters:

formula (str) – new formula to update the formula property value with.

property value: str

Returns the string representation of the formula property value.

class RelationPropertyValue(**kwargs)[source]

Bases: PropertyValue

class CheckboxPropertyValue(checked: bool, raw=None, **kwargs)[source]

Bases: PropertyValue

Checkbox property value object.

Parameters:
  • checked (bool) – checked to initialize the checkbox property value with.

  • id (str, optional) – property_value_id. Defaults to None.

Returns:

Checkbox property value object.

Return type:

CheckboxPropertyValue

Example

>>> checkbox = CheckboxPropertyValue(True)
>>> checkbox
True

Methods:

update(checked)

Updates the property value.

Attributes:

value

update(checked: bool) None[source]

Updates the property value. :param value: The new value

property value: str