Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
42cdcd6
Remove GDrive
mdelmans Jan 3, 2025
0057c29
Create a subfolder for sync version
mdelmans Jan 3, 2025
6bb656c
Fix some typehints
mdelmans Jan 3, 2025
66ae8f9
Update README
mdelmans Jan 3, 2025
eb7b6a2
Rename README
mdelmans Jan 3, 2025
c452ece
Remove unused dependencies
mdelmans Jan 3, 2025
09f702c
Add pull workflow
mdelmans Jan 3, 2025
17384cc
Add NOTION_TOKEN env var to pull workflow
mdelmans Jan 8, 2025
32d306b
Split cache action. Add test report generator
mdelmans Jan 8, 2025
b50567a
Add dummy release workflow
mdelmans Jan 8, 2025
bc1fd98
Add GITHUB_TOKEN env var to release workflow
mdelmans Jan 8, 2025
981a11b
Add GITHUB_TOKEN env var to release workflow
mdelmans Jan 8, 2025
4196163
Add feature_1
mdelmans Jan 8, 2025
b869a71
Add pull_request trigger to release workflow
mdelmans Jan 8, 2025
10f4798
Add feature 2
mdelmans Jan 8, 2025
9449d11
Fixed bug 1
mdelmans Jan 8, 2025
e24b9a4
Add version increment for hotfixes
mdelmans Jan 8, 2025
e79755b
Fix pull_request branches in release workflow
mdelmans Jan 8, 2025
74ee5ee
Add feature 5
mdelmans Jan 8, 2025
5cb93cb
Fixed: fake bug 2
mdelmans Jan 8, 2025
b26b764
Fix fake bug 3
mdelmans Jan 8, 2025
3cd18f8
Fix fake hotfix 4
mdelmans Jan 8, 2025
8b432b2
Fix fake bug 5
mdelmans Jan 8, 2025
268feec
Fix fake bug 6
mdelmans Jan 8, 2025
e948453
Add fake feature 6
mdelmans Jan 8, 2025
d625886
Fix fake bug 7
mdelmans Jan 8, 2025
07333f0
Add build/publish steps to release workflow
mdelmans Jan 8, 2025
2a1f827
Fix release worklfow defs
mdelmans Jan 8, 2025
75a45d9
Fix output -> outputs in the release workflow tml
mdelmans Jan 8, 2025
cead205
Add auto-commit step for version update in the release workflow
mdelmans Jan 8, 2025
eed378c
Add a commit message for version bump in the release workflow
mdelmans Jan 8, 2025
21d47f0
Bump version to 0.12.0
mdelmans Jan 8, 2025
b80ddd7
Change NOTION_TOKEN to secrets vs vars
mdelmans Jan 9, 2025
fcaf7c9
Fix release workflow to use actual PyPI and non-fake branches
mdelmans Jan 24, 2025
0e1c52a
Add logo to README.md
mdelmans Jan 30, 2025
4f666bd
Change opening sentence in README.md
mdelmans Jan 30, 2025
9ceabd3
Fix README.md
mdelmans Jan 30, 2025
04b17c1
Cleanup pipelines definitions
mdelmans Jan 30, 2025
2788f8b
Add pre-commit action to PR workflow
mdelmans Jan 30, 2025
9a07787
Move documentation to docs
mdelmans Jan 30, 2025
4c981ce
Fix link to logo in README.md
mdelmans Jan 30, 2025
9acf9ac
Remove features.md
mdelmans Jan 30, 2025
b8057b5
Cleanup typehints and docstrings. Add API docs
mdelmans Jan 31, 2025
062a6e0
Update authors list
mdelmans Jan 31, 2025
a832b76
Fix tests. Add LICENSE
mdelmans Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Pull workflow

on:
pull_request:
branches:
- 'develop'

jobs:
run-tests:
if: true
runs-on: ubuntu-latest

steps:
- name: Print info
run: echo "Hello world"

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 'latest'

- name: Setup local venv
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
poetry run python --version

- name: Restore dependencies
id: restore-dependencies
uses: actions/cache/restore@v4
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
if: steps.restore-dependencies.outputs.cache-hit != 'true'
run: poetry install -vvv

- name: Cache dependencies
uses: actions/cache/save@v4
with:
path: ./.venv
key: ${{ steps.restore-dependencies.outputs.cache-primary-key }}

- name: Install project
run: poetry install --only-root

- name: Run tests
run: poetry run pytest --junitxml=junit/test-results.xml
env:
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}

- name: Publish test report
uses: mikepenz/action-junit-report@v5
if: always()
with:
report_paths: 'junit/test-results.xml'

- name: Run pre-commit
uses: pre-commit/action@v3.0.1
73 changes: 73 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Release workflow

on:
workflow_dispatch:
inputs:
version:
type: string
required: true
description: 'Version number to release in X.Y.Z format'
dry_run:
type: boolean
default: true
description: 'Dry run'
pull_request:
types:
- closed
branches:
- 'main'

jobs:
release_workflow:
runs-on: ubuntu-latest

steps:
- name: Gitflow action
id: gitflow-action
uses: hoangvvo/gitflow-workflow-action@0.3.7
with:
develop_branch: "develop"
main_branch: "main"
version: ${{ inputs.version }}
version_increment: ${{ contains(github.head_ref, 'hotfix/') && 'patch' || '' }}
dry_run: ${{ inputs.dry_run }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ steps.gitflow-action.outputs.release_branch || 'main' }}

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 'latest'

# Bumping version if we are in the 'create release PR mode'
- name: Bump version
if: ${{ steps.gitflow-action.outputs.release_branch }}
env:
VERSION: ${{ steps.gitflow-action.outputs.version }}
run: poetry version $VERSION

# Committing bumped version to the release branch
- name: Commit new version
if: ${{ steps.gitflow-action.outputs.release_branch }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Bump version to ${{ steps.gitflow-action.outputs.version }}"

# Building and publishing if we are in 'created new release mode'
- name: Build and publish package
if: ${{ !steps.gitflow-action.outputs.release_branch }}
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.egg-info
__pycache__
dist
site
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Colorifix

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Python Notion API

<img src="./docs/img/logo.webp" alt="Logo" width="100"/>

Python Notion API implements a client for talking with Notion API.

The key features of this implementation are:

* Async calls allowing you to send multiple requests at once
* [pydantic](https://docs.pydantic.dev/latest/) wrappers around Notion pages, properties and databases
3 changes: 3 additions & 0 deletions docs/api/async.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Async

::: python_notion_api.async_api
1 change: 1 addition & 0 deletions docs/api/sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: python_notion_api.sync_api.api
115 changes: 115 additions & 0 deletions docs/get_started/blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
## Retrieve a block

=== "Async"

```python
async def main():
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
block = await async_api.get_block(block_id='<BLOCK_ID>')
```

=== "Sync"

```python
api = NotionAPI(access_token='<NOTION_TOKEN>')
block = api.get_block(block_id='<BLOCK_ID>')
```

## Retrieve page blocks

=== "Async"

```python
async def main():
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
page = await async_api.get_page(page_id='<PAGE_ID>')
await for block in page.get_blocks():
...
```

=== "Sync"

```python
api = NotionAPI(access_token='<NOTION_TOKEN>')
page = api.get_page(page_id='<PAGE_ID>')

blocks = page.get_blocks()

for block in blocks:
...
```

## Get and add block children


=== "Async"

```python
async def main():
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
block = await async_api.get_block(block_id='<BLOCK_ID>')

p = ParagraphBlock(
rich_text=[RichTextObject.from_str("Some text to add through API")]
)
await block.add_child_block(content=[p])

block = await block.get_children_block()
```

=== "Sync"

```python
api = NotionAPI(access_token='<NOTION_TOKEN>')
block = api.get_block(block_id='<BLOCK_ID>')

p = ParagraphBlock(
rich_text=[RichTextObject.from_str("Some text to add through API")]
)
block.add_child_block(content=[p])

child_blocks = block.get_child_blocks()
```

## Update a block

All values must be updated at once.

=== "Async"

```python
from python_notion_api.models.blocks import ParagraphBlock

async def main():
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
block = await async_api.get_block(block_id='<BLOCK_ID>')

new_block = ParagraphBlock.from_obj({'object': 'block',
'type': 'paragraph',
'paragraph': {'rich_text': [
{'plain_text': 'Text here not used for some reason', 'type': 'text',
'text': {'content': 'This is the text that will be added', 'link': None}}]}
})

await block.set(new_block)
```

=== "Sync"


```python
from python_notion_api.models.blocks import ParagraphBlock

api = NotionAPI(access_token='<NOTION_TOKEN>')
block = api.get_block(block_id='<BLOCK_ID>')

new_block = ParagraphBlock.from_obj({'object': 'block',
'type': 'paragraph',
'paragraph': {'rich_text': [
{'plain_text': 'Text here not used for some reason', 'type': 'text',
'text': {'content': 'This is the text that will be added', 'link': None}}]}
})

block = api.get_block(block_id='<BLOCK_ID>')
block.set(new_block)
```
Loading
Loading