notionhelper 0.1.6__tar.gz → 0.1.8__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.8/.claude/settings.local.json +12 -0
- notionhelper-0.1.8/.coverage +0 -0
- notionhelper-0.1.8/.github/workflows/claude-code-review.yml +78 -0
- notionhelper-0.1.8/.github/workflows/claude.yml +64 -0
- notionhelper-0.1.8/CLAUDE.md +74 -0
- notionhelper-0.1.6/README.md → notionhelper-0.1.8/PKG-INFO +89 -8
- notionhelper-0.1.6/PKG-INFO → notionhelper-0.1.8/README.md +63 -20
- notionhelper-0.1.8/pyproject.toml +64 -0
- notionhelper-0.1.8/pytest.ini +28 -0
- notionhelper-0.1.8/src/notionhelper/__init__.py +3 -0
- {notionhelper-0.1.6 → notionhelper-0.1.8}/src/notionhelper/helper.py +53 -41
- notionhelper-0.1.8/tests/README.md +194 -0
- notionhelper-0.1.8/tests/__init__.py +1 -0
- notionhelper-0.1.8/tests/conftest.py +283 -0
- notionhelper-0.1.8/tests/test_helper.py +365 -0
- notionhelper-0.1.8/uv.lock +921 -0
- notionhelper-0.1.6/pyproject.toml +0 -19
- notionhelper-0.1.6/src/notionhelper/__init__.py +0 -1
- notionhelper-0.1.6/uv.lock +0 -337
- {notionhelper-0.1.6 → notionhelper-0.1.8}/.gitignore +0 -0
- {notionhelper-0.1.6 → notionhelper-0.1.8}/.python-version +0 -0
- {notionhelper-0.1.6 → notionhelper-0.1.8}/images/helper_logo.png +0 -0
- {notionhelper-0.1.6 → notionhelper-0.1.8}/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
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: notionhelper
|
|
3
|
+
Version: 0.1.8
|
|
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
|
+
|
|
1
27
|
# NotionHelper
|
|
2
28
|
|
|
3
29
|

|
|
@@ -9,9 +35,11 @@ For help constructing the JSON for the properties, use the [Notion API - JSON Bu
|
|
|
9
35
|
## Features
|
|
10
36
|
|
|
11
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.
|
|
12
40
|
- **Database Management**: Create, query, and retrieve Notion databases.
|
|
13
41
|
- **Page Operations**: Add new pages to databases and append content to existing pages.
|
|
14
|
-
- **File Handling**: Upload files and attach them to pages or page properties.
|
|
42
|
+
- **File Handling**: Upload files and attach them to pages or page properties with built-in validation.
|
|
15
43
|
- **Pandas Integration**: Convert Notion database pages into a Pandas DataFrame for easy data manipulation.
|
|
16
44
|
|
|
17
45
|
## Installation
|
|
@@ -121,13 +149,16 @@ print(f"Successfully appended content to page ID: {page_id}")
|
|
|
121
149
|
### Upload a File and Attach to a Page
|
|
122
150
|
|
|
123
151
|
```python
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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}")
|
|
131
162
|
```
|
|
132
163
|
|
|
133
164
|
### Simplified File Operations
|
|
@@ -173,3 +204,53 @@ print(f"Successfully attached file to property: {response}")
|
|
|
173
204
|
```
|
|
174
205
|
|
|
175
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
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: notionhelper
|
|
3
|
-
Version: 0.1.6
|
|
4
|
-
Summary: Add your description here
|
|
5
|
-
Author-email: Jan du Plessis <drjanduplessis@icloud.com>
|
|
6
|
-
Requires-Python: >=3.12
|
|
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
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
|
|
13
1
|
# NotionHelper
|
|
14
2
|
|
|
15
3
|

|
|
@@ -21,9 +9,11 @@ For help constructing the JSON for the properties, use the [Notion API - JSON Bu
|
|
|
21
9
|
## Features
|
|
22
10
|
|
|
23
11
|
- **Synchronous Operations**: Uses `notion-client` and `requests` for straightforward API interactions.
|
|
12
|
+
- **Type Safety**: Full type hints for all methods ensuring better development experience and IDE support.
|
|
13
|
+
- **Error Handling**: Robust error handling for API calls and file operations.
|
|
24
14
|
- **Database Management**: Create, query, and retrieve Notion databases.
|
|
25
15
|
- **Page Operations**: Add new pages to databases and append content to existing pages.
|
|
26
|
-
- **File Handling**: Upload files and attach them to pages or page properties.
|
|
16
|
+
- **File Handling**: Upload files and attach them to pages or page properties with built-in validation.
|
|
27
17
|
- **Pandas Integration**: Convert Notion database pages into a Pandas DataFrame for easy data manipulation.
|
|
28
18
|
|
|
29
19
|
## Installation
|
|
@@ -133,13 +123,16 @@ print(f"Successfully appended content to page ID: {page_id}")
|
|
|
133
123
|
### Upload a File and Attach to a Page
|
|
134
124
|
|
|
135
125
|
```python
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
126
|
+
try:
|
|
127
|
+
file_path = "path/to/your/file.pdf" # Replace with your file path
|
|
128
|
+
upload_response = helper.upload_file(file_path)
|
|
129
|
+
file_upload_id = upload_response["id"]
|
|
130
|
+
# Replace with your page_id
|
|
131
|
+
page_id = "your_page_id"
|
|
132
|
+
attach_response = helper.attach_file_to_page(page_id, file_upload_id)
|
|
133
|
+
print(f"Successfully uploaded and attached file: {attach_response}")
|
|
134
|
+
except Exception as e:
|
|
135
|
+
print(f"Error uploading file: {e}")
|
|
143
136
|
```
|
|
144
137
|
|
|
145
138
|
### Simplified File Operations
|
|
@@ -185,3 +178,53 @@ print(f"Successfully attached file to property: {response}")
|
|
|
185
178
|
```
|
|
186
179
|
|
|
187
180
|
These methods handle all the intermediate steps automatically, making file operations with Notion much simpler.
|
|
181
|
+
|
|
182
|
+
## Code Quality
|
|
183
|
+
|
|
184
|
+
The NotionHelper library includes several quality improvements:
|
|
185
|
+
|
|
186
|
+
- **Type Hints**: All methods include comprehensive type annotations for better IDE support and code clarity
|
|
187
|
+
- **Error Handling**: Built-in validation and exception handling for common failure scenarios
|
|
188
|
+
- **Clean Imports**: Explicit imports with `__all__` declaration for better namespace management
|
|
189
|
+
- **Production Ready**: Removed debug output and implemented proper error reporting
|
|
190
|
+
|
|
191
|
+
## Complete Function Reference
|
|
192
|
+
|
|
193
|
+
The `NotionHelper` class provides the following methods:
|
|
194
|
+
|
|
195
|
+
### Database Operations
|
|
196
|
+
- **`get_database(database_id)`** - Retrieves the schema of a Notion database
|
|
197
|
+
- **`create_database(parent_page_id, database_title, properties)`** - Creates a new database under a parent page
|
|
198
|
+
- **`notion_search_db(database_id, query="")`** - Searches for pages in a database containing the query in their title
|
|
199
|
+
|
|
200
|
+
### Page Operations
|
|
201
|
+
- **`new_page_to_db(database_id, page_properties)`** - Adds a new page to a database with specified properties
|
|
202
|
+
- **`append_page_body(page_id, blocks)`** - Appends blocks of content to the body of a page
|
|
203
|
+
- **`notion_get_page(page_id)`** - Retrieves page properties and content blocks as JSON
|
|
204
|
+
|
|
205
|
+
### Data Retrieval & Conversion
|
|
206
|
+
- **`get_all_page_ids(database_id)`** - Returns IDs of all pages in a database
|
|
207
|
+
- **`get_all_pages_as_json(database_id, limit=None)`** - Returns all pages as JSON objects with properties
|
|
208
|
+
- **`get_all_pages_as_dataframe(database_id, limit=None, include_page_ids=True)`** - Converts database pages to a Pandas DataFrame
|
|
209
|
+
|
|
210
|
+
### File Operations
|
|
211
|
+
- **`upload_file(file_path)`** - Uploads a file to Notion and returns the file upload object
|
|
212
|
+
- **`attach_file_to_page(page_id, file_upload_id)`** - Attaches an uploaded file to a specific page
|
|
213
|
+
- **`embed_image_to_page(page_id, file_upload_id)`** - Embeds an uploaded image into a page
|
|
214
|
+
- **`attach_file_to_page_property(page_id, property_name, file_upload_id, file_name)`** - Attaches a file to a Files & Media property
|
|
215
|
+
|
|
216
|
+
### One-Step Convenience Methods
|
|
217
|
+
- **`one_step_image_embed(page_id, file_path)`** - Uploads and embeds an image in one operation
|
|
218
|
+
- **`one_step_file_to_page(page_id, file_path)`** - Uploads and attaches a file to a page in one operation
|
|
219
|
+
- **`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
|
|
220
|
+
|
|
221
|
+
### Utility Methods
|
|
222
|
+
- **`info()`** - Displays comprehensive library information with all available methods (Jupyter notebook compatible)
|
|
223
|
+
|
|
224
|
+
## Requirements
|
|
225
|
+
|
|
226
|
+
- Python 3.10+
|
|
227
|
+
- notion-client >= 2.4.0
|
|
228
|
+
- pandas >= 2.3.1
|
|
229
|
+
- requests >= 2.32.4
|
|
230
|
+
- mimetype >= 0.1.5
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "notionhelper"
|
|
3
|
+
version = "0.1.8"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Jan du Plessis", email = "drjanduplessis@icloud.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"mimetype>=0.1.5",
|
|
12
|
+
"notion-client>=2.4.0",
|
|
13
|
+
"pandas>=2.3.1",
|
|
14
|
+
"requests>=2.32.4",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["hatchling"]
|
|
19
|
+
build-backend = "hatchling.build"
|
|
20
|
+
|
|
21
|
+
[tool.pytest.ini_options]
|
|
22
|
+
testpaths = ["tests"]
|
|
23
|
+
python_files = "test_*.py"
|
|
24
|
+
python_classes = "Test*"
|
|
25
|
+
python_functions = "test_*"
|
|
26
|
+
addopts = [
|
|
27
|
+
"--verbose",
|
|
28
|
+
"--strict-markers",
|
|
29
|
+
"--strict-config",
|
|
30
|
+
"--tb=short",
|
|
31
|
+
"--cov=src/notionhelper",
|
|
32
|
+
"--cov-report=term-missing",
|
|
33
|
+
"--cov-report=html:htmlcov",
|
|
34
|
+
"--cov-report=xml",
|
|
35
|
+
"--cov-fail-under=80"
|
|
36
|
+
]
|
|
37
|
+
markers = [
|
|
38
|
+
"unit: Unit tests",
|
|
39
|
+
"integration: Integration tests",
|
|
40
|
+
"slow: Slow tests that may take longer to run",
|
|
41
|
+
"network: Tests that require network access (normally mocked)"
|
|
42
|
+
]
|
|
43
|
+
filterwarnings = [
|
|
44
|
+
"ignore::DeprecationWarning",
|
|
45
|
+
"ignore::PendingDeprecationWarning"
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
test = [
|
|
50
|
+
"pytest>=7.0.0",
|
|
51
|
+
"pytest-cov>=4.0.0",
|
|
52
|
+
"pytest-mock>=3.10.0",
|
|
53
|
+
"pytest-asyncio>=0.21.0"
|
|
54
|
+
]
|
|
55
|
+
dev = [
|
|
56
|
+
"pytest>=7.0.0",
|
|
57
|
+
"pytest-cov>=4.0.0",
|
|
58
|
+
"pytest-mock>=3.10.0",
|
|
59
|
+
"pytest-asyncio>=0.21.0",
|
|
60
|
+
"black>=23.0.0",
|
|
61
|
+
"isort>=5.12.0",
|
|
62
|
+
"flake8>=6.0.0",
|
|
63
|
+
"mypy>=1.0.0"
|
|
64
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[tool:pytest]
|
|
2
|
+
# Pytest configuration for NotionHelper
|
|
3
|
+
testpaths = tests
|
|
4
|
+
python_files = test_*.py
|
|
5
|
+
python_classes = Test*
|
|
6
|
+
python_functions = test_*
|
|
7
|
+
addopts =
|
|
8
|
+
--verbose
|
|
9
|
+
--strict-markers
|
|
10
|
+
--strict-config
|
|
11
|
+
--tb=short
|
|
12
|
+
--cov=src/notionhelper
|
|
13
|
+
--cov-report=term-missing
|
|
14
|
+
--cov-report=html:htmlcov
|
|
15
|
+
--cov-report=xml
|
|
16
|
+
--cov-fail-under=80
|
|
17
|
+
markers =
|
|
18
|
+
unit: Unit tests
|
|
19
|
+
integration: Integration tests
|
|
20
|
+
slow: Slow tests that may take longer to run
|
|
21
|
+
network: Tests that require network access (normally mocked)
|
|
22
|
+
filterwarnings =
|
|
23
|
+
ignore::DeprecationWarning
|
|
24
|
+
ignore::PendingDeprecationWarning
|
|
25
|
+
log_cli = true
|
|
26
|
+
log_cli_level = INFO
|
|
27
|
+
log_cli_format = %(asctime)s [%(levelname)8s] %(name)s: %(message)s
|
|
28
|
+
log_cli_date_format = %Y-%m-%d %H:%M:%S
|