Skip to content

Commit 6804fe8

Browse files
Release 1.0.0
1 parent d01d134 commit 6804fe8

31 files changed

+2411
-2112
lines changed

.github/workflows/pull.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Pull workflow
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'develop'
7+
8+
jobs:
9+
run-tests:
10+
if: true
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Print info
15+
run: echo "Hello world"
16+
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.head_ref }}
21+
22+
- name: Install Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.11'
26+
27+
- name: Install Poetry
28+
uses: abatilo/actions-poetry@v2
29+
with:
30+
poetry-version: 'latest'
31+
32+
- name: Setup local venv
33+
run: |
34+
poetry config virtualenvs.create true --local
35+
poetry config virtualenvs.in-project true --local
36+
poetry run python --version
37+
38+
- name: Restore dependencies
39+
id: restore-dependencies
40+
uses: actions/cache/restore@v4
41+
with:
42+
path: ./.venv
43+
key: venv-${{ hashFiles('poetry.lock') }}
44+
45+
- name: Install dependencies
46+
if: steps.restore-dependencies.outputs.cache-hit != 'true'
47+
run: poetry install -vvv
48+
49+
- name: Cache dependencies
50+
uses: actions/cache/save@v4
51+
with:
52+
path: ./.venv
53+
key: ${{ steps.restore-dependencies.outputs.cache-primary-key }}
54+
55+
- name: Install project
56+
run: poetry install --only-root
57+
58+
- name: Run tests
59+
run: poetry run pytest --junitxml=junit/test-results.xml
60+
env:
61+
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
62+
63+
- name: Publish test report
64+
uses: mikepenz/action-junit-report@v5
65+
if: always()
66+
with:
67+
report_paths: 'junit/test-results.xml'
68+
69+
- name: Run pre-commit
70+
uses: pre-commit/[email protected]

.github/workflows/release.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Release workflow
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
type: string
8+
required: true
9+
description: 'Version number to release in X.Y.Z format'
10+
dry_run:
11+
type: boolean
12+
default: true
13+
description: 'Dry run'
14+
pull_request:
15+
types:
16+
- closed
17+
branches:
18+
- 'main'
19+
20+
jobs:
21+
release_workflow:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Gitflow action
26+
id: gitflow-action
27+
uses: hoangvvo/[email protected]
28+
with:
29+
develop_branch: "develop"
30+
main_branch: "main"
31+
version: ${{ inputs.version }}
32+
version_increment: ${{ contains(github.head_ref, 'hotfix/') && 'patch' || '' }}
33+
dry_run: ${{ inputs.dry_run }}
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
with:
40+
ref: ${{ steps.gitflow-action.outputs.release_branch || 'main' }}
41+
42+
- name: Install Python
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: '3.11'
46+
47+
- name: Install Poetry
48+
uses: abatilo/actions-poetry@v2
49+
with:
50+
poetry-version: 'latest'
51+
52+
# Bumping version if we are in the 'create release PR mode'
53+
- name: Bump version
54+
if: ${{ steps.gitflow-action.outputs.release_branch }}
55+
env:
56+
VERSION: ${{ steps.gitflow-action.outputs.version }}
57+
run: poetry version $VERSION
58+
59+
# Committing bumped version to the release branch
60+
- name: Commit new version
61+
if: ${{ steps.gitflow-action.outputs.release_branch }}
62+
uses: stefanzweifel/git-auto-commit-action@v5
63+
with:
64+
commit_message: "Bump version to ${{ steps.gitflow-action.outputs.version }}"
65+
66+
# Building and publishing if we are in 'created new release mode'
67+
- name: Build and publish package
68+
if: ${{ !steps.gitflow-action.outputs.release_branch }}
69+
env:
70+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
71+
run: |
72+
poetry config pypi-token.pypi $PYPI_TOKEN
73+
poetry publish --build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.egg-info
22
__pycache__
3+
dist
4+
site
5+
.DS_Store

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
## [1.0.0] - 2025/01/31
8+
9+
- First public release
10+
711
## [0.10.0] - 2024/12/20
812

913
### Added

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Colorifix
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Python Notion API
2+
3+
<img src="./docs/img/logo.webp" alt="Logo" width="100"/>
4+
5+
Python Notion API implements a client for talking with Notion API.
6+
7+
The key features of this implementation are:
8+
9+
* Async calls allowing you to send multiple requests at once
10+
* [pydantic](https://docs.pydantic.dev/latest/) wrappers around Notion pages, properties and databases

docs/api/async.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Async
2+
3+
::: python_notion_api.async_api

docs/api/sync.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: python_notion_api.sync_api.api

docs/get_started/blocks.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
## Retrieve a block
2+
3+
=== "Async"
4+
5+
```python
6+
async def main():
7+
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
8+
block = await async_api.get_block(block_id='<BLOCK_ID>')
9+
```
10+
11+
=== "Sync"
12+
13+
```python
14+
api = NotionAPI(access_token='<NOTION_TOKEN>')
15+
block = api.get_block(block_id='<BLOCK_ID>')
16+
```
17+
18+
## Retrieve page blocks
19+
20+
=== "Async"
21+
22+
```python
23+
async def main():
24+
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
25+
page = await async_api.get_page(page_id='<PAGE_ID>')
26+
await for block in page.get_blocks():
27+
...
28+
```
29+
30+
=== "Sync"
31+
32+
```python
33+
api = NotionAPI(access_token='<NOTION_TOKEN>')
34+
page = api.get_page(page_id='<PAGE_ID>')
35+
36+
blocks = page.get_blocks()
37+
38+
for block in blocks:
39+
...
40+
```
41+
42+
## Get and add block children
43+
44+
45+
=== "Async"
46+
47+
```python
48+
async def main():
49+
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
50+
block = await async_api.get_block(block_id='<BLOCK_ID>')
51+
52+
p = ParagraphBlock(
53+
rich_text=[RichTextObject.from_str("Some text to add through API")]
54+
)
55+
await block.add_child_block(content=[p])
56+
57+
block = await block.get_children_block()
58+
```
59+
60+
=== "Sync"
61+
62+
```python
63+
api = NotionAPI(access_token='<NOTION_TOKEN>')
64+
block = api.get_block(block_id='<BLOCK_ID>')
65+
66+
p = ParagraphBlock(
67+
rich_text=[RichTextObject.from_str("Some text to add through API")]
68+
)
69+
block.add_child_block(content=[p])
70+
71+
child_blocks = block.get_child_blocks()
72+
```
73+
74+
## Update a block
75+
76+
All values must be updated at once.
77+
78+
=== "Async"
79+
80+
```python
81+
from python_notion_api.models.blocks import ParagraphBlock
82+
83+
async def main():
84+
async_api = AsyncNotionAPI(access_token='<NOTION_TOKEN>')
85+
block = await async_api.get_block(block_id='<BLOCK_ID>')
86+
87+
new_block = ParagraphBlock.from_obj({'object': 'block',
88+
'type': 'paragraph',
89+
'paragraph': {'rich_text': [
90+
{'plain_text': 'Text here not used for some reason', 'type': 'text',
91+
'text': {'content': 'This is the text that will be added', 'link': None}}]}
92+
})
93+
94+
await block.set(new_block)
95+
```
96+
97+
=== "Sync"
98+
99+
100+
```python
101+
from python_notion_api.models.blocks import ParagraphBlock
102+
103+
api = NotionAPI(access_token='<NOTION_TOKEN>')
104+
block = api.get_block(block_id='<BLOCK_ID>')
105+
106+
new_block = ParagraphBlock.from_obj({'object': 'block',
107+
'type': 'paragraph',
108+
'paragraph': {'rich_text': [
109+
{'plain_text': 'Text here not used for some reason', 'type': 'text',
110+
'text': {'content': 'This is the text that will be added', 'link': None}}]}
111+
})
112+
113+
block = api.get_block(block_id='<BLOCK_ID>')
114+
block.set(new_block)
115+
```

0 commit comments

Comments
 (0)