Objects
objects ¶
Wrapper for various Notion API objects like parents, mentions, emojis & users.
Similar to other records, these object provide access to the primitive data structure used in the Notion API.
For validation the Pydantic model fields specify if a field is optional or not. Some fields are always set, e.g. id, when retrieving an object but must not be set when sending the object to the Notion API in order to create the object. To model this behavior, the default sentinel value Unset is used for those objects, e.g.
class SelectOption(GenericObject)
id: str | UnsetType = Unset
GO_co = TypeVar('GO_co', bound=GenericObject, default=GenericObject, covariant=True) module-attribute ¶
MAX_TEXT_OBJECT_SIZE = 2000 module-attribute ¶
The max text size according to the Notion API is 2000 characters.
T = TypeVar('T', default=Any) module-attribute ¶
Annotations ¶
Style information for RichTextObject's.
bold: bool = False class-attribute instance-attribute ¶
code: bool = False class-attribute instance-attribute ¶
color: Color | BGColor | UnsetType = Unset class-attribute instance-attribute ¶
italic: bool = False class-attribute instance-attribute ¶
strikethrough: bool = False class-attribute instance-attribute ¶
underline: bool = False class-attribute instance-attribute ¶
BlockRef ¶
Bot ¶
Represents a Bot in Notion.
bot: BotTypeData = Field(default_factory=BotTypeData) class-attribute instance-attribute ¶
BotTypeData ¶
Comment ¶
CommentRef ¶
CustomEmojiObject ¶
A Notion custom emoji object.
Within text a custom emoji is represented as a mention. For this reason there is no MentionCustomEmoji class, but the CustomEmojiObject itself can be used to build a mention object.
CustomEmojiObjectTypeData ¶
DatabaseRef ¶
DateRange ¶
A Notion date range, with an optional end date.
end: dt.date | dt.datetime | None = None class-attribute instance-attribute ¶
start: dt.date | dt.datetime instance-attribute ¶
time_zone: str | None = None class-attribute instance-attribute ¶
__str__() -> str ¶
build(dt_spec: str | DateTimeOrRange) -> DateRange classmethod ¶
Compose a DateRange object from the given properties.
build_mention(style: Annotations | None = None) -> MentionObject ¶
to_pendulum() -> DateTimeOrRange ¶
Convert the DateRange to a pendulum object.
EmojiObject ¶
EquationObject ¶
Notion equation element.
equation: TypeData instance-attribute ¶
build(expression: str, *, href: str | None = None, style: Annotations | None = None) -> EquationObject classmethod ¶
Compose a TextObject from the given properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression | str | expression | required |
href | str | None | optional link for this object | None |
style | Annotations | None | optional annotations for styling this text | None |
ExternalFile ¶
FileImportError ¶
FileImportSuccess ¶
FileImportTypeData ¶
Type data for FileImportSuccess and FileImportError.
For ease of use, the parameters of success and error are combined into a single class.
code: str | None = None class-attribute instance-attribute ¶
message: str | None = None class-attribute instance-attribute ¶
parameter: str | None = None class-attribute instance-attribute ¶
status_code: int | None = None class-attribute instance-attribute ¶
type: str | None = None class-attribute instance-attribute ¶
FileObject ¶
A Notion file object.
Depending on the context, a FileObject may require a name (such as in the Files property) or may have a caption, for instance when used within a File block, which makes the object hierarchy complex. Thus, we simply allow name and caption to be optional. It is the responsibility of the caller to set name if required by the API.
FileUpload ¶
A Notion file upload object.
This object is used to handle the process of uploading a file to Notion.
archived: bool instance-attribute ¶
complete_url: str | None = None class-attribute instance-attribute ¶
content_length: int | None = None class-attribute instance-attribute ¶
content_type: str | None = None class-attribute instance-attribute ¶
created_by: User instance-attribute ¶
created_time: dt.datetime instance-attribute ¶
expiry_time: dt.datetime | None = None class-attribute instance-attribute ¶
file_import_result: FileImportSuccess | FileImportError | None = None class-attribute instance-attribute ¶
filename: str | None = None class-attribute instance-attribute ¶
id: UUID instance-attribute ¶
last_edited_time: dt.datetime instance-attribute ¶
number_of_parts: NumberOfParts | None = None class-attribute instance-attribute ¶
status: FileUploadStatus instance-attribute ¶
upload_url: str | None = None class-attribute instance-attribute ¶
HostedFile ¶
HostedTypedata ¶
LinkObject ¶
MentionBase ¶
Base class for typed Mention objects.
Note that this class is different to MentionMixin, which is used to provide a build_mention method for objects that can be mentioned in Notion. Here, we have a class method to build a mention object from the target object.
build_mention_from(*args: Any, **kwargs: Any) -> MentionObject abstractmethod classmethod ¶
Build a mention object for this type of mention from the actual target object.
MentionDatabase ¶
MentionDate ¶
MentionLink ¶
MentionLinkPreview ¶
Nested url data for Mention properties.
Warning
Link previews cannot be created via the API.
MentionLinkTypeData ¶
MentionMixin ¶
Mixin for objects that can be mentioned in Notion.
This mixin adds a build_mention property to the object, which can be used to reference the object in a mention.
build_mention(style: Annotations | None = None) -> MentionObject abstractmethod ¶
Return a mention object for this object.
MentionPage ¶
MentionTemplate ¶
Nested template data for Mention properties.
template_mention: SerializeAsAny[MentionTemplateData] instance-attribute ¶
MentionTemplateData ¶
Nested template data for Mention properties.
MentionTemplateDate ¶
Nested date template data for Mention properties.
template_mention_date: str instance-attribute ¶
MentionTemplateUser ¶
Nested user template data for Mention properties.
template_mention_user: str instance-attribute ¶
MentionUser ¶
ObjectRef ¶
PageRef ¶
ParentRef ¶
Reference another block as a parent.
Notion API: Parent Object
This class is simply a placeholder for the typed concrete *Ref classes.
Callers should always instantiate the intended concrete versions.
Person ¶
Represents a Person in Notion.
person: PersonTypeData = Field(default_factory=PersonTypeData) class-attribute instance-attribute ¶
PersonTypeData ¶
Type data for a Person.
email: str | None = None class-attribute instance-attribute ¶
RichTextBaseObject ¶
SelectGroup ¶
Group of options for status objects.
color: Color | UnsetType = Unset class-attribute instance-attribute ¶
id: str | UnsetType = Unset class-attribute instance-attribute ¶
name: str instance-attribute ¶
option_ids: list[str] = Field(default_factory=list) class-attribute instance-attribute ¶
__eq__(other: object) -> bool ¶
__hash__() -> int ¶
SelectOption ¶
Options for select & multi-select objects.
Specifying no color will result in the default color being used, i.e. Color.DEFAULT, which is a light grey. Note that colors can't be changed after they are set.
color: Color | UnsetType = Unset class-attribute instance-attribute ¶
description: list[RichTextBaseObject] | None = None class-attribute instance-attribute ¶
id: str | UnsetType = Unset class-attribute instance-attribute ¶
name: str instance-attribute ¶
__eq__(other: object) -> bool ¶
Compare SelectOption objects by all attributes except id.
__hash__() -> int ¶
Return a hash of the SelectOption based on name, color, and description.
build(name: str, color: Color = Color.DEFAULT) -> SelectOption classmethod ¶
Create a SelectOption object from the given name and color.
TextObject ¶
Notion text element.
text: TypeData instance-attribute ¶
TypeData ¶
build(text: str, *, href: str | None = None, style: Annotations | None = None) -> TextObject classmethod ¶
Compose a TextObject from the given properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | the plain text of this object | required |
href | str | None | optional link for this object | None |
style | Annotations | None | optional annotations for styling this text | None |
UnknownUser ¶
Represents an unknown user in Notion.
This is a unofficial placeholder for a user that is not recognized by the API.
UnknownUserTypeData ¶
Type data for an UnknownUser.
UploadedFile ¶
User ¶
UserRef ¶
WorkSpaceLimits ¶
Limits for a Notion workspace.
max_file_upload_size_in_bytes: int | None = None class-attribute instance-attribute ¶
get_uuid(obj: str | UUID | ParentRef | NotionObject | BlockRef) -> UUID ¶
Retrieves a UUID from an object reference.
Only meant for internal use.
rich_text_to_str(rich_texts: list[RichTextBaseObject]) -> str ¶
Convert a list of rich texts to plain text.