Convert Markdown to Notion blocks
Project description
notion-blockify
notion-blockify is a Python library that converts Markdown into Notion API–compatible block structures.
Installation
pip install notion-blockify
Usage
from notion_blockify import Blockizer
markdown = """
# Heading 1
This is paragraph.
"""
blocks = Blockizer().convert(markdown)
Supported Blocks
Headings
# Heading 1
## Heading 2
### Heading 3
Lists
Note: The block that allows children is limited to a maximum of two levels of nesting by the Notion API.
bulleted list
- bulleted list 1
- bulleted list 2
- bulleted list 3
numbered list
1. numbered list 1
1. numbered list 2
1. numbered list 3
Table
| Col1 | Col2 | Col3 |
|------|------|------|
| A | B | C |
Quote
> Quote
Code
```cpp
#include <iostream>
using namespace std;
int main() {
cout<<"hello world"<<endl;
return 0;
}
```
```python
print('hello')
```
```
plain text
```
Horizontal Line
---
Image

If an <img> tag is used on its own or wrapped inside a <figure> tag, it will be converted into an image block. If a <figcaption> tag is present inside the <figure>, its content will be added below the image in italic.
<img src="image url">
<figure>
<img src="image url">
</figure>
<figure>
<img src="image url">
<figcaption>caption text</figcaption>
</figure>
Latex
$$ E = mc^2 $$
TODO
[x] checked
[] not checked
[ ] not checked
Text Style
bold
**bold**
__bold__
italic
*italic*
_italic_
strikethrough
~~strikethrough~~
code
`code`
Examples
If you are using the notion-client library, you can create a page.
Note: The Notion API does not allow more than 100 blocks in a single request. Exceeding this limit will result in an error.
If you need to add more than 100 blocks, split them into multiple requests and append them sequentially to the same parent block or page.
Create a page in a Notion page
import os
from notion_blockify import Blockizer
from notion_client import Client
with open('example.md', 'r') as f:
text = f.read()
blocks = Blockizer().convert(text)
notion = Client(auth=os.environ["NOTION_API_KEY"])
my_page = notion.pages.create(
**{
"parent": {"page_id": NOTION_PAGE_ID},
"properties: {"title": [{"text": {"content": PAGE_TITLE}}]},
"children": blocks
}
)
Create a page in a Notion database
import os
from notion_blockify import Blockizer
from notion_client import Client
with open('example.md', 'r') as f:
text = f.read()
blocks = Blockizer().convert(text)
notion = Client(auth=os.environ["NOTION_API_KEY"])
my_page = notion.pages.create(
**{
"parent": {"page_id": NOTION_DATABASE_ID},
"properties: {
"Name": {
"title": [
{"text": {"content": PAGE_TITLE}}
]
},
"Food group": {"select": {"name": "Vegetable"}},
"Price": {"number": 2.5},
},
"children": blocks
}
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notion_blockify-0.1.1.tar.gz.
File metadata
- Download URL: notion_blockify-0.1.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eda722f24762b41585c695cbc0fad76af81815213537dbdb440532547add1b8
|
|
| MD5 |
4f14164b169e7633d30f341287bcf02d
|
|
| BLAKE2b-256 |
ce10b26916cfd9355a33bc5f913c549024a30f273ec4533e9f72e0be99669fa4
|
File details
Details for the file notion_blockify-0.1.1-py3-none-any.whl.
File metadata
- Download URL: notion_blockify-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cd1b685bbb307a1c1c02754d582ca61b4529f9e617f86dd34489c33a1cc4a12
|
|
| MD5 |
5b3c6eaef93183f979a27d57e32d6ecf
|
|
| BLAKE2b-256 |
7807a89908cebcbbf45bbf4f75735ae136da4050dd27740e4e85f1b68d3fc3eb
|