A Python library for interacting with the Notion API, providing robust functionality for managing pages, databases, and content.
- Create and manage Notion pages
- Create and query databases
- Add page children
- Handle complex Notion object creation
# Clone the repository
git clone <repository-url>
# Install dependencies
pip install -r requirements.txt
api_token: your_notion_api_token_here
task_db_token: your_task_database_id_here
Define Notion object templates for consistent object creation.
Configure logging behavior
handler = NotionApiHandler()
handler.create_page(
parent_id="parent_page_id",
page_title="My New Page",
icon="https://example.com/icon.png"
)
handler = NotionApiHandler()
page = handler.retrieve_page(
page_id="page_id",
)
properties = {
"Description": "text", "Checkbox": "checkbox",
"Date": "date", "Email": "email",
}
handler.create_database(
parent_id="parent_page_id",
db_title="Project Tracker",
properties=properties
)
filters = {
"and": [
{"property": "Completed",
"checkbox": {"equals": True}},
{"property": "Project",
"relation": {"is_empty": True}}
]
}
sorts = [
{"property": "Date creation", "direction": "ascending"}
]
results = handler.query_database(
database_id="database_id",
filters=filters, sorts=sorts,
limit=50
)
Configurable logging through log-config.yaml
Automatically delete completed tasks without associated projects from a Notion database.
Customize deletion criteria in script:
- Completed tasks filter
- Project relation filter
- Sorting preferences
- Utilizes configurable logging
- Records task deletion information
# Delete completed tasks from specific database
python delete.py db_abc123