Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Last active July 19, 2023 18:26
Show Gist options
  • Save Cdaprod/e350c83a8d279ad6a3129800ca38d8df to your computer and use it in GitHub Desktop.
Save Cdaprod/e350c83a8d279ad6a3129800ca38d8df to your computer and use it in GitHub Desktop.
Langchain scripts to pull Notion data
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "89f29112",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"!pip install langchain"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0fdbe2dc",
"metadata": {},
"outputs": [],
"source": [
"# Cell 1: Import necessary libraries\n",
"from getpass import getpass\n",
"from langchain.document_loaders import NotionDBLoader\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f55d9631",
"metadata": {},
"outputs": [],
"source": [
"# Cell 2: Input your Notion integration token and database ID\n",
"#print(\"Enter your Notion Integration Token:\")\n",
"#NOTION_TOKEN = getpass() # This securely gets your input without showing it\n",
"\n",
"#print(\"\\\\nEnter your Notion Database ID:\")\n",
"#DATABASE_ID = getpass() # This securely gets your input without showing it\n",
"\n",
"NOTION_TOKEN = \"your_token_here\"\n",
"DATABASE_ID = \"your_database_id_here\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9101a84e",
"metadata": {},
"outputs": [],
"source": [
"# Cell 3: Create a loader object with the Notion integration token and database ID\n",
"loader = NotionDBLoader(\n",
" integration_token=NOTION_TOKEN,\n",
" database_id=DATABASE_ID,\n",
" request_timeout_sec=30, # optional, defaults to 10\n",
")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7c7a651",
"metadata": {},
"outputs": [],
"source": [
"# Cell 4: Load the documents from the Notion database\n",
"docs = loader.load()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12b3884b",
"metadata": {},
"outputs": [],
"source": [
"# Cell 5: Print the first document to check the result\n",
"print(docs[0])\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment