Blocks
blocks ¶
Blocks that make up the content of a page.
AnyBlock: TypeAlias = Block[Any] module-attribute ¶
For type hinting purposes, especially for lists of blocks, i.e. list[AnyBlock], in user code.
BT = TypeVar('BT', bound=obj_blocks.Block) module-attribute ¶
DO = TypeVar('DO', bound=obj_blocks.DataObject) module-attribute ¶
FT = TypeVar('FT', bound=obj_blocks.FileBase) module-attribute ¶
MIN_COLS = 2 module-attribute ¶
Minimum number of columns when creating a column block to structure a page.
Block(*args: Any, **kwargs: Any) ¶
Abstract Notion block.
Parent class of all block types.
discussions: tuple[Discussion, ...] property ¶
Return comments of this block as list of discussions, i.e. threads of comments.
insert_after(blocks: Block | Sequence[Block]) -> None ¶
Insert a block or several blocks after this block.
reload() -> Self ¶
Reload the block from the API.
replace(blocks: Block | Sequence[Block]) -> None ¶
Replace this block with another block or blocks.
Bookmark(url: str, *, caption: str | None = None) ¶
BulletedItem(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Bulleted list item.
to_markdown() -> str ¶
Callout(text: str, *, color: Color | BGColor = Color.DEFAULT, icon: FileInfo | Emoji | CustomEmoji | None = None) ¶
Callout block.
Note
The default icon is an electric light bulb, i.e. 💡 in case None is passed as icon. It is not possible to remove the icon, but you can change it to a different emoji or a file.
CaptionMixin(*args: Any, **kwargs: Any) ¶
Mixin for objects that can have captions.
caption: Text | None property writable ¶
Return the caption of the code block.
ChildDatabase() ¶
Child database block.
Note
To create a child database block as an end-user, create a new database with the corresponding parent. This block is used only internally.
ChildPage() ¶
ChildrenMixin(*args: Any, **kwargs: Any) ¶
Mixin for data objects that can have children
Note that we don't use the children property of some Notion objects, e.g. paragraph, quote, etc., as not every object has this property, e.g. a page, database or toggable heading.
Code(text: str, *, language: CodeLang = CodeLang.PLAIN_TEXT, caption: str | None = None) ¶
ColoredTextBlock(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Abstract Text block with color.
Parent class of all text block types with color.
color: Color | BGColor property writable ¶
Return the color of the text block.
Column() ¶
Columns(columns: int | Sequence[float | int]) ¶
Columns block holding multiple Column blocks.
This block is used to create a layout with multiple columns in a single page. Either specify the number of columns as an integer or provide a sequence of width ratios, which can be positive integers or floats.
width_ratios: tuple[float | None, ...] property writable ¶
Return the width ratios of the columns.
__getitem__(index: int) -> Column ¶
add_column(index: int | None = None) -> Self ¶
Add a new column to this block of columns at the given index.
The index must be between 0 and the number of columns (inclusive). If no index is given, the new column is added at the end.
To specify the width ratio of the new column, use the width_ratios property.
append(blocks: Block | Sequence[Block], *, after: Block | None = None) -> Self ¶
Append a block or a sequence of blocks to the content of this block.
to_markdown() -> str ¶
Return the content of all columns as Markdown.
CommentMixin(*args: Any, **kwargs: Any) ¶
Mixin for objects that can have comments and discussions.
DataObject(*args: Any, **kwargs: Any) ¶
The base type for all data-related types, i.e, pages, databases and blocks.
block_url: str property ¶
Return the URL of the block.
Note
Databases and pages are also considered blocks in Notion but they also have a long-form URL. Use the url property to get the long-form URL.
has_children: bool property ¶
Return whether the object has children.
is_deleted: bool property ¶
Return wether the object is in trash.
last_edited_by: User property ¶
Return the user who last edited the block.
delete() -> Self ¶
Delete the block.
Pages and databases are moved to the trash, blocks are deleted permanently.
to_markdown() -> str abstractmethod ¶
Return the content of the block as Markdown.
Embed(url: str, *, caption: str | None = None) ¶
Equation(latex: str) ¶
File(name: str, url: str, *, caption: str | None = None) ¶
File block.
Note
Only the caption and name can be modified, the URL is read-only. Note that only the file name not the file suffix can be modified, the suffix is determined initially by the url.
FileBaseBlock(url: str, *, caption: str | None = None, name: str | None = None) ¶
Heading(text: str, *, color: Color | BGColor = Color.DEFAULT, toggleable: bool = False) ¶
Heading1(text: str, *, color: Color | BGColor = Color.DEFAULT, toggleable: bool = False) ¶
Heading 1 block.
to_markdown() -> str ¶
Heading2(text: str, *, color: Color | BGColor = Color.DEFAULT, toggleable: bool = False) ¶
Heading 2 block.
to_markdown() -> str ¶
Heading3(text: str, *, color: Color | BGColor = Color.DEFAULT, toggleable: bool = False) ¶
Heading 3 block.
to_markdown() -> str ¶
Image(url: str, *, caption: str | None = None) ¶
Image block.
Note
Only the caption can be modified, the URL is read-only.
to_markdown() -> str ¶
Return the image as Markdown.
LinkPreview(url: str) ¶
LinkToPage(page: Page) ¶
NumberedItem(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Numbered list item.
to_markdown() -> str ¶
PDF(url: str, *, caption: str | None = None, name: str | None = None) ¶
PDF block.
Note
Only the caption can be modified, the URL is read-only.
to_markdown() -> str ¶
Return the PDF as Markdown.
Paragraph(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Paragraph block.
SyncedBlock(blocks: Block | Sequence[Block]) ¶
Synced block - either original or synced.
is_original: bool property ¶
Return if this block is the original block.
is_synced: bool property ¶
Return if this block is synced from another block.
create_synced() -> SyncedBlock ¶
Return the synced block for appending.
get_original() -> SyncedBlock ¶
Return the original block.
to_markdown(*, with_comment: bool = True) -> str ¶
Return the content of this synced block as Markdown.
Table(n_rows: int, n_cols: int, *, header_col: bool = False, header_row: bool = False) ¶
Table block.
children: tuple[TableRow, ...] property ¶
Return all rows of the table.
has_header_col: bool property writable ¶
Return whether the table has a header column.
has_header_row: bool property writable ¶
Return whether the table has a header row.
shape: tuple[int, int] property ¶
Return the shape of the table.
width: int property ¶
Return the width, i.e. number of columns, of the table.
__getitem__(index: int | tuple[int, int]) -> Text | TableRow | None ¶
__getitem__(index: int) -> TableRow
__getitem__(index: tuple[int, int]) -> Text | None
__setitem__(index: int | tuple[int, int], value: str | Sequence[str | None] | None) -> None ¶
__str__() -> str ¶
append_row(values: Sequence[str]) -> Self ¶
Append a new row to the table.
insert_row(index: int, values: Sequence[str]) -> Self ¶
Insert a new row at the given index.
to_markdown() -> str ¶
Return the table as Markdown.
TableOfContents(*, color: Color | BGColor = Color.DEFAULT) ¶
Table of Contents block.
to_markdown() -> str ¶
TableRow(*cells: str | None) ¶
Template() ¶
Template block.
Deprecated
As of March 27, 2023 creation of template blocks will no longer be supported.
to_markdown() -> str ¶
Return the template content as Markdown.
TextBlock(text: str) ¶
ToDoItem(text: str, *, checked: bool = False, color: Color | BGColor = Color.DEFAULT) ¶
ToggleItem(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Toggle list item.
to_markdown() -> str ¶
Unsupported() ¶
Unsupported block in the API.
Some blocks like buttons, AI blocks, or templates are not supported by the Notion API. They will be returned as Unsupported blocks when fetched, but cannot be created or modified.
to_markdown() -> str ¶
Return a placeholder for unsupported blocks.
Video(url: str, *, caption: str | None = None, name: str | None = None) ¶
Video block.
Note
Only the caption can be modified, the URL is read-only.
to_markdown() -> str ¶
Return the video as Markdown.
wrap_icon(icon_obj: objs.FileObject | objs.EmojiObject | objs.CustomEmojiObject) -> FileInfo | CustomEmoji | Emoji ¶
Wrap the icon object into the corresponding class.