notion-database 1.4.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- notion_database-2.0.0/PKG-INFO +468 -0
- notion_database-2.0.0/README.md +445 -0
- notion_database-2.0.0/notion_database/__init__.py +73 -0
- notion_database-2.0.0/notion_database/api/blocks.py +160 -0
- notion_database-2.0.0/notion_database/api/comments.py +73 -0
- notion_database-2.0.0/notion_database/api/databases.py +246 -0
- notion_database-2.0.0/notion_database/api/pages.py +278 -0
- notion_database-2.0.0/notion_database/api/search.py +163 -0
- notion_database-2.0.0/notion_database/api/users.py +78 -0
- notion_database-2.0.0/notion_database/client.py +84 -0
- notion_database-2.0.0/notion_database/const/__init__.py +46 -0
- notion_database-2.0.0/notion_database/exceptions.py +51 -0
- notion_database-2.0.0/notion_database/http/client.py +109 -0
- notion_database-2.0.0/notion_database/models/__init__.py +20 -0
- notion_database-2.0.0/notion_database/models/blocks.py +582 -0
- notion_database-2.0.0/notion_database/models/filters.py +498 -0
- notion_database-2.0.0/notion_database/models/icons.py +70 -0
- notion_database-2.0.0/notion_database/models/properties.py +625 -0
- notion_database-2.0.0/notion_database/models/rich_text.py +160 -0
- notion_database-2.0.0/notion_database/models/sorts.py +75 -0
- notion_database-2.0.0/notion_database.egg-info/PKG-INFO +468 -0
- notion_database-2.0.0/notion_database.egg-info/SOURCES.txt +35 -0
- notion_database-2.0.0/notion_database.egg-info/requires.txt +1 -0
- {notion_database-1.4.0 → notion_database-2.0.0}/notion_database.egg-info/top_level.txt +0 -1
- notion_database-2.0.0/pyproject.toml +41 -0
- notion_database-2.0.0/tests/test_models_blocks.py +179 -0
- notion_database-2.0.0/tests/test_models_filters.py +242 -0
- notion_database-2.0.0/tests/test_models_icons.py +28 -0
- notion_database-2.0.0/tests/test_models_properties.py +215 -0
- notion_database-2.0.0/tests/test_models_rich_text.py +102 -0
- notion_database-2.0.0/tests/test_models_sorts.py +36 -0
- notion_database-1.4.0/PKG-INFO +0 -142
- notion_database-1.4.0/README.md +0 -108
- notion_database-1.4.0/notion_database/__init__.py +0 -4
- notion_database-1.4.0/notion_database/block.py +0 -43
- notion_database-1.4.0/notion_database/children.py +0 -520
- notion_database-1.4.0/notion_database/components/request.py +0 -58
- notion_database-1.4.0/notion_database/const/query.py +0 -38
- notion_database-1.4.0/notion_database/cover.py +0 -43
- notion_database-1.4.0/notion_database/database.py +0 -179
- notion_database-1.4.0/notion_database/icon.py +0 -61
- notion_database-1.4.0/notion_database/page.py +0 -143
- notion_database-1.4.0/notion_database/properties.py +0 -270
- notion_database-1.4.0/notion_database/search.py +0 -78
- notion_database-1.4.0/notion_database/utils/__init__.py +0 -0
- notion_database-1.4.0/notion_database/utils/deprecate.py +0 -21
- notion_database-1.4.0/notion_database.egg-info/PKG-INFO +0 -142
- notion_database-1.4.0/notion_database.egg-info/SOURCES.txt +0 -30
- notion_database-1.4.0/notion_database.egg-info/requires.txt +0 -2
- notion_database-1.4.0/setup.py +0 -35
- notion_database-1.4.0/tests/__init__.py +0 -1
- notion_database-1.4.0/tests/test_children.py +0 -286
- notion_database-1.4.0/tests/test_cover.py +0 -22
- notion_database-1.4.0/tests/test_icon.py +0 -33
- notion_database-1.4.0/tests/test_page.py +0 -74
- notion_database-1.4.0/tests/test_properties.py +0 -276
- {notion_database-1.4.0 → notion_database-2.0.0}/LICENSE +0 -0
- {notion_database-1.4.0/notion_database/components → notion_database-2.0.0/notion_database/api}/__init__.py +0 -0
- {notion_database-1.4.0 → notion_database-2.0.0}/notion_database/const/color.py +0 -0
- {notion_database-1.4.0/notion_database/const → notion_database-2.0.0/notion_database/http}/__init__.py +0 -0
- {notion_database-1.4.0 → notion_database-2.0.0}/notion_database.egg-info/dependency_links.txt +0 -0
- {notion_database-1.4.0 → notion_database-2.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: notion-database
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Python client for the Notion API
|
|
5
|
+
Author-email: minwook-shin <minwook0106@gmail.com>
|
|
6
|
+
License: LGPLv3
|
|
7
|
+
Project-URL: Homepage, https://github.com/minwook-shin/notion-database
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/minwook-shin/notion-database/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Development Status :: 4 - Beta
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: requests<3.0,>=2.33.1
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
[](https://github.com/minwook-shin/notion-database/actions/workflows/python-publish.yml)
|
|
25
|
+
|
|
26
|
+
> [!IMPORTANT]
|
|
27
|
+
> **Upgrading from v1.4?**
|
|
28
|
+
> Version 2.0 is a full redesign with a new API — `NotionClient` replaces the old `Page`, `Database`, and `Search` classes.
|
|
29
|
+
> v1.4.x will continue to receive security fixes only. See the [migration table](#install) and [CHANGELOG](CHANGELOG.md) for details.
|
|
30
|
+
|
|
31
|
+
# notion-database
|
|
32
|
+
|
|
33
|
+
> Python client for the Notion API — easy to use, 1-to-1 API mapping, AI/MCP friendly
|
|
34
|
+
|
|
35
|
+
**Notion API version supported: `2026-03-11`**
|
|
36
|
+
|
|
37
|
+
## What's new in 2.0
|
|
38
|
+
|
|
39
|
+
| Feature | Description |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `client.pages.retrieve_markdown()` | Retrieve a page as enhanced Markdown (`GET /pages/{id}/markdown`) |
|
|
42
|
+
| `client.pages.update_markdown()` | Replace page content with Markdown (`PATCH /pages/{id}/markdown`) |
|
|
43
|
+
| `client.pages.append_markdown()` | Append Markdown to the bottom of a page (`PATCH /pages/{id}/markdown`) |
|
|
44
|
+
| `client.pages.create(timezone=...)` | IANA timezone for template variables (`@now`, `@today`) |
|
|
45
|
+
| `client.blocks.append_children(position=...)` | Insert blocks at `start`, `end`, or `after_block` |
|
|
46
|
+
| `client.databases.query(in_trash=...)` | Filter trashed / non-trashed rows |
|
|
47
|
+
| `client.databases.update(is_inline=..., in_trash=..., is_locked=...)` | Toggle inline layout, trash, and lock state |
|
|
48
|
+
| `client.databases.create(initial_data_source=...)` | Pre-populate a database from a data source on creation |
|
|
49
|
+
| `PropertySchema.button()` | Automation button column |
|
|
50
|
+
| `PropertySchema.location()` | Geographic location column |
|
|
51
|
+
| `PropertySchema.last_visited_time()` | Last visited time column (read-only) |
|
|
52
|
+
| `PropertySchema.rollup(relation_property_id=..., rollup_property_id=...)` | ID-based rollup lookup params |
|
|
53
|
+
| `PropertySchema.verification()` | Wiki page verification column |
|
|
54
|
+
| `PropertyValue.verification()` | Set wiki page verification state |
|
|
55
|
+
| `BlockContent.tab()` / `tab_group()` | Tab layout blocks |
|
|
56
|
+
| `Filter.created_by()` / `last_edited_by()` | Filter by creator or last editor |
|
|
57
|
+
| `Filter.formula(name, value_type)` | Filter on formula property results |
|
|
58
|
+
| `Filter.rollup(name, aggregate, value_type)` | Filter on rollup aggregates |
|
|
59
|
+
| `Filter.verification()` | Filter on wiki verification state |
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install notion-database==2.0.0
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from notion_database import (
|
|
71
|
+
NotionClient,
|
|
72
|
+
PropertyValue,
|
|
73
|
+
PropertySchema,
|
|
74
|
+
BlockContent,
|
|
75
|
+
RichText,
|
|
76
|
+
Filter,
|
|
77
|
+
Sort,
|
|
78
|
+
Icon,
|
|
79
|
+
Cover,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
client = NotionClient("secret_xxx")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Databases
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# Retrieve
|
|
89
|
+
db = client.databases.retrieve("database-id")
|
|
90
|
+
|
|
91
|
+
# Create
|
|
92
|
+
db = client.databases.create(
|
|
93
|
+
parent={"type": "page_id", "page_id": "page-id"},
|
|
94
|
+
title=[RichText.text("My Database")],
|
|
95
|
+
properties={
|
|
96
|
+
"Name": PropertySchema.title(),
|
|
97
|
+
"Status": PropertySchema.select([
|
|
98
|
+
{"name": "Active", "color": "green"},
|
|
99
|
+
{"name": "Done", "color": "gray"},
|
|
100
|
+
]),
|
|
101
|
+
"Score": PropertySchema.number("number"),
|
|
102
|
+
"Due": PropertySchema.date(),
|
|
103
|
+
},
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Query with filter and sort
|
|
107
|
+
results = client.databases.query(
|
|
108
|
+
"database-id",
|
|
109
|
+
filter=Filter.select("Status").equals("Active"),
|
|
110
|
+
sorts=[Sort.descending("Score")],
|
|
111
|
+
)
|
|
112
|
+
pages = results["results"]
|
|
113
|
+
|
|
114
|
+
# Compound filter
|
|
115
|
+
results = client.databases.query(
|
|
116
|
+
"database-id",
|
|
117
|
+
filter=Filter.and_([
|
|
118
|
+
Filter.select("Status").equals("Active"),
|
|
119
|
+
Filter.number("Score").greater_than(80),
|
|
120
|
+
]),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Auto-paginate (returns all pages at once)
|
|
124
|
+
all_pages = client.databases.query_all("database-id")
|
|
125
|
+
|
|
126
|
+
# Update schema — rename, lock, and set inline layout
|
|
127
|
+
client.databases.update(
|
|
128
|
+
"database-id",
|
|
129
|
+
title=[RichText.text("Renamed DB")],
|
|
130
|
+
is_inline=False, # full-page, not inline
|
|
131
|
+
is_locked=True, # prevent edits without unlocking
|
|
132
|
+
)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Pages
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# Create
|
|
139
|
+
page = client.pages.create(
|
|
140
|
+
parent={"database_id": "database-id"},
|
|
141
|
+
properties={
|
|
142
|
+
"Name": PropertyValue.title("Hello, Notion 2.0!"),
|
|
143
|
+
"Status": PropertyValue.select("Active"),
|
|
144
|
+
"Score": PropertyValue.number(95),
|
|
145
|
+
"Due": PropertyValue.date("2024-12-31"),
|
|
146
|
+
"Done": PropertyValue.checkbox(False),
|
|
147
|
+
},
|
|
148
|
+
icon=Icon.emoji("🚀"),
|
|
149
|
+
cover=Cover.external("https://example.com/cover.jpg"),
|
|
150
|
+
children=[
|
|
151
|
+
BlockContent.heading_1("Introduction"),
|
|
152
|
+
BlockContent.paragraph("This page was created via notion-database 2.0."),
|
|
153
|
+
],
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Retrieve
|
|
157
|
+
page = client.pages.retrieve("page-id")
|
|
158
|
+
|
|
159
|
+
# Update properties
|
|
160
|
+
client.pages.update(
|
|
161
|
+
"page-id",
|
|
162
|
+
properties={
|
|
163
|
+
"Status": PropertyValue.select("Done"),
|
|
164
|
+
"Done": PropertyValue.checkbox(True),
|
|
165
|
+
},
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# Archive / restore
|
|
169
|
+
client.pages.archive("page-id")
|
|
170
|
+
client.pages.archive("page-id", archived=False)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Blocks
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
# Append content to a page (inserted at end by default)
|
|
177
|
+
client.blocks.append_children(
|
|
178
|
+
"page-id",
|
|
179
|
+
children=[
|
|
180
|
+
BlockContent.heading_2("Section"),
|
|
181
|
+
BlockContent.paragraph([
|
|
182
|
+
RichText.text("Normal text, "),
|
|
183
|
+
RichText.text("bold", bold=True),
|
|
184
|
+
RichText.text(", and "),
|
|
185
|
+
RichText.text("italic", italic=True),
|
|
186
|
+
]),
|
|
187
|
+
BlockContent.bulleted_list_item("First item"),
|
|
188
|
+
BlockContent.bulleted_list_item("Second item"),
|
|
189
|
+
BlockContent.to_do("Finish docs", checked=False),
|
|
190
|
+
BlockContent.code("print('hello')", language="python"),
|
|
191
|
+
BlockContent.divider(),
|
|
192
|
+
BlockContent.image("https://example.com/image.png", caption="Fig 1"),
|
|
193
|
+
BlockContent.column_list([
|
|
194
|
+
[BlockContent.paragraph("Left column")],
|
|
195
|
+
[BlockContent.paragraph("Right column")],
|
|
196
|
+
]),
|
|
197
|
+
# Tab layout (Notion-Version: 2026-03-11)
|
|
198
|
+
BlockContent.tab_group([
|
|
199
|
+
BlockContent.tab("Overview", [BlockContent.paragraph("Overview content")]),
|
|
200
|
+
BlockContent.tab("Details", [BlockContent.paragraph("Details content")]),
|
|
201
|
+
]),
|
|
202
|
+
],
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
# Insert at a specific position (Notion-Version: 2026-03-11)
|
|
206
|
+
client.blocks.append_children("page-id", children=[
|
|
207
|
+
BlockContent.paragraph("Prepended to top"),
|
|
208
|
+
], position={"type": "start"})
|
|
209
|
+
|
|
210
|
+
client.blocks.append_children("page-id", children=[
|
|
211
|
+
BlockContent.paragraph("After a specific block"),
|
|
212
|
+
], position={"type": "after_block", "after_block": {"id": "block-id"}})
|
|
213
|
+
|
|
214
|
+
# Retrieve children (single page)
|
|
215
|
+
response = client.blocks.retrieve_children("page-id")
|
|
216
|
+
blocks = response["results"]
|
|
217
|
+
|
|
218
|
+
# Auto-paginate all children
|
|
219
|
+
all_blocks = client.blocks.retrieve_all_children("page-id")
|
|
220
|
+
|
|
221
|
+
# Delete a block
|
|
222
|
+
client.blocks.delete("block-id")
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Search
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
# Search all
|
|
229
|
+
results = client.search.search("Project")
|
|
230
|
+
|
|
231
|
+
# Filter by type
|
|
232
|
+
db_results = client.search.search_databases("Project")
|
|
233
|
+
page_results = client.search.search_pages("Meeting notes")
|
|
234
|
+
|
|
235
|
+
# Auto-paginate all results
|
|
236
|
+
all_results = client.search.search_all("Q1")
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Users
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
# Current bot
|
|
243
|
+
me = client.users.me()
|
|
244
|
+
|
|
245
|
+
# List all workspace users
|
|
246
|
+
all_users = client.users.list_all()
|
|
247
|
+
|
|
248
|
+
# Retrieve by ID
|
|
249
|
+
user = client.users.retrieve("user-id")
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Comments
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
# Retrieve comments on a page
|
|
256
|
+
comments = client.comments.retrieve("page-id")
|
|
257
|
+
|
|
258
|
+
# Post a comment
|
|
259
|
+
client.comments.create(
|
|
260
|
+
parent={"page_id": "page-id"},
|
|
261
|
+
rich_text=[RichText.text("Great work!")],
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Filters reference
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
# Text / title
|
|
269
|
+
Filter.text("Name").equals("Alice")
|
|
270
|
+
Filter.text("Name").contains("Al")
|
|
271
|
+
Filter.text("Name").starts_with("A")
|
|
272
|
+
Filter.text("Name").is_empty()
|
|
273
|
+
|
|
274
|
+
# Number
|
|
275
|
+
Filter.number("Score").greater_than(80)
|
|
276
|
+
Filter.number("Score").less_than_or_equal_to(100)
|
|
277
|
+
|
|
278
|
+
# Checkbox
|
|
279
|
+
Filter.checkbox("Done").equals(True)
|
|
280
|
+
|
|
281
|
+
# Select / status
|
|
282
|
+
Filter.select("Status").equals("Active")
|
|
283
|
+
Filter.status("Status").does_not_equal("Archived")
|
|
284
|
+
|
|
285
|
+
# Multi-select
|
|
286
|
+
Filter.multi_select("Tags").contains("python")
|
|
287
|
+
|
|
288
|
+
# Date
|
|
289
|
+
Filter.date("Due").before("2025-01-01")
|
|
290
|
+
Filter.date("Due").past_week()
|
|
291
|
+
Filter.date("Due").next_month()
|
|
292
|
+
|
|
293
|
+
# People-type columns
|
|
294
|
+
Filter.people("Assignee").contains("user-id")
|
|
295
|
+
Filter.created_by("Created By").contains("user-id")
|
|
296
|
+
Filter.last_edited_by("Last Edited By").does_not_contain("user-id")
|
|
297
|
+
|
|
298
|
+
# Timestamp columns
|
|
299
|
+
Filter.created_time().after("2024-01-01")
|
|
300
|
+
Filter.last_edited_time().past_week()
|
|
301
|
+
|
|
302
|
+
# Formula (value_type: "string" | "number" | "checkbox" | "date")
|
|
303
|
+
Filter.formula("Computed", "string").equals("ok")
|
|
304
|
+
Filter.formula("Score", "number").greater_than(50)
|
|
305
|
+
|
|
306
|
+
# Rollup (aggregate: "any" | "every" | "none" | "number"; value_type: property type)
|
|
307
|
+
Filter.rollup("Tasks", "any", "number").greater_than(0)
|
|
308
|
+
Filter.rollup("Tags", "every", "rich_text").contains("urgent")
|
|
309
|
+
|
|
310
|
+
# Verification (wiki pages)
|
|
311
|
+
Filter.verification("Verified").equals("verified")
|
|
312
|
+
|
|
313
|
+
# Compound
|
|
314
|
+
Filter.and_([
|
|
315
|
+
Filter.select("Status").equals("Active"),
|
|
316
|
+
Filter.number("Score").greater_than(80),
|
|
317
|
+
])
|
|
318
|
+
Filter.or_([
|
|
319
|
+
Filter.text("Name").contains("Alice"),
|
|
320
|
+
Filter.text("Name").contains("Bob"),
|
|
321
|
+
])
|
|
322
|
+
|
|
323
|
+
# Nested compound
|
|
324
|
+
Filter.and_([
|
|
325
|
+
Filter.checkbox("Done").equals(False),
|
|
326
|
+
Filter.or_([
|
|
327
|
+
Filter.select("Priority").equals("High"),
|
|
328
|
+
Filter.date("Due").before("2025-01-01"),
|
|
329
|
+
]),
|
|
330
|
+
])
|
|
331
|
+
|
|
332
|
+
# Raw (escape hatch)
|
|
333
|
+
Filter.raw({"property": "Formula", "formula": {"string": {"equals": "ok"}}})
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Sorts reference
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
Sort.by_property("Name") # ascending by default
|
|
340
|
+
Sort.by_property("Score", "descending")
|
|
341
|
+
Sort.ascending("Name") # alias
|
|
342
|
+
Sort.descending("CreatedAt") # alias
|
|
343
|
+
Sort.by_timestamp("created_time", "descending")
|
|
344
|
+
Sort.by_timestamp("last_edited_time")
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## RichText reference
|
|
348
|
+
|
|
349
|
+
```python
|
|
350
|
+
RichText.text("plain")
|
|
351
|
+
RichText.text("bold", bold=True)
|
|
352
|
+
RichText.text("italic", italic=True)
|
|
353
|
+
RichText.text("underline", underline=True)
|
|
354
|
+
RichText.text("strike", strikethrough=True)
|
|
355
|
+
RichText.text("code", code=True)
|
|
356
|
+
RichText.text("colored", color="red")
|
|
357
|
+
RichText.text("link", link="https://example.com")
|
|
358
|
+
|
|
359
|
+
RichText.mention_page("page-id")
|
|
360
|
+
RichText.mention_database("db-id")
|
|
361
|
+
RichText.mention_user("user-id")
|
|
362
|
+
RichText.mention_date("2024-01-01", end="2024-01-31")
|
|
363
|
+
RichText.equation("E=mc^2")
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## PropertySchema reference
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
from notion_database import PropertySchema
|
|
370
|
+
|
|
371
|
+
{
|
|
372
|
+
# Text
|
|
373
|
+
"Name": PropertySchema.title(),
|
|
374
|
+
"Notes": PropertySchema.rich_text(),
|
|
375
|
+
"Website": PropertySchema.url(),
|
|
376
|
+
"Email": PropertySchema.email(),
|
|
377
|
+
"Phone": PropertySchema.phone_number(),
|
|
378
|
+
|
|
379
|
+
# Numeric
|
|
380
|
+
"Score": PropertySchema.number("number"),
|
|
381
|
+
"Price": PropertySchema.number("dollar"),
|
|
382
|
+
|
|
383
|
+
# Selection
|
|
384
|
+
"Category": PropertySchema.select([{"name": "A", "color": "green"}]),
|
|
385
|
+
"Tags": PropertySchema.multi_select(),
|
|
386
|
+
"Status": PropertySchema.status(),
|
|
387
|
+
|
|
388
|
+
# Date / time (read-only system columns)
|
|
389
|
+
"Due": PropertySchema.date(),
|
|
390
|
+
"Created": PropertySchema.created_time(),
|
|
391
|
+
"CreatedBy": PropertySchema.created_by(),
|
|
392
|
+
"LastEdited": PropertySchema.last_edited_time(),
|
|
393
|
+
"LastEditedBy": PropertySchema.last_edited_by(),
|
|
394
|
+
|
|
395
|
+
# Other
|
|
396
|
+
"Done": PropertySchema.checkbox(),
|
|
397
|
+
"Files": PropertySchema.files(),
|
|
398
|
+
"People": PropertySchema.people(),
|
|
399
|
+
|
|
400
|
+
# Special (2026-03-11)
|
|
401
|
+
"Action": PropertySchema.button(), # automation trigger
|
|
402
|
+
"Location": PropertySchema.location(), # geographic location
|
|
403
|
+
"LastVisited": PropertySchema.last_visited_time(), # read-only
|
|
404
|
+
|
|
405
|
+
# Computed
|
|
406
|
+
"Formula": PropertySchema.formula("prop('Score') * 2"),
|
|
407
|
+
"UniqueID": PropertySchema.unique_id(prefix="ITEM"),
|
|
408
|
+
"Related": PropertySchema.relation("other-database-id"),
|
|
409
|
+
"Rollup": PropertySchema.rollup("Related", "Count", "count"),
|
|
410
|
+
# ID-based rollup (stable against column renames)
|
|
411
|
+
"RollupByID": PropertySchema.rollup(
|
|
412
|
+
"Related", "Count", "sum",
|
|
413
|
+
relation_property_id="rel-id",
|
|
414
|
+
rollup_property_id="prop-id",
|
|
415
|
+
),
|
|
416
|
+
# Verification (wiki databases only)
|
|
417
|
+
"Verified": PropertySchema.verification(),
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Error handling
|
|
422
|
+
|
|
423
|
+
```python
|
|
424
|
+
from notion_database import (
|
|
425
|
+
NotionAPIError,
|
|
426
|
+
NotionNotFoundError,
|
|
427
|
+
NotionRateLimitError,
|
|
428
|
+
NotionUnauthorizedError,
|
|
429
|
+
)
|
|
430
|
+
import time
|
|
431
|
+
|
|
432
|
+
try:
|
|
433
|
+
page = client.pages.retrieve("invalid-id")
|
|
434
|
+
except NotionNotFoundError:
|
|
435
|
+
print("Page not found")
|
|
436
|
+
except NotionRateLimitError:
|
|
437
|
+
time.sleep(1)
|
|
438
|
+
page = client.pages.retrieve("invalid-id")
|
|
439
|
+
except NotionUnauthorizedError:
|
|
440
|
+
print("Check your integration token")
|
|
441
|
+
except NotionAPIError as e:
|
|
442
|
+
print(f"[{e.status_code}] {e.code}: {e.message}")
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
## Color constants
|
|
446
|
+
|
|
447
|
+
```python
|
|
448
|
+
from notion_database.const import (
|
|
449
|
+
DEFAULT, GRAY, BROWN, ORANGE, YELLOW, GREEN, BLUE, PURPLE, PINK, RED,
|
|
450
|
+
GRAY_BACKGROUND, BROWN_BACKGROUND, ORANGE_BACKGROUND, YELLOW_BACKGROUND,
|
|
451
|
+
GREEN_BACKGROUND, BLUE_BACKGROUND, PURPLE_BACKGROUND, PINK_BACKGROUND,
|
|
452
|
+
RED_BACKGROUND,
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
BlockContent.paragraph("Highlighted", color=RED_BACKGROUND)
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
## MCP integration
|
|
459
|
+
|
|
460
|
+
`NotionClient` is designed to map directly to Notion API endpoints, making it
|
|
461
|
+
straightforward to expose as MCP tools. Each sub-client (`databases`,
|
|
462
|
+
`pages`, `blocks`, `search`, `users`, `comments`) corresponds to one section
|
|
463
|
+
of the Notion API docs. All parameters are typed and documented, so an AI can
|
|
464
|
+
introspect the signatures without additional context.
|
|
465
|
+
|
|
466
|
+
## License
|
|
467
|
+
|
|
468
|
+
LGPLv3
|