Skip to content

Core

core

Base classes for working with the Notion API.

logger = logging.getLogger(__name__) module-attribute

GenericObject

The base for all API objects.

As a general convention, data fields in lower case are defined by the Notion API. Properties in Title Case are provided for convenience.

model_config = ConfigDict(extra='forbid') class-attribute instance-attribute

build(*args, **kwargs) classmethod

Use the standard constructur to build the instance. Will be overridden for more complex types.

serialize_for_api()

Serialize the object for sending it to the Notion API.

update(**data)

Update the internal attributes with new data.

NotionObject

A top-level Notion API resource.

id: UUID | str = None class-attribute instance-attribute

object: str instance-attribute

request_id: UUID = None class-attribute instance-attribute

__init_subclass__(*, object=None, **kwargs)

__pydantic_init_subclass__(*, object=None, **kwargs) classmethod

Update GenericObject defaults for the named object.

Needed since model_fields are not available during init_subclass See: pydantic/pydantic#5369

TypedObject

A type-referenced object.

Many objects in the Notion API follow a standard pattern with a 'type' property followed by additional data. These objects must specify a type attribute to ensure that the correct object is created.

For example, this contains a nested 'detail' object:

data = {
    type: "detail",
    ...
    detail: {
        ...
    }
}

Calling the object provides direct access to the data stored in {type}.

type: str instance-attribute

value: Any property

Return the nested object.

__init_subclass__(*, type: str | None = None, polymorphic_base: bool = False, **kwargs)

__pydantic_init_subclass__(*, type: str | None = None, **kwargs) classmethod

Register the subtypes of the TypedObject subclass.

Needed since model_fields are not available during init_subclass. See: pydantic/pydantic#5369