Skip to content

Instantly share code, notes, and snippets.

@disler
Created May 14, 2023 14:23
Show Gist options
  • Save disler/9176c592876fbaf4f7bb2f5478db1864 to your computer and use it in GitHub Desktop.
Save disler/9176c592876fbaf4f7bb2f5478db1864 to your computer and use it in GitHub Desktop.
Notion - create a page then write content to the page
from notion_client import Client
from pprint import pprint
notion_token = '<your token>'
notion_page_id = '<your page id>'
def create_page(client, parent_page_id, title):
new_page = client.pages.create(
parent={
"page_id": parent_page_id
},
properties={
"title": {
"title": [
{
"type": "text",
"text": {
"content": title
}
}
]
}
}
)
return new_page
def write_text(client, page_id, text, type='paragraph'):
client.blocks.children.append(
block_id=page_id,
children=[{
"object": "block",
"type": type,
type: {
"rich_text": [{"type": "text", "text": {"content": text}}]
}
}]
)
def main():
client = Client(auth=notion_token)
new_page = create_page(client, notion_page_id, 'New Page: WOO!')
write_text(client, new_page['id'], 'Hello World!', 'to_do')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment