Schema API Reference¶
The schema module defines the core data structures used throughout BlockNote-py.
Classes¶
Bases: BaseModel
Represents a Blocknote block with content and children.
A Block is the fundamental unit of content in Blocknote. Blocks can contain inline content and can have child blocks, allowing for nested structures like lists and complex documents.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the block |
type |
BlockType
|
The type of block (paragraph, heading, list items, etc.) |
props |
Dict[str, Any]
|
Block-specific properties including default styling |
content |
Union[str, List[InlineContent]]
|
The content of the block (text or list of InlineContent) |
children |
List[Block]
|
List of child blocks |
Source code in .venv/lib/python3.11/site-packages/blocknote/schema/types.py
validate_content(v, values)
¶
Validate that content format matches the block type.
Source code in .venv/lib/python3.11/site-packages/blocknote/schema/types.py
Bases: BaseModel
Represents inline content within a block.
Inline content is the text and styling information that makes up the content of a block. Currently only supports text content with optional styling.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
InlineContentType
|
The type of inline content (currently only "text") |
text |
str
|
The actual text content |
styles |
Dict[str, Any]
|
Dictionary of styling properties (e.g., {"bold": True}) |
Source code in .venv/lib/python3.11/site-packages/blocknote/schema/types.py
Enums¶
Bases: str, Enum
Enumeration of supported block types in Blocknote.
Source code in .venv/lib/python3.11/site-packages/blocknote/schema/types.py
Usage Examples¶
Creating Blocks¶
from blocknote.schema import Block, InlineContent, BlockType, InlineContentType
# Simple paragraph
paragraph = Block(
id="para-1",
type=BlockType.PARAGRAPH,
content=[
InlineContent(
type=InlineContentType.TEXT,
text="Hello, World!",
styles={}
)
]
)
# Heading with styling
heading = Block(
id="heading-1",
type=BlockType.HEADING,
props={"level": 1},
content=[
InlineContent(
type=InlineContentType.TEXT,
text="Document Title",
styles={"bold": True}
)
]
)
# List with children
list_item = Block(
id="list-1",
type=BlockType.BULLET_LIST_ITEM,
content=[
InlineContent(
type=InlineContentType.TEXT,
text="Parent item"
)
],
children=[
Block(
id="list-1-1",
type=BlockType.PARAGRAPH,
content=[
InlineContent(
type=InlineContentType.TEXT,
text="Child item"
)
]
)
]
)
Working with Styles¶
# Text with multiple styles
styled_content = InlineContent(
type=InlineContentType.TEXT,
text="Styled text",
styles={
"bold": True,
"italic": True,
"textColor": "#ff0000",
"backgroundColor": "#ffff00"
}
)
# Block with styled content
styled_block = Block(
id="styled-1",
type=BlockType.PARAGRAPH,
content=[styled_content]
)
Validation¶
All schema classes use Pydantic for validation:
from pydantic import ValidationError
try:
# This will raise a validation error
invalid_block = Block(
id="invalid",
type="invalid_type", # Not a valid BlockType
content=[]
)
except ValidationError as e:
print(f"Validation error: {e}")
Type Definitions¶
Block Properties¶
Different block types support different properties:
| Block Type | Supported Props | Example |
|---|---|---|
heading |
level (1-6) |
{"level": 2} |
checkListItem |
checked (bool) |
{"checked": True} |
paragraph |
textAlignment |
{"textAlignment": "center"} |
Style Properties¶
Inline content supports various styling options:
| Style Property | Type | Description | Example |
|---|---|---|---|
bold |
bool |
Bold text | {"bold": True} |
italic |
bool |
Italic text | {"italic": True} |
underline |
bool |
Underlined text | {"underline": True} |
strike |
bool |
Strikethrough text | {"strike": True} |
code |
bool |
Inline code formatting | {"code": True} |
textColor |
str |
Text color (CSS color) | {"textColor": "#ff0000"} |
backgroundColor |
str |
Background color | {"backgroundColor": "#ffff00"} |