notionhelper 0.1.5__tar.gz → 0.1.7__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.
- notionhelper-0.1.7/.claude/settings.local.json +12 -0
- notionhelper-0.1.7/.coverage +0 -0
- notionhelper-0.1.7/.github/workflows/claude-code-review.yml +78 -0
- notionhelper-0.1.7/.github/workflows/claude.yml +64 -0
- notionhelper-0.1.7/CLAUDE.md +74 -0
- notionhelper-0.1.7/PKG-INFO +256 -0
- notionhelper-0.1.7/README.md +230 -0
- notionhelper-0.1.7/pyproject.toml +64 -0
- notionhelper-0.1.7/pytest.ini +28 -0
- notionhelper-0.1.7/src/notionhelper/__init__.py +3 -0
- {notionhelper-0.1.5 → notionhelper-0.1.7}/src/notionhelper/helper.py +53 -41
- notionhelper-0.1.7/tests/README.md +194 -0
- notionhelper-0.1.7/tests/__init__.py +1 -0
- notionhelper-0.1.7/tests/conftest.py +283 -0
- notionhelper-0.1.7/tests/test_helper.py +365 -0
- notionhelper-0.1.7/uv.lock +921 -0
- notionhelper-0.1.5/PKG-INFO +0 -142
- notionhelper-0.1.5/README.md +0 -130
- notionhelper-0.1.5/pyproject.toml +0 -19
- notionhelper-0.1.5/src/notionhelper/__init__.py +0 -1
- notionhelper-0.1.5/uv.lock +0 -337
- {notionhelper-0.1.5 → notionhelper-0.1.7}/.gitignore +0 -0
- {notionhelper-0.1.5 → notionhelper-0.1.7}/.python-version +0 -0
- {notionhelper-0.1.5 → notionhelper-0.1.7}/images/helper_logo.png +0 -0
- {notionhelper-0.1.5 → notionhelper-0.1.7}/images/json_builder.png.png +0 -0
|
Binary file
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Claude Code Review
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, synchronize]
|
|
6
|
+
# Optional: Only run on specific file changes
|
|
7
|
+
# paths:
|
|
8
|
+
# - "src/**/*.ts"
|
|
9
|
+
# - "src/**/*.tsx"
|
|
10
|
+
# - "src/**/*.js"
|
|
11
|
+
# - "src/**/*.jsx"
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
claude-review:
|
|
15
|
+
# Optional: Filter by PR author
|
|
16
|
+
# if: |
|
|
17
|
+
# github.event.pull_request.user.login == 'external-contributor' ||
|
|
18
|
+
# github.event.pull_request.user.login == 'new-developer' ||
|
|
19
|
+
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
|
|
20
|
+
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
permissions:
|
|
23
|
+
contents: read
|
|
24
|
+
pull-requests: read
|
|
25
|
+
issues: read
|
|
26
|
+
id-token: write
|
|
27
|
+
|
|
28
|
+
steps:
|
|
29
|
+
- name: Checkout repository
|
|
30
|
+
uses: actions/checkout@v4
|
|
31
|
+
with:
|
|
32
|
+
fetch-depth: 1
|
|
33
|
+
|
|
34
|
+
- name: Run Claude Code Review
|
|
35
|
+
id: claude-review
|
|
36
|
+
uses: anthropics/claude-code-action@beta
|
|
37
|
+
with:
|
|
38
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
39
|
+
|
|
40
|
+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4.1)
|
|
41
|
+
# model: "claude-opus-4-1-20250805"
|
|
42
|
+
|
|
43
|
+
# Direct prompt for automated review (no @claude mention needed)
|
|
44
|
+
direct_prompt: |
|
|
45
|
+
Please review this pull request and provide feedback on:
|
|
46
|
+
- Code quality and best practices
|
|
47
|
+
- Potential bugs or issues
|
|
48
|
+
- Performance considerations
|
|
49
|
+
- Security concerns
|
|
50
|
+
- Test coverage
|
|
51
|
+
|
|
52
|
+
Be constructive and helpful in your feedback.
|
|
53
|
+
|
|
54
|
+
# Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR
|
|
55
|
+
# use_sticky_comment: true
|
|
56
|
+
|
|
57
|
+
# Optional: Customize review based on file types
|
|
58
|
+
# direct_prompt: |
|
|
59
|
+
# Review this PR focusing on:
|
|
60
|
+
# - For TypeScript files: Type safety and proper interface usage
|
|
61
|
+
# - For API endpoints: Security, input validation, and error handling
|
|
62
|
+
# - For React components: Performance, accessibility, and best practices
|
|
63
|
+
# - For tests: Coverage, edge cases, and test quality
|
|
64
|
+
|
|
65
|
+
# Optional: Different prompts for different authors
|
|
66
|
+
# direct_prompt: |
|
|
67
|
+
# ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' &&
|
|
68
|
+
# 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' ||
|
|
69
|
+
# 'Please provide a thorough code review focusing on our coding standards and best practices.' }}
|
|
70
|
+
|
|
71
|
+
# Optional: Add specific tools for running tests or linting
|
|
72
|
+
# allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)"
|
|
73
|
+
|
|
74
|
+
# Optional: Skip review for certain conditions
|
|
75
|
+
# if: |
|
|
76
|
+
# !contains(github.event.pull_request.title, '[skip-review]') &&
|
|
77
|
+
# !contains(github.event.pull_request.title, '[WIP]')
|
|
78
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
name: Claude Code
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
pull_request_review_comment:
|
|
7
|
+
types: [created]
|
|
8
|
+
issues:
|
|
9
|
+
types: [opened, assigned]
|
|
10
|
+
pull_request_review:
|
|
11
|
+
types: [submitted]
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
claude:
|
|
15
|
+
if: |
|
|
16
|
+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
|
|
17
|
+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
|
|
18
|
+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
|
|
19
|
+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
permissions:
|
|
22
|
+
contents: read
|
|
23
|
+
pull-requests: read
|
|
24
|
+
issues: read
|
|
25
|
+
id-token: write
|
|
26
|
+
actions: read # Required for Claude to read CI results on PRs
|
|
27
|
+
steps:
|
|
28
|
+
- name: Checkout repository
|
|
29
|
+
uses: actions/checkout@v4
|
|
30
|
+
with:
|
|
31
|
+
fetch-depth: 1
|
|
32
|
+
|
|
33
|
+
- name: Run Claude Code
|
|
34
|
+
id: claude
|
|
35
|
+
uses: anthropics/claude-code-action@beta
|
|
36
|
+
with:
|
|
37
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
38
|
+
|
|
39
|
+
# This is an optional setting that allows Claude to read CI results on PRs
|
|
40
|
+
additional_permissions: |
|
|
41
|
+
actions: read
|
|
42
|
+
|
|
43
|
+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4.1)
|
|
44
|
+
# model: "claude-opus-4-1-20250805"
|
|
45
|
+
|
|
46
|
+
# Optional: Customize the trigger phrase (default: @claude)
|
|
47
|
+
# trigger_phrase: "/claude"
|
|
48
|
+
|
|
49
|
+
# Optional: Trigger when specific user is assigned to an issue
|
|
50
|
+
# assignee_trigger: "claude-bot"
|
|
51
|
+
|
|
52
|
+
# Optional: Allow Claude to run specific commands
|
|
53
|
+
# allowed_tools: "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)"
|
|
54
|
+
|
|
55
|
+
# Optional: Add custom instructions for Claude to customize its behavior for your project
|
|
56
|
+
# custom_instructions: |
|
|
57
|
+
# Follow our coding standards
|
|
58
|
+
# Ensure all new code has tests
|
|
59
|
+
# Use TypeScript for new files
|
|
60
|
+
|
|
61
|
+
# Optional: Custom environment variables for Claude
|
|
62
|
+
# claude_env: |
|
|
63
|
+
# NODE_ENV: test
|
|
64
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
NotionHelper is a Python library that provides a convenient interface for interacting with the Notion API. The library simplifies database management, page operations, file handling, and data conversion to Pandas DataFrames.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
### Package Management
|
|
12
|
+
- Uses `uv` for dependency management (see `uv.lock`)
|
|
13
|
+
- Install dependencies: `uv sync` or `uv sync --extra dev`
|
|
14
|
+
- Build package: `uv build`
|
|
15
|
+
|
|
16
|
+
### Testing
|
|
17
|
+
- Full pytest test suite with 21 tests covering all major functionality
|
|
18
|
+
- Run tests: `uv run pytest`
|
|
19
|
+
- Run with coverage: `uv run pytest --cov=src/notionhelper --cov-report=term-missing`
|
|
20
|
+
- Test configuration in `pytest.ini` and `pyproject.toml`
|
|
21
|
+
- Install test dependencies: `uv sync --extra test`
|
|
22
|
+
|
|
23
|
+
## Architecture
|
|
24
|
+
|
|
25
|
+
### Core Structure
|
|
26
|
+
- Main implementation: `src/notionhelper/helper.py`
|
|
27
|
+
- Single class `NotionHelper` contains all functionality
|
|
28
|
+
- Built on top of `notion-client`, `requests`, and `pandas`
|
|
29
|
+
|
|
30
|
+
### Key Components
|
|
31
|
+
|
|
32
|
+
**NotionHelper Class** (`src/notionhelper/helper.py:12`)
|
|
33
|
+
- Single entry point for all Notion API interactions
|
|
34
|
+
- Handles authentication via token-based auth
|
|
35
|
+
- Provides both basic API wrappers and convenience methods
|
|
36
|
+
|
|
37
|
+
**Database Operations**
|
|
38
|
+
- `get_database()` - retrieve database schema
|
|
39
|
+
- `create_database()` - create new databases
|
|
40
|
+
- `get_all_pages_as_json()` / `get_all_pages_as_dataframe()` - bulk data retrieval with pagination
|
|
41
|
+
|
|
42
|
+
**Page Operations**
|
|
43
|
+
- `new_page_to_db()` - add pages to databases
|
|
44
|
+
- `append_page_body()` - add content blocks to pages
|
|
45
|
+
- `notion_get_page()` - retrieve page properties and blocks
|
|
46
|
+
|
|
47
|
+
**File Operations**
|
|
48
|
+
- `upload_file()` - raw file upload to Notion
|
|
49
|
+
- `attach_file_to_page()` / `embed_image_to_page()` - attach files/images to pages
|
|
50
|
+
- `one_step_*` methods - convenience functions combining upload + attachment
|
|
51
|
+
|
|
52
|
+
**Data Conversion**
|
|
53
|
+
- `get_all_pages_as_dataframe()` - converts Notion data to pandas DataFrame
|
|
54
|
+
- Handles 19+ Notion property types (title, status, number, date, etc.)
|
|
55
|
+
- Includes pagination support and optional page ID inclusion
|
|
56
|
+
|
|
57
|
+
### Authentication Pattern
|
|
58
|
+
- Requires `NOTION_TOKEN` environment variable
|
|
59
|
+
- Token passed to constructor: `NotionHelper(notion_token)`
|
|
60
|
+
- Uses notion-client's `Client(auth=token)` for API access
|
|
61
|
+
|
|
62
|
+
### Dependencies
|
|
63
|
+
- `notion-client>=2.4.0` - Official Notion API client
|
|
64
|
+
- `pandas>=2.3.1` - DataFrame operations
|
|
65
|
+
- `requests>=2.32.4` - Direct API calls for file operations
|
|
66
|
+
- `mimetype>=0.1.5` - File type detection
|
|
67
|
+
|
|
68
|
+
## Development Notes
|
|
69
|
+
|
|
70
|
+
- The library uses synchronous operations only
|
|
71
|
+
- File uploads use Notion's file upload API with direct HTTP requests
|
|
72
|
+
- Pagination is handled automatically in bulk operations
|
|
73
|
+
- Property extraction supports most common Notion field types
|
|
74
|
+
- Complementary Streamlit app available for JSON construction: https://notioinapiassistant.streamlit.app
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: notionhelper
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author-email: Jan du Plessis <drjanduplessis@icloud.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: mimetype>=0.1.5
|
|
8
|
+
Requires-Dist: notion-client>=2.4.0
|
|
9
|
+
Requires-Dist: pandas>=2.3.1
|
|
10
|
+
Requires-Dist: requests>=2.32.4
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: flake8>=6.0.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: isort>=5.12.0; extra == 'dev'
|
|
15
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'test'
|
|
22
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
|
|
23
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == 'test'
|
|
24
|
+
Requires-Dist: pytest>=7.0.0; extra == 'test'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# NotionHelper
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
`NotionHelper` is a Python library that provides a convenient interface for interacting with the Notion API. It simplifies common tasks such as managing databases, pages, and file uploads, allowing you to integrate Notion's powerful features into your applications with ease.
|
|
32
|
+
|
|
33
|
+
For help constructing the JSON for the properties, use the [Notion API - JSON Builder](https://notioinapiassistant.streamlit.app) Streamlit app.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- **Synchronous Operations**: Uses `notion-client` and `requests` for straightforward API interactions.
|
|
38
|
+
- **Type Safety**: Full type hints for all methods ensuring better development experience and IDE support.
|
|
39
|
+
- **Error Handling**: Robust error handling for API calls and file operations.
|
|
40
|
+
- **Database Management**: Create, query, and retrieve Notion databases.
|
|
41
|
+
- **Page Operations**: Add new pages to databases and append content to existing pages.
|
|
42
|
+
- **File Handling**: Upload files and attach them to pages or page properties with built-in validation.
|
|
43
|
+
- **Pandas Integration**: Convert Notion database pages into a Pandas DataFrame for easy data manipulation.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
To install `NotionHelper`, you can use `pip`:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install notionhelper
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This will also install all the necessary dependencies, including `notion-client`, `pandas`, and `requests`.
|
|
54
|
+
|
|
55
|
+
## Authentication
|
|
56
|
+
|
|
57
|
+
To use the Notion API, you need to create an integration and obtain an integration token.
|
|
58
|
+
|
|
59
|
+
1. **Create an Integration**: Go to [My Integrations](https://www.notion.so/my-integrations) and create a new integration.
|
|
60
|
+
2. **Get the Token**: Copy the "Internal Integration Token".
|
|
61
|
+
3. **Share with a Page/Database**: For your integration to access a page or database, you must share it with your integration from the "Share" menu in Notion.
|
|
62
|
+
|
|
63
|
+
It is recommended to store your Notion token as an environment variable for security.
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
export NOTION_TOKEN="your_secret_token"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
Here is an example of how to use the library:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import os
|
|
75
|
+
from notionhelper import NotionHelper
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Initialize the NotionHelper class
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
notion_token = os.getenv("NOTION_TOKEN")
|
|
82
|
+
|
|
83
|
+
helper = NotionHelper(notion_token)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Retrieve a Database
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
database_id = "your_database_id"
|
|
90
|
+
database_schema = helper.get_database(database_id)
|
|
91
|
+
print(database_schema)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Create a New Page in a Database
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
page_properties = {
|
|
98
|
+
"Name": {
|
|
99
|
+
"title": [
|
|
100
|
+
{
|
|
101
|
+
"text": {
|
|
102
|
+
"content": "New Page from NotionHelper"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
new_page = helper.new_page_to_db(database_id, page_properties)
|
|
109
|
+
print(new_page)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Append Content to the New Page
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
blocks = [
|
|
116
|
+
{
|
|
117
|
+
"object": "block",
|
|
118
|
+
"type": "heading_2",
|
|
119
|
+
"heading_2": {
|
|
120
|
+
"rich_text": [{"type": "text", "text": {"content": "Hello from NotionHelper!"}}]
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"object": "block",
|
|
125
|
+
"type": "paragraph",
|
|
126
|
+
"paragraph": {
|
|
127
|
+
"rich_text": [
|
|
128
|
+
{
|
|
129
|
+
"type": "text",
|
|
130
|
+
"text": {
|
|
131
|
+
"content": "This content was appended synchronously."
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
helper.append_page_body(page_id, blocks)
|
|
139
|
+
print(f"Successfully appended content to page ID: {page_id}")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Get all pages as a Pandas DataFrame
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
df = helper.get_all_pages_as_dataframe(database_id)
|
|
146
|
+
print(df.head())
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Upload a File and Attach to a Page
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
try:
|
|
153
|
+
file_path = "path/to/your/file.pdf" # Replace with your file path
|
|
154
|
+
upload_response = helper.upload_file(file_path)
|
|
155
|
+
file_upload_id = upload_response["id"]
|
|
156
|
+
# Replace with your page_id
|
|
157
|
+
page_id = "your_page_id"
|
|
158
|
+
attach_response = helper.attach_file_to_page(page_id, file_upload_id)
|
|
159
|
+
print(f"Successfully uploaded and attached file: {attach_response}")
|
|
160
|
+
except Exception as e:
|
|
161
|
+
print(f"Error uploading file: {e}")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Simplified File Operations
|
|
165
|
+
|
|
166
|
+
NotionHelper provides convenient one-step methods that combine file upload and attachment operations:
|
|
167
|
+
|
|
168
|
+
#### one_step_image_embed()
|
|
169
|
+
Uploads an image and embeds it in a Notion page in a single call, combining what would normally require:
|
|
170
|
+
1. Uploading the file
|
|
171
|
+
2. Embedding it in the page
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
page_id = "your_page_id"
|
|
175
|
+
image_path = "path/to/image.png"
|
|
176
|
+
response = helper.one_step_image_embed(page_id, image_path)
|
|
177
|
+
print(f"Successfully embedded image: {response}")
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### one_step_file_to_page()
|
|
181
|
+
Uploads a file and attaches it to a Notion page in one step, combining:
|
|
182
|
+
1. Uploading the file
|
|
183
|
+
2. Attaching it to the page
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
page_id = "your_page_id"
|
|
187
|
+
file_path = "path/to/document.pdf"
|
|
188
|
+
response = helper.one_step_file_to_page(page_id, file_path)
|
|
189
|
+
print(f"Successfully attached file: {response}")
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### one_step_file_to_page_property()
|
|
193
|
+
Uploads a file and attaches it to a specific Files & Media property on a page, combining:
|
|
194
|
+
1. Uploading the file
|
|
195
|
+
2. Attaching it to the page property
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
page_id = "your_page_id"
|
|
199
|
+
property_name = "Files" # Name of your Files & Media property
|
|
200
|
+
file_path = "path/to/document.pdf"
|
|
201
|
+
file_name = "Custom Display Name.pdf" # Optional display name
|
|
202
|
+
response = helper.one_step_file_to_page_property(page_id, property_name, file_path, file_name)
|
|
203
|
+
print(f"Successfully attached file to property: {response}")
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
These methods handle all the intermediate steps automatically, making file operations with Notion much simpler.
|
|
207
|
+
|
|
208
|
+
## Code Quality
|
|
209
|
+
|
|
210
|
+
The NotionHelper library includes several quality improvements:
|
|
211
|
+
|
|
212
|
+
- **Type Hints**: All methods include comprehensive type annotations for better IDE support and code clarity
|
|
213
|
+
- **Error Handling**: Built-in validation and exception handling for common failure scenarios
|
|
214
|
+
- **Clean Imports**: Explicit imports with `__all__` declaration for better namespace management
|
|
215
|
+
- **Production Ready**: Removed debug output and implemented proper error reporting
|
|
216
|
+
|
|
217
|
+
## Complete Function Reference
|
|
218
|
+
|
|
219
|
+
The `NotionHelper` class provides the following methods:
|
|
220
|
+
|
|
221
|
+
### Database Operations
|
|
222
|
+
- **`get_database(database_id)`** - Retrieves the schema of a Notion database
|
|
223
|
+
- **`create_database(parent_page_id, database_title, properties)`** - Creates a new database under a parent page
|
|
224
|
+
- **`notion_search_db(database_id, query="")`** - Searches for pages in a database containing the query in their title
|
|
225
|
+
|
|
226
|
+
### Page Operations
|
|
227
|
+
- **`new_page_to_db(database_id, page_properties)`** - Adds a new page to a database with specified properties
|
|
228
|
+
- **`append_page_body(page_id, blocks)`** - Appends blocks of content to the body of a page
|
|
229
|
+
- **`notion_get_page(page_id)`** - Retrieves page properties and content blocks as JSON
|
|
230
|
+
|
|
231
|
+
### Data Retrieval & Conversion
|
|
232
|
+
- **`get_all_page_ids(database_id)`** - Returns IDs of all pages in a database
|
|
233
|
+
- **`get_all_pages_as_json(database_id, limit=None)`** - Returns all pages as JSON objects with properties
|
|
234
|
+
- **`get_all_pages_as_dataframe(database_id, limit=None, include_page_ids=True)`** - Converts database pages to a Pandas DataFrame
|
|
235
|
+
|
|
236
|
+
### File Operations
|
|
237
|
+
- **`upload_file(file_path)`** - Uploads a file to Notion and returns the file upload object
|
|
238
|
+
- **`attach_file_to_page(page_id, file_upload_id)`** - Attaches an uploaded file to a specific page
|
|
239
|
+
- **`embed_image_to_page(page_id, file_upload_id)`** - Embeds an uploaded image into a page
|
|
240
|
+
- **`attach_file_to_page_property(page_id, property_name, file_upload_id, file_name)`** - Attaches a file to a Files & Media property
|
|
241
|
+
|
|
242
|
+
### One-Step Convenience Methods
|
|
243
|
+
- **`one_step_image_embed(page_id, file_path)`** - Uploads and embeds an image in one operation
|
|
244
|
+
- **`one_step_file_to_page(page_id, file_path)`** - Uploads and attaches a file to a page in one operation
|
|
245
|
+
- **`one_step_file_to_page_property(page_id, property_name, file_path, file_name)`** - Uploads and attaches a file to a page property in one operation
|
|
246
|
+
|
|
247
|
+
### Utility Methods
|
|
248
|
+
- **`info()`** - Displays comprehensive library information with all available methods (Jupyter notebook compatible)
|
|
249
|
+
|
|
250
|
+
## Requirements
|
|
251
|
+
|
|
252
|
+
- Python 3.10+
|
|
253
|
+
- notion-client >= 2.4.0
|
|
254
|
+
- pandas >= 2.3.1
|
|
255
|
+
- requests >= 2.32.4
|
|
256
|
+
- mimetype >= 0.1.5
|