Reference
ultimate_notion ¶
Ultimate Notion provides a pythonic, high-level API for Notion.
Notion-API: https://developers.notion.com/reference/intro
DateTimeOrRange: TypeAlias = dt.datetime | dt.date | pnd.Interval[pnd.DateTime] | pnd.Interval[pnd.Date] module-attribute ¶
A type alias for various date, date time and interval representations.
Workspace: Final = _Workspace.ROOT module-attribute ¶
This represents the actual root workspace in Notion.
WorkspaceType: TypeAlias = Literal[_Workspace.ROOT] module-attribute ¶
This represents the type of the root workspace in Notion for type hinting.
__all__ = ['PDF', 'AggFunc', 'AnyFile', 'Audio', 'BGColor', 'Block', 'Bookmark', 'Breadcrumb', 'BuiltInIcon', 'BulletedItem', 'Callout', 'Code', 'CodeLang', 'Color', 'Column', 'Columns', 'Condition', 'CustomEmoji', 'DataSource', 'Database', 'DateTimeOrRange', 'Divider', 'Embed', 'Emoji', 'Equation', 'ExternalFile', 'File', 'FileUploadStatus', 'Heading1', 'Heading2', 'Heading3', 'Heading4', 'Image', 'LinkPreview', 'LinkToPage', 'NotionFile', 'NumberFormat', 'NumberedItem', 'Option', 'OptionGroup', 'OptionGroupType', 'OptionNS', 'Page', 'Paragraph', 'PlaceDict', 'PropType', 'Property', 'Quote', 'SList', 'Schema', 'SelfRef', 'Session', 'SyncedBlock', 'Table', 'TableOfContents', 'TableRow', 'Tabs', 'ToDoItem', 'ToggleItem', 'User', 'VState', 'Video', 'Workspace', 'WorkspaceType', '__version__', 'get_active_session', 'join', 'math', 'mention', 'prop', 'text', 'url'] module-attribute ¶
__version__ = version('ultimate-notion') module-attribute ¶
AggFunc ¶
Aggregation functions for formulas.
The categories naming corresonds mostly to the naming in the Notion App but also eliminates some inconsistencies. The first part of the tuple is the string used in the Notion API, the second part is an alias corresoinding to the defined category num.
AVERAGE = ('average', 'average') class-attribute instance-attribute ¶
COUNT_ALL = ('count', 'count_all') class-attribute instance-attribute ¶
COUNT_CHECKED = ('checked', 'count_checked') class-attribute instance-attribute ¶
COUNT_EMPTY = ('empty', 'count_empty') class-attribute instance-attribute ¶
COUNT_NOT_EMPTY = ('not_empty', 'count_not_empty') class-attribute instance-attribute ¶
COUNT_PER_GROUP = ('count_per_group', 'count_per_group') class-attribute instance-attribute ¶
COUNT_UNCHECKED = ('unchecked', 'count_unchecked') class-attribute instance-attribute ¶
COUNT_UNIQUE_VALUES = ('unique', 'count_unique_values') class-attribute instance-attribute ¶
COUNT_VALUES = ('count_values', 'count_values') class-attribute instance-attribute ¶
DATE_RANGE = ('date_range', 'date_range') class-attribute instance-attribute ¶
EARLIEST_DATE = ('earliest_date', 'earliest_date') class-attribute instance-attribute ¶
LATEST_DATE = ('latest_date', 'latest_date') class-attribute instance-attribute ¶
MAX = ('max', 'max') class-attribute instance-attribute ¶
MEDIAN = ('median', 'median') class-attribute instance-attribute ¶
MIN = ('min', 'min') class-attribute instance-attribute ¶
PERCENT_CHECKED = ('percent_checked', 'percent_checked') class-attribute instance-attribute ¶
PERCENT_EMPTY = ('percent_empty', 'percent_empty') class-attribute instance-attribute ¶
PERCENT_NOT_EMPTY = ('percent_not_empty', 'percent_not_empty') class-attribute instance-attribute ¶
PERCENT_PER_GROUP = ('percent_per_group', 'percent_per_group') class-attribute instance-attribute ¶
RANGE = ('range', 'range') class-attribute instance-attribute ¶
SHOW_ORIGINAL = ('show_original', 'show_original') class-attribute instance-attribute ¶
SHOW_UNIQUE = ('show_unique', 'show_unique') class-attribute instance-attribute ¶
SUM = ('sum', 'sum') class-attribute instance-attribute ¶
alias: str instance-attribute ¶
__new__(value: str, alias: str = '') -> AggFunc ¶
from_alias(alias: str) -> AggFunc classmethod ¶
AnyFile(*args: Any, **kwargs: Any) ¶
Audio(file: AnyFile, *, caption: str | None = None) ¶
Audio block.
Note
Only the caption can be modified, the URL is read-only.
to_markdown() -> str ¶
Return the audio as Markdown.
BGColor ¶
Background colors for most textual blocks, e.g. paragraphs, callouts, etc.
BLUE = 'blue_background' class-attribute instance-attribute ¶
BROWN = 'brown_background' class-attribute instance-attribute ¶
DEFAULT = 'default' class-attribute instance-attribute ¶
GRAY = 'gray_background' class-attribute instance-attribute ¶
GREEN = 'green_background' class-attribute instance-attribute ¶
ORANGE = 'orange_background' class-attribute instance-attribute ¶
PINK = 'pink_background' class-attribute instance-attribute ¶
PURPLE = 'purple_background' class-attribute instance-attribute ¶
RED = 'red_background' class-attribute instance-attribute ¶
YELLOW = 'yellow_background' class-attribute instance-attribute ¶
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.
parent: Block | Page | None property ¶
Return the parent block or page, or None if not accessible.
__eq__(other: Any | Block) -> bool ¶
Compare blocks by their content, not by their metadata like id, timestamp etc.
__hash__() -> int ¶
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) ¶
BuiltInIcon() ¶
BulletedItem(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Bulleted list item.
to_markdown() -> str ¶
Callout(text: str, *, color: Color | BGColor = Color.DEFAULT, icon: AnyFile | str | Emoji | CustomEmoji | BuiltInIcon = '💡') ¶
Callout block.
Note
The default icon is an electric light bulb, i.e. 💡. Currently it is not supported by the Notion API to have a callout block without an icon.
Code(text: str, *, language: str | CodeLang = CodeLang.PLAIN_TEXT, caption: str | None = None) ¶
CodeLang ¶
Coding languages for code blocks.
ABAP = 'abap' class-attribute instance-attribute ¶
ARDUINO = 'arduino' class-attribute instance-attribute ¶
BASH = 'bash' class-attribute instance-attribute ¶
BASIC = 'basic' class-attribute instance-attribute ¶
C = 'c' class-attribute instance-attribute ¶
CLOJURE = 'clojure' class-attribute instance-attribute ¶
COFFEESCRIPT = 'coffeescript' class-attribute instance-attribute ¶
CPP = 'c++' class-attribute instance-attribute ¶
CSHARP = 'c#' class-attribute instance-attribute ¶
CSS = 'css' class-attribute instance-attribute ¶
DART = 'dart' class-attribute instance-attribute ¶
DIFF = 'diff' class-attribute instance-attribute ¶
DOCKER = 'docker' class-attribute instance-attribute ¶
ELIXIR = 'elixir' class-attribute instance-attribute ¶
ELM = 'elm' class-attribute instance-attribute ¶
ERLANG = 'erlang' class-attribute instance-attribute ¶
FLOW = 'flow' class-attribute instance-attribute ¶
FORTRAN = 'fortran' class-attribute instance-attribute ¶
FSHARP = 'f#' class-attribute instance-attribute ¶
GHERKIN = 'gherkin' class-attribute instance-attribute ¶
GLSL = 'glsl' class-attribute instance-attribute ¶
GO = 'go' class-attribute instance-attribute ¶
GRAPHQL = 'graphql' class-attribute instance-attribute ¶
GROOVY = 'groovy' class-attribute instance-attribute ¶
HASKELL = 'haskell' class-attribute instance-attribute ¶
HTML = 'html' class-attribute instance-attribute ¶
JAVA = 'java' class-attribute instance-attribute ¶
JAVASCRIPT = 'javascript' class-attribute instance-attribute ¶
JSON = 'json' class-attribute instance-attribute ¶
JULIA = 'julia' class-attribute instance-attribute ¶
KOTLIN = 'kotlin' class-attribute instance-attribute ¶
LATEX = 'latex' class-attribute instance-attribute ¶
LESS = 'less' class-attribute instance-attribute ¶
LISP = 'lisp' class-attribute instance-attribute ¶
LIVESCRIPT = 'livescript' class-attribute instance-attribute ¶
LUA = 'lua' class-attribute instance-attribute ¶
MAKEFILE = 'makefile' class-attribute instance-attribute ¶
MARKDOWN = 'markdown' class-attribute instance-attribute ¶
MARKUP = 'markup' class-attribute instance-attribute ¶
MATLAB = 'matlab' class-attribute instance-attribute ¶
MERMAID = 'mermaid' class-attribute instance-attribute ¶
MISC = 'java/c/c++/c#' class-attribute instance-attribute ¶
NIX = 'nix' class-attribute instance-attribute ¶
OBJECTIVE_C = 'objective-c' class-attribute instance-attribute ¶
OCAML = 'ocaml' class-attribute instance-attribute ¶
PASCAL = 'pascal' class-attribute instance-attribute ¶
PERL = 'perl' class-attribute instance-attribute ¶
PHP = 'php' class-attribute instance-attribute ¶
PLAIN_TEXT = 'plain text' class-attribute instance-attribute ¶
POWERSHELL = 'powershell' class-attribute instance-attribute ¶
PROLOG = 'prolog' class-attribute instance-attribute ¶
PROTOBUF = 'protobuf' class-attribute instance-attribute ¶
PYTHON = 'python' class-attribute instance-attribute ¶
R = 'r' class-attribute instance-attribute ¶
REASON = 'reason' class-attribute instance-attribute ¶
RUBY = 'ruby' class-attribute instance-attribute ¶
RUST = 'rust' class-attribute instance-attribute ¶
SASS = 'sass' class-attribute instance-attribute ¶
SCALA = 'scala' class-attribute instance-attribute ¶
SCHEME = 'scheme' class-attribute instance-attribute ¶
SCSS = 'scss' class-attribute instance-attribute ¶
SHELL = 'shell' class-attribute instance-attribute ¶
SQL = 'sql' class-attribute instance-attribute ¶
SWIFT = 'swift' class-attribute instance-attribute ¶
TOML = 'toml' class-attribute instance-attribute ¶
TYPESCRIPT = 'typescript' class-attribute instance-attribute ¶
VB_NET = 'vb.net' class-attribute instance-attribute ¶
VERILOG = 'verilog' class-attribute instance-attribute ¶
VHDL = 'vhdl' class-attribute instance-attribute ¶
VISUAL_BASIC = 'visual basic' class-attribute instance-attribute ¶
WEBASSEMBLY = 'webassembly' class-attribute instance-attribute ¶
XML = 'xml' class-attribute instance-attribute ¶
YAML = 'yaml' class-attribute instance-attribute ¶
Color ¶
Basic colors
DEFAULT is a light gray, which is the default color in the Notion App.
BLUE = 'blue' class-attribute instance-attribute ¶
BROWN = 'brown' class-attribute instance-attribute ¶
DEFAULT = 'default' class-attribute instance-attribute ¶
GRAY = 'gray' class-attribute instance-attribute ¶
GREEN = 'green' class-attribute instance-attribute ¶
ORANGE = 'orange' class-attribute instance-attribute ¶
PINK = 'pink' class-attribute instance-attribute ¶
PURPLE = 'purple' class-attribute instance-attribute ¶
RED = 'red' class-attribute instance-attribute ¶
YELLOW = 'yellow' class-attribute instance-attribute ¶
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.
children: tuple[Column, ...] property ¶
Return all columns of this multi-column block. Alias for columns.
columns: tuple[Column, ...] property ¶
Return all columns of this multi-column block.
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, sync: bool | 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.
Condition ¶
Base class for filter query conditions.
is_method: bool = False class-attribute instance-attribute ¶
__and__(other: Condition) -> Condition ¶
__iand__(other: Condition) -> Condition ¶
__ior__(other: Condition) -> Condition ¶
__or__(other: Condition) -> Condition ¶
__repr__() -> str abstractmethod ¶
__str__() -> str ¶
create_obj_ref(ds: DataSource) -> obj_query.QueryFilter abstractmethod ¶
CustomEmoji() ¶
DataSource(*args: Any, **kwargs: Any) ¶
A Notion data source.
A data source contains the schema (properties) and pages. This object always represents an original data source, not a linked one.
API reference: https://developers.notion.com/reference/data-source
database_id: UUID property ¶
Return the id of the database container that holds this data source.
The container is transparent in the hierarchy (parent/ancestors skip it), but it is what a mention or the public URL of this data source actually points to, so its id is exposed here. Use session.get_db(ds.database_id) to retrieve the container Database object itself.
db_parent: NotionEntity | WorkspaceType | None property ¶
Alias of parent: the parent of this data source's (transparent) database container.
description: Text | None property writable ¶
Return the description of this data source as rich text.
is_ds: bool property ¶
Return whether the object is a data source.
is_empty: bool property ¶
Return whether the data source is empty.
is_inline: bool property writable ¶
Return whether the data source's database is displayed inline on its parent page.
is_locked: bool property writable ¶
Return whether this data source's database is locked for editing.
parent: NotionEntity | WorkspaceType | None property ¶
Return the parent of this data source.
The 2025-09-03 API nests every data source inside a database container. That container is transparent in the high-level API: a data source presents as a child of the page (or workspace) that holds its database. The parent is therefore resolved from database_parent (the database's parent) rather than the immediate parent ref (the container database).
query: Query property ¶
Return a Query object to build and execute a data source query.
schema: type[Schema] property writable ¶
Schema of the data source.
url: str property ¶
Return the public URL of this data source's database.
__bool__() -> bool ¶
Overwrite default behaviour.
__len__() -> int ¶
Return the number of pages in this data source.
__repr__() -> str ¶
__str__() -> str ¶
create_page(**kwargs: Any) -> Page ¶
Create a page with properties according to the schema within the corresponding data source.
delete() -> Self ¶
Delete this data source.
get_all_pages() -> View ¶
Retrieve all pages and return a view.
move(database: Database) -> Self ¶
Move this data source to a different parent database.
Reassigns the data source from its current container database to database. Cached children of the old and new parent are invalidated so the hierarchy reflects the move.
reload(*, rebind_schema: bool = True) -> Self ¶
Reload this data source.
If rebind_schema is True, the schema will be rebound to the current data source. Otherwise, the schema will set to the reflected schema of the current data source.
restore() -> Self ¶
Restore this data source.
to_markdown() -> str ¶
Return the reference to this data source as Markdown.
Database(*args: Any, **kwargs: Any) ¶
A Notion database - a collection that can contain multiple data sources.
API reference: https://developers.notion.com/docs/working-with-databases
data_sources: SList[DataSource] property ¶
Return all data sources in this database.
Trashed data sources are excluded: Notion keeps them in the container's raw list even after they are moved to the trash, so they are filtered out here (use restore_ds() to bring one back).
is_db: bool property ¶
Check if this is a database (always True for Database objects).
is_inline: bool property writable ¶
Return whether the database is inline.
is_locked: bool property writable ¶
Return whether the database is locked for editing.
is_wiki: bool property ¶
Return whether the database is a wiki.
public_url: str | None property ¶
Return the public URL of this database, if available.
query: Query property ¶
Return a Query object of the database if it has a single data source.
url: str property ¶
Return the public URL of this database.
__eq__(other: object) -> bool ¶
Compare Database objects.
__hash__() -> int ¶
Hash the Database object.
__repr__() -> str ¶
__str__() -> str ¶
create_ds(*, schema: type[Schema] | None = None, title: str | None = None) -> DataSource ¶
Add a new data source to this database.
In case a title and a schema are provided, the title overrides the schema's db_title. If no schema is given, a default single-title schema is used. Use delete_ds() to remove one again.
delete() -> Self ¶
Delete (move to trash) this database and all of its data sources.
delete_ds(ds: DataSource) -> DataSource ¶
Remove (move to trash) a single data source from this database.
The data source's siblings and the database container itself are left untouched. To delete the whole database (and all its data sources), use delete(). Restore a removed data source with restore_ds().
get_all_pages() -> SList[View] ¶
Retrieve all pages of all databases as a list of views.
reload() -> Self ¶
Reload this database from Notion, refreshing its data sources and metadata.
restore() -> Self ¶
Restore this database from trash.
restore_ds(ds: DataSource) -> DataSource ¶
Restore a data source previously removed from this database with delete_ds().
to_markdown() -> str ¶
Return the reference to this database as Markdown.
Embed(url: str, *, caption: str | None = None) ¶
Emoji(emoji: str) ¶
Equation(latex: str) ¶
ExternalFile(*, url: str, name: str | None = None, caption: str | None = None) ¶
File(file: AnyFile, *, name: str | None = None, caption: str | None = None) ¶
File block.
Note
Only the caption and name can be modified, the file object is read-only. Note that only the file name not the file suffix can be modified, the suffix is determined initially by the url.
FileUploadStatus ¶
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 ¶
Heading4(text: str, *, color: Color | BGColor = Color.DEFAULT, toggleable: bool = False) ¶
Heading 4 block.
to_markdown() -> str ¶
Image(file: AnyFile, *, 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) ¶
NotionFile(*, url: str, name: str | None = None, caption: str | None = None) ¶
NumberFormat ¶
Number formats for numbers.
ARGENTINE_PESO = 'argentine_peso' class-attribute instance-attribute ¶
AUSTRALIAN_DOLLAR = 'australian_dollar' class-attribute instance-attribute ¶
BAHT = 'baht' class-attribute instance-attribute ¶
CANADIAN_DOLLAR = 'canadian_dollar' class-attribute instance-attribute ¶
CHILEAN_PESO = 'chilean_peso' class-attribute instance-attribute ¶
COLOMBIAN_PESO = 'colombian_peso' class-attribute instance-attribute ¶
DANISH_KRONE = 'danish_krone' class-attribute instance-attribute ¶
DIRHAM = 'dirham' class-attribute instance-attribute ¶
DOLLAR = 'dollar' class-attribute instance-attribute ¶
EURO = 'euro' class-attribute instance-attribute ¶
FORINT = 'forint' class-attribute instance-attribute ¶
FRANC = 'franc' class-attribute instance-attribute ¶
HONG_KONG_DOLLAR = 'hong_kong_dollar' class-attribute instance-attribute ¶
KORUNA = 'koruna' class-attribute instance-attribute ¶
KRONA = 'krona' class-attribute instance-attribute ¶
LEU = 'leu' class-attribute instance-attribute ¶
LIRA = 'lira' class-attribute instance-attribute ¶
MEXICAN_PESO = 'mexican_peso' class-attribute instance-attribute ¶
NEW_TAIWAN_DOLLAR = 'new_taiwan_dollar' class-attribute instance-attribute ¶
NEW_ZEALAND_DOLLAR = 'new_zealand_dollar' class-attribute instance-attribute ¶
NORWEGIAN_KRONE = 'norwegian_krone' class-attribute instance-attribute ¶
NUMBER = 'number' class-attribute instance-attribute ¶
NUMBER_WITH_COMMAS = 'number_with_commas' class-attribute instance-attribute ¶
PERCENT = 'percent' class-attribute instance-attribute ¶
PHILIPPINE_PESO = 'philippine_peso' class-attribute instance-attribute ¶
POUND = 'pound' class-attribute instance-attribute ¶
RAND = 'rand' class-attribute instance-attribute ¶
REAL = 'real' class-attribute instance-attribute ¶
RINGGIT = 'ringgit' class-attribute instance-attribute ¶
RIYAL = 'riyal' class-attribute instance-attribute ¶
RUBLE = 'ruble' class-attribute instance-attribute ¶
RUPEE = 'rupee' class-attribute instance-attribute ¶
RUPIAH = 'rupiah' class-attribute instance-attribute ¶
SHEKEL = 'shekel' class-attribute instance-attribute ¶
URUGUAYAN_PESO = 'uruguayan_peso' class-attribute instance-attribute ¶
WON = 'won' class-attribute instance-attribute ¶
YEN = 'yen' class-attribute instance-attribute ¶
YUAN = 'yuan' class-attribute instance-attribute ¶
ZLOTY = 'zloty' class-attribute instance-attribute ¶
NumberedItem(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Numbered list item.
to_markdown() -> str ¶
Option(name: str, *, color: Color | str | UnsetType = Unset) ¶
Option for select & multi-select property.
OptionGroup(group_type: OptionGroupType | str, options: list[Option]) ¶
Group of options for status property.
name: str property ¶
Name of the option group.
options: list[Option] property ¶
Options within this option group.
__eq__(other: object) -> bool ¶
__hash__() -> int ¶
__repr__() -> str ¶
__str__() -> str ¶
wrap_obj_ref(obj_ref: obj_core.GenericObject, /, *, options: list[Option] | None = None) -> OptionGroup classmethod ¶
Convienence constructor for the group of options.
OptionGroupType ¶
OptionNS ¶
Option namespace to simplify working with (Multi-)Select options.
PDF(file: AnyFile, *, caption: 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.
Page(*args: Any, **kwargs: Any) ¶
A Notion page.
Attributes:
| Name | Type | Description |
|---|---|---|
props | PagePropertiesNS | accessor for all page properties |
comments: Discussion property ¶
Return the discussion thread of this page.
A page can only have a single discussion thread in contrast to inline comments.
Note
This functionality requires that your integration was granted read comment capabilities.
cover: ExternalFile | NotionFile | None property writable ¶
Cover of the page.
icon: NotionFile | ExternalFile | Emoji | CustomEmoji | BuiltInIcon | None property writable ¶
Icon of the page, i.e. emojis, Notion's icons, or custom images.
in_ds: bool property ¶
Return True if this page is located in a data source.
is_locked: bool property writable ¶
Return whether the page is locked for editing.
is_page: bool property ¶
Return whether the object is a page.
parent_ds: DataSource | None property ¶
If this page is located in a data source return the data source or None otherwise.
This is a convenience method to avoid the need to check and cast the type of the parent.
props: PagePropertiesNS instance-attribute ¶
public_url: str | None property ¶
Return the public URL of this page.
sub_dss: list[DataSource] property ¶
Return all contained data sources within this page.
subpages: list[Page] property ¶
Return all contained pages within this page
title: Text | None property writable ¶
Title of the page.
url: str property ¶
Return the URL of this page.
__repr__() -> str ¶
__str__() -> str ¶
delete() -> Self ¶
Delete this page.
Warning
Deleting a page will also delete all child pages and child data sources recursively. If these objects are already cached in the session, they will not be updated. Use session.cache.clear() to clear the cache or call reload() on them.
get_property(prop_name: str) -> Any ¶
Directly retrieve the property value from the API.
Use this method only if you want to retrieve a specific property value that might have been updated on the server side without reloading the whole page. In all other cases, use the props namespace of the page to avoid unnecessary API calls.
reload() -> Self ¶
Reload this page.
restore() -> Self ¶
Restore this page.
show(*, simple: bool | None = None) -> None ¶
Show the content of the page, rendered in JupyterLab
to_html(*, raw: bool = False) -> str ¶
Return the content of the page as HTML.
to_markdown() -> str ¶
Return the content of the page as Markdown.
Note
This will not include nested blocks, i.e. the children of top-level blocks.
update_props(**kwargs: Any) -> None ¶
Update multiple properties at once.
Paragraph(text: str, *, color: Color | BGColor = Color.DEFAULT) ¶
Paragraph block.
icon: NotionFile | ExternalFile | Emoji | CustomEmoji | BuiltInIcon | None property writable ¶
Icon shown alongside the paragraph when it is used as a tab label.
Notion only allows an icon on a paragraph that is a direct child of a Tabs block, i.e. a tab label. A plain body paragraph never shows an icon, so reading this returns None for any non-tab paragraph.
Warning
Setting an icon only works on a tab-label paragraph. Notion rejects it on any other paragraph with Cannot set icon on a paragraph block that is not a direct child of a tab block.. Use Tabs.add_tab(label, icon=...), or set .icon on a paragraph already returned from a Tabs block (e.g. tabs[0].icon = '📋').
PlaceDict ¶
Dictionary type for Place property values.
PropType ¶
Namespace class of all creatable property types of a data source for easier access.
Checkbox = Checkbox class-attribute instance-attribute ¶
CreatedBy = CreatedBy class-attribute instance-attribute ¶
CreatedTime = CreatedTime class-attribute instance-attribute ¶
Date = Date class-attribute instance-attribute ¶
Email = Email class-attribute instance-attribute ¶
Files = Files class-attribute instance-attribute ¶
Formula = Formula class-attribute instance-attribute ¶
ID = ID class-attribute instance-attribute ¶
LastEditedBy = LastEditedBy class-attribute instance-attribute ¶
LastEditedTime = LastEditedTime class-attribute instance-attribute ¶
MultiSelect = MultiSelect class-attribute instance-attribute ¶
Number = Number class-attribute instance-attribute ¶
Person = Person class-attribute instance-attribute ¶
Phone = Phone class-attribute instance-attribute ¶
Place = Place class-attribute instance-attribute ¶
Relation = Relation class-attribute instance-attribute ¶
Rollup = Rollup class-attribute instance-attribute ¶
Select = Select class-attribute instance-attribute ¶
Status = Status class-attribute instance-attribute ¶
Text = Text class-attribute instance-attribute ¶
Title = Title class-attribute instance-attribute ¶
URL = URL class-attribute instance-attribute ¶
Property(name: str | None = None, **kwargs: Any) ¶
Base class for Notion property objects.
A property defines the name and type of a property in a data source, e.g. number, date, text, etc.
allowed_at_creation = True class-attribute instance-attribute ¶
If the Notion API allows to create a new data source with a property of this type
attr_name: str property writable ¶
Return the Python attribute name of the property in the schema.
description: str | None property ¶
Return the description of this property.
id: str | None property ¶
Return identifier of this property.
name: str property writable ¶
Return name of this property.
obj_ref = obj_api_type.build(**kwargs) instance-attribute ¶
prop_value: type[PropertyValue] property ¶
Return the corresponding property value of this property.
readonly: bool property ¶
Return if this property is read-only.
__eq__(other: object) -> bool ¶
__hash__() -> int ¶
__new__(*args: Any, **kwargs: Any) -> Property ¶
__repr__() -> str ¶
__str__() -> str ¶
delete() -> None ¶
Delete this property from the schema.
Schema ¶
Base class for the schema of a data source.
__init_subclass__(db_title: str | None = None, db_id: str | None = None, **kwargs: Any) ¶
assert_consistency_with(other_schema: type[Schema], *, during_init: bool = False) -> None classmethod ¶
Assert that this schema is consistent with another schema.
bind_ds(ds: DataSource | None = None) -> None classmethod ¶
Bind this schema to the corresponding data source for back-reference and vice versa.
If None (default) is passed, search for the data source using db_id or db_title and bind it to this schema.
create(**kwargs: Any) -> Page classmethod ¶
Create a page using this schema with a bound data source.
get_ro_props() -> list[Property] classmethod ¶
Get all read-only properties of this schema.
get_rw_props() -> list[Property] classmethod ¶
Get all writeable properties of this schema.
get_title_prop() -> Property classmethod ¶
Returns the property holding the title of the pages.
has_prop(prop_name: str) -> bool classmethod ¶
Check if a property exists in this schema.
show(*, simple: bool | None = None) -> None classmethod ¶
Show the schema as html or as simple table.
to_pydantic_model(*, with_ro_props: bool = False) -> type[SchemaModel] classmethod ¶
Return a Pydantic model of this schema for validation.
This is useful for instance when writing a web API that receives data that should be validated before it is passed to Ultimate Notion. The actual values are converted to PropertyValue and thus value needs to be called to retrieve the actual Python type.
If with_ro_props is set to True, read-only properties are included in the model.
SelfRef ¶
Target schema for self-referencing data source relations.
_ = Title('title') class-attribute instance-attribute ¶
Session(cfg: Config | None = None, *, client: notion_client.Client | None = None, **kwargs: Any) ¶
A session for the Notion API.
The session keeps tracks of all objects, e.g. pages, data sources, etc. in an object store to avoid unnecessary calls to the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg | Config | None | configuration object | None |
**kwargs | Any | Arguments for the Notion SDK Client | {} |
api: NotionAPI = NotionAPI(self.client) instance-attribute ¶
cache: dict[UUID, DataObject | User] = {} class-attribute ¶
client: notion_client.Client = create_notion_client(cfg, **kwargs) if client is None else client instance-attribute ¶
__enter__() -> Session ¶
__exit__(exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None ¶
all_users() -> list[User] ¶
Retrieve all users of this workspace.
close() -> None ¶
Close the session and release resources.
create_db(parent: Page, *, schema: type[Schema] | None = None, title: str | None = None, inline: bool = False) -> Database ¶
Create a new database (a container of data sources) within a page.
In API version 2025-09-03+ every data source lives inside a database container. This creates that container together with its first data source (from schema, or a default single-title schema) and returns the Database. Use db.create_ds(...) to add further data sources, and db.data_sources to list them. Pass inline=True to display the database inline on the page.
create_ds(parent: Page, *, schema: type[Schema] | None = None, title: str | None = None, inline: bool = False) -> DataSource ¶
Create a new data source within a page.
In API version 2025-09-03+ a data source under a page is created via the Create Database endpoint, which creates the database container together with its initial data source. This method returns that data source. Pass inline=True to display the database inline on the page.
In case a title and a schema are provided, title overrides the schema's db_title attribute if it exists.
create_page(parent: Page | DataSource, title: Text | str | None = None, blocks: Sequence[Block] | None = None, *, cover: AnyFile | None = None, icon: AnyFile | Emoji | CustomEmoji | str | None = None) -> Page ¶
Create a new page in a parent page or data source with a given title.
The blocks are optional and can be used to create a page with content right away. Note that some nested blocks may not be supported by the API and must be created separately, i.e. with an append call to a given block.
get_active() -> Session classmethod ¶
Return the current active session or None.
get_block(block_ref: UUID | str, *, use_cache: bool = True) -> Block ¶
Retrieve a single block by an object reference.
get_db(db_ref: UUID | str, *, use_cache: bool = True) -> Database ¶
Retrieve a Notion database (a container of data sources) by uuid.
get_ds(ds_ref: UUID | str, *, use_cache: bool = True) -> DataSource ¶
Retrieve Notion data source by uuid.
get_or_create(*args: Any, **kwargs: Any) -> Session classmethod ¶
Return the current active session or create a new session.
get_or_create_ds(parent: Page, schema: type[Schema]) -> DataSource ¶
Get or create the data source.
get_or_create_page(parent: Page | DataSource, title: str | None = None) -> Page ¶
Get an existing page or create a new one if it doesn't exist.
get_page(page_ref: UUID | str, *, use_cache: bool = True) -> Page ¶
Retrieve a page by uuid.
get_user(user_ref: UUID | str, *, use_cache: bool = True, raise_on_unknown: bool = True) -> User ¶
Get a user by uuid.
In case the user is not found and raise_on_unknown is False, an User object is returned with the name Unknown User, where the property is_unknown is set to True.
Warning
Trying to retrieve yourself, i.e. the bot integration, only works if use_cache is true, since the low-level api, i.e. api.users.retrieve() does not work for the bot integration. Better use whoami() to get the bot integration user object.
import_url(url: str, file_name: str, *, block: bool = True) -> UploadedFile ¶
Import a file from a URL.
is_closed() -> bool ¶
Determine if the session is closed or not.
list_uploads(filter: FileUploadStatus | None = None) -> list[UploadedFile] ¶
List all uploaded files and optionally filter by status.
raise_for_status() -> None ¶
Confirm that the session is active and raise otherwise.
Raises SessionError if there is a problem, otherwise returns None.
search_ds(name: str | None = None, *, exact: bool = True, reverse: bool = False, deleted: bool = False) -> SList[DataSource] ¶
Search a data source by name or return all if name is None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | None | name/title of the data source, return all if | None |
exact | bool | perform an exact search, not only a substring match | True |
reverse | bool | search in the reverse order, i.e. the least recently edited results first | False |
deleted | bool | include deleted data sources in search | False |
search_page(title: str | None = None, *, exact: bool = True, reverse: bool = False) -> SList[Page] ¶
Search a page by name. Deleted pages, i.e. in trash, are not included in the search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title | str | None | title of the page, return all if | None |
exact | bool | perform an exact search, not only a substring match | True |
reverse | bool | search in the reverse order, i.e. the least recently edited results first | False |
search_user(name: str) -> SList[User] ¶
Search a user by name.
upload(file: BinaryIO, *, file_name: str | None = None, mime_type: str | None = None) -> UploadedFile ¶
Upload a file to Notion.
whoami() -> Bot ¶
Return the integration as bot object.
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. Alias for rows.
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.
rows: tuple[TableRow, ...] property ¶
Return all rows of the table.
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) ¶
Tabs(tabs: Sequence[str]) ¶
Tabs block grouping content into labeled tabs.
Each tab is a Paragraph whose rich text is the tab label, with an optional icon, and whose children hold the tab content. Only paragraphs may be direct children of a tabs block. See https://developers.notion.com/changelog/tab-block-support
children: tuple[Paragraph, ...] property ¶
Return all tabs of this block. Alias for tabs.
tabs: tuple[Paragraph, ...] property ¶
Return all tabs of this block.
__getitem__(index: int) -> Paragraph ¶
add_tab(label: str, index: int | None = None, *, icon: AnyFile | Emoji | CustomEmoji | BuiltInIcon | str | None = None) -> Self ¶
Add a new tab with the given label and optional icon to this block at the given index.
The index must be between 0 and the number of tabs (inclusive). If no index is given, the new tab is added at the end.
The optional icon is shown alongside the label. Notion only allows an icon on a tab-label paragraph, which is exactly what a tab is, so it is always valid here (unlike a plain Paragraph.icon, which Notion rejects outside a tab).
Append content to the new tab by indexing into the block, e.g. tabs[-1].append(...).
append(blocks: Block | Sequence[Block], *, after: Block | None = None, sync: bool | 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 tabs as Markdown.
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 ¶
User(*args: Any, **kwargs: Any) ¶
User object for persons, bots and unknown users.
Unknown users are users, which no longer participate in the workspace or were revoked access. They are represented by their ID and have the name Unknown User.
avatar_url: str | None property ¶
Return the avatar URL of this user.
id: UUID property ¶
Return the ID of this user.
is_bot: bool property ¶
Return True if this user is a bot.
is_person: bool property ¶
Return True if this user is a person.
is_unknown: bool property ¶
Return True if this user is an unknown user.
name: str | None property ¶
Return the name of this user.
__eq__(other: object) -> bool ¶
__hash__() -> int ¶
__repr__() -> str ¶
__str__() -> str ¶
VState ¶
Video(file: AnyFile, *, caption: 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.
get_active_session() -> Session ¶
Return the current active session or raise an exception.
Avoids cyclic imports when used within the package itself. For internal use mostly.
join(texts: Sequence[str], *, delim: str = ' ') -> Text ¶
Join multiple str objects, including Text, into a single Text object with a given delimeter.
math(expression: str, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color = Color.DEFAULT) -> Text ¶
Create a Text that holds a formula.
mention(target: User | Page | DataSource | CustomEmoji | DateTimeOrRange, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color = Color.DEFAULT) -> Text ¶
Create a Text that mentions another object.
prop(prop_name: str) -> PageProperty ¶
Create a property object.
text(text: str, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color | BGColor | None = None, href: str | None = None) -> Text ¶
Create a rich text Text object from a normal string with formatting.
Note
With the color parameter the font color or the background color can be set. Unfortunately Notion's API does not allow to set both at the same time like in the Notion UI.
Warning
If a Text object is passed, the original formatting will be lost!
url(url: str, *, name: str | None = None, caption: str | None = None) -> NotionFile | ExternalFile ¶
Create a NotionFile or ExternalFile based on the URL.
A name and caption can be provided and will be used as default values, e.g. in a File block.