notionary 0.1.17__tar.gz → 0.1.18__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.
Files changed (62) hide show
  1. {notionary-0.1.17 → notionary-0.1.18}/PKG-INFO +89 -43
  2. notionary-0.1.18/README.md +230 -0
  3. {notionary-0.1.17 → notionary-0.1.18}/notionary/database/notion_database.py +20 -0
  4. {notionary-0.1.17 → notionary-0.1.18}/notionary.egg-info/PKG-INFO +89 -43
  5. {notionary-0.1.17 → notionary-0.1.18}/setup.py +1 -1
  6. notionary-0.1.17/README.md +0 -184
  7. {notionary-0.1.17 → notionary-0.1.18}/LICENSE +0 -0
  8. {notionary-0.1.17 → notionary-0.1.18}/notionary/__init__.py +0 -0
  9. {notionary-0.1.17 → notionary-0.1.18}/notionary/database/database_discovery.py +0 -0
  10. {notionary-0.1.17 → notionary-0.1.18}/notionary/database/database_info_service.py +0 -0
  11. {notionary-0.1.17 → notionary-0.1.18}/notionary/database/models/page_result.py +0 -0
  12. {notionary-0.1.17 → notionary-0.1.18}/notionary/database/notion_database_factory.py +0 -0
  13. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/audio_element.py +0 -0
  14. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/block_element_registry.py +0 -0
  15. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/block_element_registry_builder.py +0 -0
  16. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/bookmark_element.py +0 -0
  17. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/callout_element.py +0 -0
  18. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/code_block_element.py +0 -0
  19. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/column_element.py +0 -0
  20. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/divider_element.py +0 -0
  21. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/embed_element.py +0 -0
  22. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/heading_element.py +0 -0
  23. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/image_element.py +0 -0
  24. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/list_element.py +0 -0
  25. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/mention_element.py +0 -0
  26. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/notion_block_element.py +0 -0
  27. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/paragraph_element.py +0 -0
  28. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/qoute_element.py +0 -0
  29. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/table_element.py +0 -0
  30. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/text_inline_formatter.py +0 -0
  31. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/todo_lists.py +0 -0
  32. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/toggle_element.py +0 -0
  33. {notionary-0.1.17 → notionary-0.1.18}/notionary/elements/video_element.py +0 -0
  34. {notionary-0.1.17 → notionary-0.1.18}/notionary/exceptions/database_exceptions.py +0 -0
  35. {notionary-0.1.17 → notionary-0.1.18}/notionary/exceptions/page_creation_exception.py +0 -0
  36. {notionary-0.1.17 → notionary-0.1.18}/notionary/notion_client.py +0 -0
  37. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/content/notion_page_content_chunker.py +0 -0
  38. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/content/page_content_manager.py +0 -0
  39. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/markdown_to_notion_converter.py +0 -0
  40. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/metadata/metadata_editor.py +0 -0
  41. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/metadata/notion_icon_manager.py +0 -0
  42. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/metadata/notion_page_cover_manager.py +0 -0
  43. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/notion_page.py +0 -0
  44. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/notion_page_factory.py +0 -0
  45. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/notion_to_markdown_converter.py +0 -0
  46. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/properites/database_property_service.py +0 -0
  47. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/properites/page_property_manager.py +0 -0
  48. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/properites/property_formatter.py +0 -0
  49. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/properites/property_operation_result.py +0 -0
  50. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/properites/property_value_extractor.py +0 -0
  51. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/relations/notion_page_relation_manager.py +0 -0
  52. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/relations/notion_page_title_resolver.py +0 -0
  53. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/relations/page_database_relation.py +0 -0
  54. {notionary-0.1.17 → notionary-0.1.18}/notionary/page/relations/relation_operation_result.py +0 -0
  55. {notionary-0.1.17 → notionary-0.1.18}/notionary/util/logging_mixin.py +0 -0
  56. {notionary-0.1.17 → notionary-0.1.18}/notionary/util/page_id_utils.py +0 -0
  57. {notionary-0.1.17 → notionary-0.1.18}/notionary/util/singleton_decorator.py +0 -0
  58. {notionary-0.1.17 → notionary-0.1.18}/notionary.egg-info/SOURCES.txt +0 -0
  59. {notionary-0.1.17 → notionary-0.1.18}/notionary.egg-info/dependency_links.txt +0 -0
  60. {notionary-0.1.17 → notionary-0.1.18}/notionary.egg-info/requires.txt +0 -0
  61. {notionary-0.1.17 → notionary-0.1.18}/notionary.egg-info/top_level.txt +0 -0
  62. {notionary-0.1.17 → notionary-0.1.18}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notionary
3
- Version: 0.1.17
3
+ Version: 0.1.18
4
4
  Summary: A toolkit to convert between Markdown and Notion blocks
5
5
  Home-page: https://github.com/mathisarends/notionary
6
6
  Author: Mathis Arends
@@ -33,12 +33,14 @@ Dynamic: summary
33
33
  [![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/downloads/)
34
34
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
35
35
 
36
- **Notionary** is a powerful Python library for interacting with the Notion API, making it easy to create, update, and manage Notion pages and databases programmatically with a clean, intuitive interface.
36
+ **Notionary** is a powerful Python library for interacting with the Notion API, making it easy to create, update, and manage Notion pages and databases programmatically with a clean, intuitive interface. It's specifically designed to be the foundation for AI-driven Notion content generation.
37
37
 
38
38
  ## Features
39
39
 
40
- - **Rich Markdown Support**: Write Notion pages using intuitive Markdown syntax with custom extensions
40
+ - **Rich Markdown Support**: Create Notion pages using intuitive Markdown syntax with custom extensions
41
41
  - **Dynamic Database Operations**: Create, update, and query database entries with schema auto-detection
42
+ - **Extensible Block Registry**: Add, customize, or remove Notion block elements with a flexible registry pattern
43
+ - **LLM-Ready Prompts**: Generate system prompts explaining Markdown syntax for LLMs to create Notion content
42
44
  - **Async-First Design**: Built for modern Python with full async/await support
43
45
  - **Schema-Based Validation**: Automatic property validation based on database schemas
44
46
  - **Intelligent Content Conversion**: Bidirectional conversion between Markdown and Notion blocks
@@ -56,7 +58,7 @@ Notionary extends standard Markdown with special syntax to support Notion-specif
56
58
  ### Text Formatting
57
59
 
58
60
  - Standard Markdown: `**bold**`, `*italic*`, `~~strikethrough~~`, `` `code` ``
59
- - Highlights: `==highlighted text==`, `==red warning==`, `==blue==`
61
+ - Highlights: `==highlighted text==`, `==red:warning==`, `==blue:note==`
60
62
 
61
63
  ### Block Elements
62
64
 
@@ -111,50 +113,43 @@ Notionary makes it easy to work with Notion databases, automatically handling sc
111
113
 
112
114
  ```python
113
115
  import asyncio
114
- from notionary.core.database.notion_database_manager import NotionDatabaseManager
116
+ from notionary import NotionDatabaseFactory
115
117
 
116
118
  async def main():
117
- database_id = "1a6389d5-7bd3-8097-aa38-e93cb052615a"
118
- db = NotionDatabaseManager(database_id)
119
- await db.initialize()
119
+ # Find database by name with fuzzy matching
120
+ db_manager = await NotionDatabaseFactory.from_database_name("Projects")
120
121
 
122
+ # Create a new page with properties
121
123
  properties = {
122
124
  "Title": "Created via Notionary",
123
- "Description": "This entry was created using Notionary.",
124
125
  "Status": "In Progress",
125
126
  "Priority": "High"
126
127
  }
127
128
 
128
- result = await db.create_page(properties)
129
+ page = await db_manager.create_blank_page()
129
130
 
130
- if result["success"]:
131
- page_id = result["page_id"]
132
- await db.update_page(page_id, {"Status": "Completed"})
131
+ # Set page content with rich Markdown
132
+ await page.set_title("My New Project")
133
+ await page.set_page_icon(emoji="🚀")
133
134
 
134
- filter_conditions = {
135
- "property": "Status",
136
- "status": {"equals": "Completed"}
137
- }
135
+ markdown = """
136
+ # Project Overview
138
137
 
139
- pages = await db.get_pages(limit=10, filter_conditions=filter_conditions)
138
+ !> [💡] This page was created programmatically using Notionary.
140
139
 
141
- await db.close()
140
+ ## Tasks
141
+ - [ ] Define project scope
142
+ - [ ] Create timeline
143
+ - [ ] Assign resources
142
144
 
143
- if __name__ == "__main__":
144
- asyncio.run(main())
145
- ```
146
-
147
- ## Finding Databases by Name
148
-
149
- Use fuzzy matching to find databases:
145
+ +++ Implementation Details
146
+ This project will use our standard architecture with custom extensions.
147
+ """
150
148
 
151
- ```python
152
- from notionary.core.database.notion_database_manager_factory import NotionDatabaseFactory
149
+ await page.replace_content(markdown)
153
150
 
154
- async def main():
155
- db_manager = await NotionDatabaseFactory.from_database_name("Projects")
156
- print(f"Found database: {db_manager.title}")
157
- await db_manager.close()
151
+ if __name__ == "__main__":
152
+ asyncio.run(main())
158
153
  ```
159
154
 
160
155
  ## Page Content Management
@@ -162,11 +157,11 @@ async def main():
162
157
  Create rich Notion pages using enhanced Markdown:
163
158
 
164
159
  ```python
165
- from notionary.core.page.notion_page_manager import NotionPageManager
160
+ from notionary import NotionPage
166
161
 
167
162
  async def create_rich_page():
168
163
  url = "https://www.notion.so/Your-Page-1cd389d57bd381e58be9d35ce24adf3d"
169
- page_manager = NotionPageManager(url=url)
164
+ page_manager = NotionPage(url=url)
170
165
 
171
166
  await page_manager.set_title("Notionary Demo")
172
167
  await page_manager.set_page_icon(emoji="✨")
@@ -190,20 +185,71 @@ async def create_rich_page():
190
185
  await page_manager.replace_content(markdown)
191
186
  ```
192
187
 
193
- ## Perfect for AI Agents and Automation
188
+ ## Block Registry & Builder
194
189
 
195
- - **Dynamic Content Generation**: AI agents can generate content in Markdown and render it as Notion pages
196
- - **Schema-Aware Operations**: Automatically validate and format properties
197
- - **Simplified API**: Easier integration with AI workflows
190
+ Notionary uses a flexible registry pattern with a builder to customize which Notion elements are supported, allowing programmatic creation of complex UI layouts that were previously only possible through Notion's UI:
191
+
192
+ ```python
193
+ from notionary import NotionPage
194
+ from notionary.elements.block_element_registry_builder import BlockElementRegistryBuilder
195
+
196
+ # Create a registry with standard Notion elements
197
+ registry = BlockElementRegistryBuilder.create_standard_registry()
198
+
199
+ # Or build a custom registry with only the elements you need
200
+ custom_registry = (
201
+ BlockElementRegistryBuilder()
202
+ .with_headings()
203
+ .with_callouts()
204
+ .with_toggles()
205
+ .with_lists()
206
+ .with_tables()
207
+ .with_paragraphs()
208
+ .build()
209
+ )
210
+
211
+ # Apply this registry to a page to enable custom Markdown support
212
+ page = NotionPage(url="https://www.notion.so/your-page-url")
213
+ page.block_registry = custom_registry
214
+
215
+ # Now your page supports exactly the elements you've defined
216
+ await page.replace_content("# Custom heading with only selected elements")
217
+ ```
218
+
219
+ This registry approach gives you granular control over which Notion UI elements can be created through Markdown, making it possible to programmatically construct any page layout that would normally require manual UI interaction.
220
+
221
+ ## AI-Ready LLM Prompt Generation
222
+
223
+ Notionary can automatically generate comprehensive system prompts for LLMs to understand Notion's custom Markdown syntax:
224
+
225
+ ```python
226
+ from notionary.elements.block_element_registry_builder import BlockElementRegistryBuilder
227
+
228
+ registry = BlockElementRegistryBuilder.create_standard_registry()
229
+ llm_system_prompt = registry.generate_llm_prompt()
230
+
231
+ # Use this prompt with your LLM to generate Notion-compatible Markdown
232
+ print(llm_system_prompt)
233
+ ```
234
+
235
+ This makes Notionary the perfect foundation for AI-driven Notion content generation, enabling LLMs to create properly formatted Notion pages.
198
236
 
199
237
  ## Examples
200
238
 
201
- See the `examples` folder for:
239
+ See the [examples folder](examples/) for more comprehensive demonstrations:
240
+
241
+ - [Database discovery and querying](examples/database_discovery_example.py)
242
+ - [Rich page creation with Markdown](examples/page_example.py)
243
+ - [Database factory usage](examples/database_factory_example.py)
244
+ - [Page lookup and access](examples/page_factory_by_url_example.py)
245
+ - [Iterating through database entries](examples/iter_database_example.py)
246
+
247
+ ## Perfect for AI Agents and Automation
202
248
 
203
- - Database discovery and querying
204
- - Rich page creation with Markdown
205
- - Entry management
206
- - Metadata manipulation
249
+ - **LLM Integration**: Generate Notion-compatible content with LLMs using the system prompt generator
250
+ - **Dynamic Content Generation**: AI agents can generate content in Markdown and render it as Notion pages
251
+ - **Schema-Aware Operations**: Automatically validate and format properties
252
+ - **Simplified API**: Easier integration with AI workflows
207
253
 
208
254
  ## License
209
255
 
@@ -0,0 +1,230 @@
1
+ # Notionary 📝
2
+
3
+ [![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/downloads/)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
5
+
6
+ **Notionary** is a powerful Python library for interacting with the Notion API, making it easy to create, update, and manage Notion pages and databases programmatically with a clean, intuitive interface. It's specifically designed to be the foundation for AI-driven Notion content generation.
7
+
8
+ ## Features
9
+
10
+ - **Rich Markdown Support**: Create Notion pages using intuitive Markdown syntax with custom extensions
11
+ - **Dynamic Database Operations**: Create, update, and query database entries with schema auto-detection
12
+ - **Extensible Block Registry**: Add, customize, or remove Notion block elements with a flexible registry pattern
13
+ - **LLM-Ready Prompts**: Generate system prompts explaining Markdown syntax for LLMs to create Notion content
14
+ - **Async-First Design**: Built for modern Python with full async/await support
15
+ - **Schema-Based Validation**: Automatic property validation based on database schemas
16
+ - **Intelligent Content Conversion**: Bidirectional conversion between Markdown and Notion blocks
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install notionary
22
+ ```
23
+
24
+ ## Custom Markdown Syntax
25
+
26
+ Notionary extends standard Markdown with special syntax to support Notion-specific features:
27
+
28
+ ### Text Formatting
29
+
30
+ - Standard Markdown: `**bold**`, `*italic*`, `~~strikethrough~~`, `` `code` ``
31
+ - Highlights: `==highlighted text==`, `==red:warning==`, `==blue:note==`
32
+
33
+ ### Block Elements
34
+
35
+ #### Callouts
36
+
37
+ ```markdown
38
+ !> [💡] This is a default callout with the light bulb emoji
39
+ !> [🔔] This is a callout with a bell emoji
40
+ !> {blue_background} [💧] This is a blue callout with a water drop emoji
41
+ !> {yellow_background} [⚠️] Warning: This is an important note
42
+ ```
43
+
44
+ #### Toggles
45
+
46
+ ```markdown
47
+ +++ How to use NotionPageManager
48
+
49
+ 1. Initialize with NotionPageManager
50
+ 2. Update metadata with set_title(), set_page_icon(), etc.
51
+ 3. Add content with replace_content() or append_markdown()
52
+ ```
53
+
54
+ #### Bookmarks
55
+
56
+ ```markdown
57
+ [bookmark](https://notion.so "Notion Homepage" "Your connected workspace")
58
+ ```
59
+
60
+ #### Multi-Column Layouts
61
+
62
+ ```markdown
63
+ ::: columns
64
+ ::: column
65
+ Content for first column
66
+ :::
67
+ ::: column
68
+ Content for second column
69
+ :::
70
+ :::
71
+ ```
72
+
73
+ And more:
74
+
75
+ - Tables with standard Markdown syntax
76
+ - Code blocks with syntax highlighting
77
+ - To-do lists with `- [ ]` and `- [x]`
78
+ - Block quotes with `>`
79
+
80
+ ## Database Management
81
+
82
+ Notionary makes it easy to work with Notion databases, automatically handling schema detection and property conversion:
83
+
84
+ ```python
85
+ import asyncio
86
+ from notionary import NotionDatabaseFactory
87
+
88
+ async def main():
89
+ # Find database by name with fuzzy matching
90
+ db_manager = await NotionDatabaseFactory.from_database_name("Projects")
91
+
92
+ # Create a new page with properties
93
+ properties = {
94
+ "Title": "Created via Notionary",
95
+ "Status": "In Progress",
96
+ "Priority": "High"
97
+ }
98
+
99
+ page = await db_manager.create_blank_page()
100
+
101
+ # Set page content with rich Markdown
102
+ await page.set_title("My New Project")
103
+ await page.set_page_icon(emoji="🚀")
104
+
105
+ markdown = """
106
+ # Project Overview
107
+
108
+ !> [💡] This page was created programmatically using Notionary.
109
+
110
+ ## Tasks
111
+ - [ ] Define project scope
112
+ - [ ] Create timeline
113
+ - [ ] Assign resources
114
+
115
+ +++ Implementation Details
116
+ This project will use our standard architecture with custom extensions.
117
+ """
118
+
119
+ await page.replace_content(markdown)
120
+
121
+ if __name__ == "__main__":
122
+ asyncio.run(main())
123
+ ```
124
+
125
+ ## Page Content Management
126
+
127
+ Create rich Notion pages using enhanced Markdown:
128
+
129
+ ```python
130
+ from notionary import NotionPage
131
+
132
+ async def create_rich_page():
133
+ url = "https://www.notion.so/Your-Page-1cd389d57bd381e58be9d35ce24adf3d"
134
+ page_manager = NotionPage(url=url)
135
+
136
+ await page_manager.set_title("Notionary Demo")
137
+ await page_manager.set_page_icon(emoji="✨")
138
+ await page_manager.set_page_cover("https://images.unsplash.com/photo-1555066931-4365d14bab8c")
139
+
140
+ markdown = '''
141
+ # Notionary Rich Content Demo
142
+
143
+ !> [💡] This page was created with Notionary's custom Markdown syntax.
144
+
145
+ ## Features
146
+ - Easy-to-use Python API
147
+ - **Rich** Markdown support
148
+ - Async functionality
149
+
150
+ +++ Implementation Details
151
+ Notionary uses a custom converter to transform Markdown into Notion blocks.
152
+ This makes it easy to create rich content programmatically.
153
+ '''
154
+
155
+ await page_manager.replace_content(markdown)
156
+ ```
157
+
158
+ ## Block Registry & Builder
159
+
160
+ Notionary uses a flexible registry pattern with a builder to customize which Notion elements are supported, allowing programmatic creation of complex UI layouts that were previously only possible through Notion's UI:
161
+
162
+ ```python
163
+ from notionary import NotionPage
164
+ from notionary.elements.block_element_registry_builder import BlockElementRegistryBuilder
165
+
166
+ # Create a registry with standard Notion elements
167
+ registry = BlockElementRegistryBuilder.create_standard_registry()
168
+
169
+ # Or build a custom registry with only the elements you need
170
+ custom_registry = (
171
+ BlockElementRegistryBuilder()
172
+ .with_headings()
173
+ .with_callouts()
174
+ .with_toggles()
175
+ .with_lists()
176
+ .with_tables()
177
+ .with_paragraphs()
178
+ .build()
179
+ )
180
+
181
+ # Apply this registry to a page to enable custom Markdown support
182
+ page = NotionPage(url="https://www.notion.so/your-page-url")
183
+ page.block_registry = custom_registry
184
+
185
+ # Now your page supports exactly the elements you've defined
186
+ await page.replace_content("# Custom heading with only selected elements")
187
+ ```
188
+
189
+ This registry approach gives you granular control over which Notion UI elements can be created through Markdown, making it possible to programmatically construct any page layout that would normally require manual UI interaction.
190
+
191
+ ## AI-Ready LLM Prompt Generation
192
+
193
+ Notionary can automatically generate comprehensive system prompts for LLMs to understand Notion's custom Markdown syntax:
194
+
195
+ ```python
196
+ from notionary.elements.block_element_registry_builder import BlockElementRegistryBuilder
197
+
198
+ registry = BlockElementRegistryBuilder.create_standard_registry()
199
+ llm_system_prompt = registry.generate_llm_prompt()
200
+
201
+ # Use this prompt with your LLM to generate Notion-compatible Markdown
202
+ print(llm_system_prompt)
203
+ ```
204
+
205
+ This makes Notionary the perfect foundation for AI-driven Notion content generation, enabling LLMs to create properly formatted Notion pages.
206
+
207
+ ## Examples
208
+
209
+ See the [examples folder](examples/) for more comprehensive demonstrations:
210
+
211
+ - [Database discovery and querying](examples/database_discovery_example.py)
212
+ - [Rich page creation with Markdown](examples/page_example.py)
213
+ - [Database factory usage](examples/database_factory_example.py)
214
+ - [Page lookup and access](examples/page_factory_by_url_example.py)
215
+ - [Iterating through database entries](examples/iter_database_example.py)
216
+
217
+ ## Perfect for AI Agents and Automation
218
+
219
+ - **LLM Integration**: Generate Notion-compatible content with LLMs using the system prompt generator
220
+ - **Dynamic Content Generation**: AI agents can generate content in Markdown and render it as Notion pages
221
+ - **Schema-Aware Operations**: Automatically validate and format properties
222
+ - **Simplified API**: Easier integration with AI workflows
223
+
224
+ ## License
225
+
226
+ MIT
227
+
228
+ ## Contributing
229
+
230
+ Contributions welcome — feel free to submit a pull request!
@@ -217,6 +217,26 @@ class NotionDatabase(LoggingMixin):
217
217
  self.logger.error("Error in delete_page: %s", str(e))
218
218
  return {"success": False, "message": f"Error: {str(e)}"}
219
219
 
220
+ async def get_last_edited_time(self) -> Optional[str]:
221
+ """
222
+ Retrieve the last edited time of the database.
223
+
224
+ Returns:
225
+ ISO 8601 timestamp string of the last database edit, or None if request fails
226
+ """
227
+ try:
228
+ response = await self._client.get(f"databases/{self.database_id}")
229
+
230
+ if response and "last_edited_time" in response:
231
+ return response["last_edited_time"]
232
+
233
+ self.logger.warning("Could not retrieve last_edited_time for database %s", self.database_id)
234
+ return None
235
+
236
+ except Exception as e:
237
+ self.logger.error("Error fetching last_edited_time: %s", str(e))
238
+ return None
239
+
220
240
  async def close(self) -> None:
221
241
  """Close the client connection."""
222
242
  await self._client.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notionary
3
- Version: 0.1.17
3
+ Version: 0.1.18
4
4
  Summary: A toolkit to convert between Markdown and Notion blocks
5
5
  Home-page: https://github.com/mathisarends/notionary
6
6
  Author: Mathis Arends
@@ -33,12 +33,14 @@ Dynamic: summary
33
33
  [![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/downloads/)
34
34
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
35
35
 
36
- **Notionary** is a powerful Python library for interacting with the Notion API, making it easy to create, update, and manage Notion pages and databases programmatically with a clean, intuitive interface.
36
+ **Notionary** is a powerful Python library for interacting with the Notion API, making it easy to create, update, and manage Notion pages and databases programmatically with a clean, intuitive interface. It's specifically designed to be the foundation for AI-driven Notion content generation.
37
37
 
38
38
  ## Features
39
39
 
40
- - **Rich Markdown Support**: Write Notion pages using intuitive Markdown syntax with custom extensions
40
+ - **Rich Markdown Support**: Create Notion pages using intuitive Markdown syntax with custom extensions
41
41
  - **Dynamic Database Operations**: Create, update, and query database entries with schema auto-detection
42
+ - **Extensible Block Registry**: Add, customize, or remove Notion block elements with a flexible registry pattern
43
+ - **LLM-Ready Prompts**: Generate system prompts explaining Markdown syntax for LLMs to create Notion content
42
44
  - **Async-First Design**: Built for modern Python with full async/await support
43
45
  - **Schema-Based Validation**: Automatic property validation based on database schemas
44
46
  - **Intelligent Content Conversion**: Bidirectional conversion between Markdown and Notion blocks
@@ -56,7 +58,7 @@ Notionary extends standard Markdown with special syntax to support Notion-specif
56
58
  ### Text Formatting
57
59
 
58
60
  - Standard Markdown: `**bold**`, `*italic*`, `~~strikethrough~~`, `` `code` ``
59
- - Highlights: `==highlighted text==`, `==red warning==`, `==blue==`
61
+ - Highlights: `==highlighted text==`, `==red:warning==`, `==blue:note==`
60
62
 
61
63
  ### Block Elements
62
64
 
@@ -111,50 +113,43 @@ Notionary makes it easy to work with Notion databases, automatically handling sc
111
113
 
112
114
  ```python
113
115
  import asyncio
114
- from notionary.core.database.notion_database_manager import NotionDatabaseManager
116
+ from notionary import NotionDatabaseFactory
115
117
 
116
118
  async def main():
117
- database_id = "1a6389d5-7bd3-8097-aa38-e93cb052615a"
118
- db = NotionDatabaseManager(database_id)
119
- await db.initialize()
119
+ # Find database by name with fuzzy matching
120
+ db_manager = await NotionDatabaseFactory.from_database_name("Projects")
120
121
 
122
+ # Create a new page with properties
121
123
  properties = {
122
124
  "Title": "Created via Notionary",
123
- "Description": "This entry was created using Notionary.",
124
125
  "Status": "In Progress",
125
126
  "Priority": "High"
126
127
  }
127
128
 
128
- result = await db.create_page(properties)
129
+ page = await db_manager.create_blank_page()
129
130
 
130
- if result["success"]:
131
- page_id = result["page_id"]
132
- await db.update_page(page_id, {"Status": "Completed"})
131
+ # Set page content with rich Markdown
132
+ await page.set_title("My New Project")
133
+ await page.set_page_icon(emoji="🚀")
133
134
 
134
- filter_conditions = {
135
- "property": "Status",
136
- "status": {"equals": "Completed"}
137
- }
135
+ markdown = """
136
+ # Project Overview
138
137
 
139
- pages = await db.get_pages(limit=10, filter_conditions=filter_conditions)
138
+ !> [💡] This page was created programmatically using Notionary.
140
139
 
141
- await db.close()
140
+ ## Tasks
141
+ - [ ] Define project scope
142
+ - [ ] Create timeline
143
+ - [ ] Assign resources
142
144
 
143
- if __name__ == "__main__":
144
- asyncio.run(main())
145
- ```
146
-
147
- ## Finding Databases by Name
148
-
149
- Use fuzzy matching to find databases:
145
+ +++ Implementation Details
146
+ This project will use our standard architecture with custom extensions.
147
+ """
150
148
 
151
- ```python
152
- from notionary.core.database.notion_database_manager_factory import NotionDatabaseFactory
149
+ await page.replace_content(markdown)
153
150
 
154
- async def main():
155
- db_manager = await NotionDatabaseFactory.from_database_name("Projects")
156
- print(f"Found database: {db_manager.title}")
157
- await db_manager.close()
151
+ if __name__ == "__main__":
152
+ asyncio.run(main())
158
153
  ```
159
154
 
160
155
  ## Page Content Management
@@ -162,11 +157,11 @@ async def main():
162
157
  Create rich Notion pages using enhanced Markdown:
163
158
 
164
159
  ```python
165
- from notionary.core.page.notion_page_manager import NotionPageManager
160
+ from notionary import NotionPage
166
161
 
167
162
  async def create_rich_page():
168
163
  url = "https://www.notion.so/Your-Page-1cd389d57bd381e58be9d35ce24adf3d"
169
- page_manager = NotionPageManager(url=url)
164
+ page_manager = NotionPage(url=url)
170
165
 
171
166
  await page_manager.set_title("Notionary Demo")
172
167
  await page_manager.set_page_icon(emoji="✨")
@@ -190,20 +185,71 @@ async def create_rich_page():
190
185
  await page_manager.replace_content(markdown)
191
186
  ```
192
187
 
193
- ## Perfect for AI Agents and Automation
188
+ ## Block Registry & Builder
194
189
 
195
- - **Dynamic Content Generation**: AI agents can generate content in Markdown and render it as Notion pages
196
- - **Schema-Aware Operations**: Automatically validate and format properties
197
- - **Simplified API**: Easier integration with AI workflows
190
+ Notionary uses a flexible registry pattern with a builder to customize which Notion elements are supported, allowing programmatic creation of complex UI layouts that were previously only possible through Notion's UI:
191
+
192
+ ```python
193
+ from notionary import NotionPage
194
+ from notionary.elements.block_element_registry_builder import BlockElementRegistryBuilder
195
+
196
+ # Create a registry with standard Notion elements
197
+ registry = BlockElementRegistryBuilder.create_standard_registry()
198
+
199
+ # Or build a custom registry with only the elements you need
200
+ custom_registry = (
201
+ BlockElementRegistryBuilder()
202
+ .with_headings()
203
+ .with_callouts()
204
+ .with_toggles()
205
+ .with_lists()
206
+ .with_tables()
207
+ .with_paragraphs()
208
+ .build()
209
+ )
210
+
211
+ # Apply this registry to a page to enable custom Markdown support
212
+ page = NotionPage(url="https://www.notion.so/your-page-url")
213
+ page.block_registry = custom_registry
214
+
215
+ # Now your page supports exactly the elements you've defined
216
+ await page.replace_content("# Custom heading with only selected elements")
217
+ ```
218
+
219
+ This registry approach gives you granular control over which Notion UI elements can be created through Markdown, making it possible to programmatically construct any page layout that would normally require manual UI interaction.
220
+
221
+ ## AI-Ready LLM Prompt Generation
222
+
223
+ Notionary can automatically generate comprehensive system prompts for LLMs to understand Notion's custom Markdown syntax:
224
+
225
+ ```python
226
+ from notionary.elements.block_element_registry_builder import BlockElementRegistryBuilder
227
+
228
+ registry = BlockElementRegistryBuilder.create_standard_registry()
229
+ llm_system_prompt = registry.generate_llm_prompt()
230
+
231
+ # Use this prompt with your LLM to generate Notion-compatible Markdown
232
+ print(llm_system_prompt)
233
+ ```
234
+
235
+ This makes Notionary the perfect foundation for AI-driven Notion content generation, enabling LLMs to create properly formatted Notion pages.
198
236
 
199
237
  ## Examples
200
238
 
201
- See the `examples` folder for:
239
+ See the [examples folder](examples/) for more comprehensive demonstrations:
240
+
241
+ - [Database discovery and querying](examples/database_discovery_example.py)
242
+ - [Rich page creation with Markdown](examples/page_example.py)
243
+ - [Database factory usage](examples/database_factory_example.py)
244
+ - [Page lookup and access](examples/page_factory_by_url_example.py)
245
+ - [Iterating through database entries](examples/iter_database_example.py)
246
+
247
+ ## Perfect for AI Agents and Automation
202
248
 
203
- - Database discovery and querying
204
- - Rich page creation with Markdown
205
- - Entry management
206
- - Metadata manipulation
249
+ - **LLM Integration**: Generate Notion-compatible content with LLMs using the system prompt generator
250
+ - **Dynamic Content Generation**: AI agents can generate content in Markdown and render it as Notion pages
251
+ - **Schema-Aware Operations**: Automatically validate and format properties
252
+ - **Simplified API**: Easier integration with AI workflows
207
253
 
208
254
  ## License
209
255
 
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
2
2
 
3
3
  setup(
4
4
  name="notionary",
5
- version="0.1.17",
5
+ version="0.1.18",
6
6
  packages=find_namespace_packages(include=["notionary*"]),
7
7
  install_requires=[
8
8
  "notion-client>=2.0.0",
@@ -1,184 +0,0 @@
1
- # Notionary 📝
2
-
3
- [![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/downloads/)
4
- [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
5
-
6
- **Notionary** is a powerful Python library for interacting with the Notion API, making it easy to create, update, and manage Notion pages and databases programmatically with a clean, intuitive interface.
7
-
8
- ## Features
9
-
10
- - **Rich Markdown Support**: Write Notion pages using intuitive Markdown syntax with custom extensions
11
- - **Dynamic Database Operations**: Create, update, and query database entries with schema auto-detection
12
- - **Async-First Design**: Built for modern Python with full async/await support
13
- - **Schema-Based Validation**: Automatic property validation based on database schemas
14
- - **Intelligent Content Conversion**: Bidirectional conversion between Markdown and Notion blocks
15
-
16
- ## Installation
17
-
18
- ```bash
19
- pip install notionary
20
- ```
21
-
22
- ## Custom Markdown Syntax
23
-
24
- Notionary extends standard Markdown with special syntax to support Notion-specific features:
25
-
26
- ### Text Formatting
27
-
28
- - Standard Markdown: `**bold**`, `*italic*`, `~~strikethrough~~`, `` `code` ``
29
- - Highlights: `==highlighted text==`, `==red warning==`, `==blue==`
30
-
31
- ### Block Elements
32
-
33
- #### Callouts
34
-
35
- ```markdown
36
- !> [💡] This is a default callout with the light bulb emoji
37
- !> [🔔] This is a callout with a bell emoji
38
- !> {blue_background} [💧] This is a blue callout with a water drop emoji
39
- !> {yellow_background} [⚠️] Warning: This is an important note
40
- ```
41
-
42
- #### Toggles
43
-
44
- ```markdown
45
- +++ How to use NotionPageManager
46
-
47
- 1. Initialize with NotionPageManager
48
- 2. Update metadata with set_title(), set_page_icon(), etc.
49
- 3. Add content with replace_content() or append_markdown()
50
- ```
51
-
52
- #### Bookmarks
53
-
54
- ```markdown
55
- [bookmark](https://notion.so "Notion Homepage" "Your connected workspace")
56
- ```
57
-
58
- #### Multi-Column Layouts
59
-
60
- ```markdown
61
- ::: columns
62
- ::: column
63
- Content for first column
64
- :::
65
- ::: column
66
- Content for second column
67
- :::
68
- :::
69
- ```
70
-
71
- And more:
72
-
73
- - Tables with standard Markdown syntax
74
- - Code blocks with syntax highlighting
75
- - To-do lists with `- [ ]` and `- [x]`
76
- - Block quotes with `>`
77
-
78
- ## Database Management
79
-
80
- Notionary makes it easy to work with Notion databases, automatically handling schema detection and property conversion:
81
-
82
- ```python
83
- import asyncio
84
- from notionary.core.database.notion_database_manager import NotionDatabaseManager
85
-
86
- async def main():
87
- database_id = "1a6389d5-7bd3-8097-aa38-e93cb052615a"
88
- db = NotionDatabaseManager(database_id)
89
- await db.initialize()
90
-
91
- properties = {
92
- "Title": "Created via Notionary",
93
- "Description": "This entry was created using Notionary.",
94
- "Status": "In Progress",
95
- "Priority": "High"
96
- }
97
-
98
- result = await db.create_page(properties)
99
-
100
- if result["success"]:
101
- page_id = result["page_id"]
102
- await db.update_page(page_id, {"Status": "Completed"})
103
-
104
- filter_conditions = {
105
- "property": "Status",
106
- "status": {"equals": "Completed"}
107
- }
108
-
109
- pages = await db.get_pages(limit=10, filter_conditions=filter_conditions)
110
-
111
- await db.close()
112
-
113
- if __name__ == "__main__":
114
- asyncio.run(main())
115
- ```
116
-
117
- ## Finding Databases by Name
118
-
119
- Use fuzzy matching to find databases:
120
-
121
- ```python
122
- from notionary.core.database.notion_database_manager_factory import NotionDatabaseFactory
123
-
124
- async def main():
125
- db_manager = await NotionDatabaseFactory.from_database_name("Projects")
126
- print(f"Found database: {db_manager.title}")
127
- await db_manager.close()
128
- ```
129
-
130
- ## Page Content Management
131
-
132
- Create rich Notion pages using enhanced Markdown:
133
-
134
- ```python
135
- from notionary.core.page.notion_page_manager import NotionPageManager
136
-
137
- async def create_rich_page():
138
- url = "https://www.notion.so/Your-Page-1cd389d57bd381e58be9d35ce24adf3d"
139
- page_manager = NotionPageManager(url=url)
140
-
141
- await page_manager.set_title("Notionary Demo")
142
- await page_manager.set_page_icon(emoji="✨")
143
- await page_manager.set_page_cover("https://images.unsplash.com/photo-1555066931-4365d14bab8c")
144
-
145
- markdown = '''
146
- # Notionary Rich Content Demo
147
-
148
- !> [💡] This page was created with Notionary's custom Markdown syntax.
149
-
150
- ## Features
151
- - Easy-to-use Python API
152
- - **Rich** Markdown support
153
- - Async functionality
154
-
155
- +++ Implementation Details
156
- Notionary uses a custom converter to transform Markdown into Notion blocks.
157
- This makes it easy to create rich content programmatically.
158
- '''
159
-
160
- await page_manager.replace_content(markdown)
161
- ```
162
-
163
- ## Perfect for AI Agents and Automation
164
-
165
- - **Dynamic Content Generation**: AI agents can generate content in Markdown and render it as Notion pages
166
- - **Schema-Aware Operations**: Automatically validate and format properties
167
- - **Simplified API**: Easier integration with AI workflows
168
-
169
- ## Examples
170
-
171
- See the `examples` folder for:
172
-
173
- - Database discovery and querying
174
- - Rich page creation with Markdown
175
- - Entry management
176
- - Metadata manipulation
177
-
178
- ## License
179
-
180
- MIT
181
-
182
- ## Contributing
183
-
184
- Contributions welcome — feel free to submit a pull request!
File without changes
File without changes