Skip to main content

Add your description here

Project description

NotionHelper

NotionHelper

NotionHelper is a Python library that provides a convenient interface for interacting with the Notion API. It simplifies common tasks such as managing databases, pages, and file uploads, allowing you to integrate Notion's powerful features into your applications with ease.

For help constructing the JSON for the properties, use the Notion API - JSON Builder Streamlit app.

Features

  • Synchronous Operations: Uses notion-client and requests for straightforward API interactions.
  • Database Management: Create, query, and retrieve Notion databases.
  • Page Operations: Add new pages to databases and append content to existing pages.
  • File Handling: Upload files and attach them to pages or page properties.
  • Pandas Integration: Convert Notion database pages into a Pandas DataFrame for easy data manipulation.

Installation

To install NotionHelper, you can use pip:

pip install notionhelper

This will also install all the necessary dependencies, including notion-client, pandas, and requests.

Authentication

To use the Notion API, you need to create an integration and obtain an integration token.

  1. Create an Integration: Go to My Integrations and create a new integration.
  2. Get the Token: Copy the "Internal Integration Token".
  3. Share with a Page/Database: For your integration to access a page or database, you must share it with your integration from the "Share" menu in Notion.

It is recommended to store your Notion token as an environment variable for security.

export NOTION_TOKEN="your_secret_token"

Usage

Here is an example of how to use the library:

import os
from notionhelper import NotionHelper

Initialize the NotionHelper class

notion_token = os.getenv("NOTION_TOKEN")

helper = NotionHelper(notion_token)

Retrieve a Database

database_id = "your_database_id"
database_schema = helper.get_database(database_id)
print(database_schema)

Create a New Page in a Database

page_properties = {
    "Name": {
        "title": [
            {
                "text": {
                    "content": "New Page from NotionHelper"
                }
            }
        ]
    }
}
new_page = helper.new_page_to_db(database_id, page_properties)
print(new_page)

Append Content to the New Page

blocks = [
    {
        "object": "block",
        "type": "heading_2",
        "heading_2": {
            "rich_text": [{"type": "text", "text": {"content": "Hello from NotionHelper!"}}]
        }
    },
    {
        "object": "block",
        "type": "paragraph",
        "paragraph": {
            "rich_text": [
                {
                    "type": "text",
                    "text": {
                        "content": "This content was appended synchronously."
                    }
                }
            ]
        }
    }
]
helper.append_page_body(page_id, blocks)
print(f"Successfully appended content to page ID: {page_id}")

Get all pages as a Pandas DataFrame

  df = helper.get_all_pages_as_dataframe(database_id)
  print(df.head())

Upload a File and Attach to a Page

file_path = "path/to/your/file.pdf"  # Replace with your file path
upload_response = helper.upload_file(file_path)
file_upload_id = upload_response["id"]
# Replace with your page_id
page_id = "your_page_id"
attach_response = helper.attach_file_to_page(page_id, file_upload_id)
print(f"Successfully uploaded and attached file: {attach_response}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notionhelper-0.1.1.tar.gz (4.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notionhelper-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file notionhelper-0.1.1.tar.gz.

File metadata

  • Download URL: notionhelper-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.14

File hashes

Hashes for notionhelper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d85b050832a72957b883b48dc67ef2ce6b86fe3d66784c7a65e1051347a0592d
MD5 8d0a5bcd208ccae58f949474f5b077fe
BLAKE2b-256 391123e2df593bd5dc4feb883b995920c685c34f61bb643bd3b8825dec3c5dd0

See more details on using hashes here.

File details

Details for the file notionhelper-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for notionhelper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a9beb37478bda4e83fa5ad58a9cce9990c9c5af297589161879b6396c5a5b47
MD5 113d1b074da1d6dd8d7b62b3eccc9de3
BLAKE2b-256 735769f6a3e76a92b585c49eca613b898a5f349422b6b4a9bcde4380c5379bc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page