Notion API in 5 Minutes: How to Read Notion Databases in Python

IndyDevDan · Beginner ·🔧 Backend Engineering ·3y ago

Key Takeaways

This video demonstrates how to read from Notion databases in Python using the Notion API, covering authentication, database creation, and data retrieval.

Full Transcript

foreign welcome to another video in this video we're learning how we can read from notion databases all the code that we have now has been written in our previous three tutorials where we learned how to authenticate write and read from into an ocean databases so if you haven't checked those out definitely do so let's get started I'm going to set the five minute timer and Jump Right In first things first let's create a database we're going to create an inline database and we're going to call this website Analytics great let's change the rows a little bit or the columns uh we'll call this user ID we'll call this event and then we'll change the type to a select field and we'll add one more date column and we'll just call that date that that's perfect all right so let's add a couple rows I'm going to use my handy bash uid function here to add a couple IDs you would think that when these events come in they'll come in as uuids we're going to create a visitor event and a sign up event and we're just going to put some dates in here so whatever shows up is great and then we're going to delete this last row excellent so next thing you need to do is get your notion database ID so we're going to come in and copy the link we're going to create a new variable notion database ID equals and when you paste this link your ID is going to be the first uuid after the slash so we're going to grab that and jump into our code so first thing we want to do is read the information from our database so let's go ahead and do that we'll call this DB info equals client.databases.retrieve excellent yeah so GitHub copilot knows exactly what we want here if you're not using GitHub copilot definitely hop on the AI train it is here it's here to stay Engineers using it are going to be better off let's write to reuse our right dict to file as Json function and let's go ahead and see the output of this function so let's check out our DB info.json let's prettify this and as you can see we have all the information from our website analytics minus our actual rows so this is just giving metadata about the database itself so let's go ahead and learn how to read the rows the first thing we need is a function that will help us safely get nested properties from complex objects so I'm just going to paste this function and this will be you know all the code all the information you need to get this running will be in the description but basically this allows us to run functions like this to get information out all right so let's go ahead and get our rows DB rows perfect equals client databases query and now that we have our rows we can write our rows to a dictionary and now we're going to Loop through our rows for row and DB rows results let's get rid of the prints let's get rid of the ID we want our user ID we want our event and then let's create one more we want our date right we will put these all in a list we'll call these simple rows it will append all these items and then after we do this we're going to dump out our simple rows to a Json file we're going to comment this code up for now so that we can see the structure of the database row so let's go ahead and run this and look at DB rows format and as you can see we have this results key value pair that's an array which contains properties in each one of these properties we have a nested selection of keys that we need to access which is why we imported that safe git method so let's go ahead and run properties.event select dot name this is how we're going to obtain our event so let's go ahead and uncomment this code and repeat for each type so let's go ahead and paste that in so that's how we get our event and let's go ahead and continue we're running out of time here so it's going to be properties dot date.date.start let's paste that in our date one more let's run properties dot user id.title dot zero dot plain text just as we're running out of time let's go ahead and paste that in and let's run and see what we get all right so let's look at our simple rows.json file that was created let's pretty print and as you can see guys we have our rows as Json so as you can see each row aligns with a row in our database thanks so much for tuning in I hope this video was helpful if I went too fast feel free to stop at any point all the code all the links are going to be in the description we just learned how to read from the ocean databases five minutes so I'll see you guys in the next video where we learn how to write to notion databases peace

Original Description

Grab the source code: https://danisler.com/dev/notion-in-5-minutes ✅ Not sure how to get started? Watch the auth, write, and read videos here. Notion Authenticate: https://youtu.be/KyllgpvQFuI Notion Write: https://youtu.be/KENSTonsiEc Notion Read: https://youtu.be/GSPpYqBgIko 💻 Documentation Get the code: https://danisler.com/dev/notion-in-5-minutes Notion Developer Documentation: https://developers.notion.com/ Python Library: https://github.com/ramnes/notion-sdk-py 🗣 Convert your notion pages to lifelike speech: https://subvolver.com ⏳ Manage your time your way: https://timeva.app #️⃣ Hashtags #notion #notionapi #api
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from IndyDevDan · IndyDevDan · 33 of 60

1 Senior developer codes ENTIRE electron app in 30 days (not for beginners)
Senior developer codes ENTIRE electron app in 30 days (not for beginners)
IndyDevDan
2 How I code custom components with vue.js, electron and GitHub Copilot (ASMR)
How I code custom components with vue.js, electron and GitHub Copilot (ASMR)
IndyDevDan
3 Coding a progress bar using vue.js, progressbar.js, pinia, and electron
Coding a progress bar using vue.js, progressbar.js, pinia, and electron
IndyDevDan
4 Vue + Electron settings menu and switch component wrapper (GitHub Copilot FTW)
Vue + Electron settings menu and switch component wrapper (GitHub Copilot FTW)
IndyDevDan
5 Zen mode, Hot keys, and circle progress bar in vue.js
Zen mode, Hot keys, and circle progress bar in vue.js
IndyDevDan
6 Coding picker components in vue.js for TIMEVA customizability.
Coding picker components in vue.js for TIMEVA customizability.
IndyDevDan
7 Coding a micro mode progress bar in vue.js on the balcony like a proper digital nomad.
Coding a micro mode progress bar in vue.js on the balcony like a proper digital nomad.
IndyDevDan
8 How to use dynamic css variables to create custom color themes for Timeva.
How to use dynamic css variables to create custom color themes for Timeva.
IndyDevDan
9 Building a minimal account page for my electron + vue.js app
Building a minimal account page for my electron + vue.js app
IndyDevDan
10 This is the final devlog
This is the final devlog
IndyDevDan
11 How to build and launch your next app in 30 days
How to build and launch your next app in 30 days
IndyDevDan
12 Learn Pinia in 10 MINUTES (Vue.js 3)
Learn Pinia in 10 MINUTES (Vue.js 3)
IndyDevDan
13 Learn Tailwind CSS by making a Cheatsheet | (30 Key CSS Properties)
Learn Tailwind CSS by making a Cheatsheet | (30 Key CSS Properties)
IndyDevDan
14 GitHub Copilot being hella useful when coding Electron + Vue.js app
GitHub Copilot being hella useful when coding Electron + Vue.js app
IndyDevDan
15 Vue Animations in 3 Lines of Code. (VueUse Motion)
Vue Animations in 3 Lines of Code. (VueUse Motion)
IndyDevDan
16 How to use VCCode Macros for Insane Developer Productivity (5x, 10x, 25x, 100x gains)
How to use VCCode Macros for Insane Developer Productivity (5x, 10x, 25x, 100x gains)
IndyDevDan
17 Is It Hype? Senior Engineer Learns GraphQL, Rages and Complains About Docs (RAW TAKE - Part 1)
Is It Hype? Senior Engineer Learns GraphQL, Rages and Complains About Docs (RAW TAKE - Part 1)
IndyDevDan
18 Is it Hype? Learn GraphQL by building an Express + GraphQL App (Part 2)
Is it Hype? Learn GraphQL by building an Express + GraphQL App (Part 2)
IndyDevDan
19 So you have an idea for an app. What's next? (3 Actions You Can Take Now)
So you have an idea for an app. What's next? (3 Actions You Can Take Now)
IndyDevDan
20 Coding Vue.js Components, Hooks, and Pinia State for Timeva v2
Coding Vue.js Components, Hooks, and Pinia State for Timeva v2
IndyDevDan
21 Coding Pomodoro Chaining (Vue.js, Electron, Pinia)
Coding Pomodoro Chaining (Vue.js, Electron, Pinia)
IndyDevDan
22 Programming Pomodoro Chaining PART 2 (Vue 3 Hooks Have Changed Me)
Programming Pomodoro Chaining PART 2 (Vue 3 Hooks Have Changed Me)
IndyDevDan
23 Chill Vue.js 3 Coding (Pom Chaining Part 3)
Chill Vue.js 3 Coding (Pom Chaining Part 3)
IndyDevDan
24 Senior Engineer Codes New App Feature With Vue.js, Copilot, Electron and TS.
Senior Engineer Codes New App Feature With Vue.js, Copilot, Electron and TS.
IndyDevDan
25 Is It Hype? Github Copilot (The Future of Programming)
Is It Hype? Github Copilot (The Future of Programming)
IndyDevDan
26 Achieving Balance as Engineers who want more from life (Raw Discussion)
Achieving Balance as Engineers who want more from life (Raw Discussion)
IndyDevDan
27 Indie Hackers Most Important Resource: RUNWAY
Indie Hackers Most Important Resource: RUNWAY
IndyDevDan
28 Timeva V2 - Customizable Productivity Timer For The Digital Age
Timeva V2 - Customizable Productivity Timer For The Digital Age
IndyDevDan
29 Notion API In 5 Minutes: Authentication (Python)
Notion API In 5 Minutes: Authentication (Python)
IndyDevDan
30 Notion API in 5 Minutes: Write (Python)
Notion API in 5 Minutes: Write (Python)
IndyDevDan
31 Notion API in 5 Minutes: Read (Python | Copilot)
Notion API in 5 Minutes: Read (Python | Copilot)
IndyDevDan
32 The AI Wave: 3 Years 3 Predictions 3 Actions (ChatGPT will be a Joke)
The AI Wave: 3 Years 3 Predictions 3 Actions (ChatGPT will be a Joke)
IndyDevDan
Notion API in 5 Minutes: How to Read Notion Databases in Python
Notion API in 5 Minutes: How to Read Notion Databases in Python
IndyDevDan
34 Notion API In 5 Minutes - Database Write (Add new rows in Python)
Notion API In 5 Minutes - Database Write (Add new rows in Python)
IndyDevDan
35 Automate Everything: Using The Notion API to automate tweets. Let’s Code
Automate Everything: Using The Notion API to automate tweets. Let’s Code
IndyDevDan
36 Going Serverless: Using Vercel Functions for our Notion Twitter App
Going Serverless: Using Vercel Functions for our Notion Twitter App
IndyDevDan
37 Serverless Cron Jobs: Automatically Run Your Serverless Functions With QStash And Vercel
Serverless Cron Jobs: Automatically Run Your Serverless Functions With QStash And Vercel
IndyDevDan
38 Let’s Break The Internet: ChatGPT API + Notion Infinite Tweet Generator
Let’s Break The Internet: ChatGPT API + Notion Infinite Tweet Generator
IndyDevDan
39 Survive the AI age: Managing AI generated content with Notion, Python, Vercel, and Cron.
Survive the AI age: Managing AI generated content with Notion, Python, Vercel, and Cron.
IndyDevDan
40 The AI Engineer: The Future of Programming
The AI Engineer: The Future of Programming
IndyDevDan
41 Master Disruption: How Top AI Engineers Will Dominate the GPT-X Era
Master Disruption: How Top AI Engineers Will Dominate the GPT-X Era
IndyDevDan
42 FFmpeg, GPT-4 & WhisperX: Convert Horizontal Videos to Vertical (97% AI)
FFmpeg, GPT-4 & WhisperX: Convert Horizontal Videos to Vertical (97% AI)
IndyDevDan
43 Why Use LangChain? A Blunt Overview for Advanced Engineers
Why Use LangChain? A Blunt Overview for Advanced Engineers
IndyDevDan
44 Nuxt + Vercel KV: Coding an AI Agent Network MVP (flow state devLog)
Nuxt + Vercel KV: Coding an AI Agent Network MVP (flow state devLog)
IndyDevDan
45 Build VueJS Components While You Sleep: First LLM Agent Network (V2)
Build VueJS Components While You Sleep: First LLM Agent Network (V2)
IndyDevDan
46 My Top 6 Modern Vue.js VSCode Snippets
My Top 6 Modern Vue.js VSCode Snippets
IndyDevDan
47 useComposable - Vue.js Composable Generator (GCP + Serverless + LLM)
useComposable - Vue.js Composable Generator (GCP + Serverless + LLM)
IndyDevDan
48 Let's Get Fired: Using AI Coding Assistant AIDER to do my Engineering Job
Let's Get Fired: Using AI Coding Assistant AIDER to do my Engineering Job
IndyDevDan
49 Writing code without coding - Browser TTS with AIDER (ASMR DEVLOG)
Writing code without coding - Browser TTS with AIDER (ASMR DEVLOG)
IndyDevDan
50 Learn Anything With AI: HTMX - FLASK - AIDER (asmr devlog)
Learn Anything With AI: HTMX - FLASK - AIDER (asmr devlog)
IndyDevDan
51 Advanced Prompt Engineering Techniques for FRONT-END Engineers
Advanced Prompt Engineering Techniques for FRONT-END Engineers
IndyDevDan
52 I'm DONE writing tests - using AI copilot AIDER to AUTOMATE testing.
I'm DONE writing tests - using AI copilot AIDER to AUTOMATE testing.
IndyDevDan
53 pip install YOUR-PACKAGE: Building your first python with Poetry, AIDER, and ChatGPT
pip install YOUR-PACKAGE: Building your first python with Poetry, AIDER, and ChatGPT
IndyDevDan
54 Git + AI = DIFFBRO: AI Coding the future of code reviews (python, aider, gpt-4)
Git + AI = DIFFBRO: AI Coding the future of code reviews (python, aider, gpt-4)
IndyDevDan
55 AI Devlog: Coding an AI powered, Code Review, CLI tool | Python, Aider,  ChatGPT
AI Devlog: Coding an AI powered, Code Review, CLI tool | Python, Aider, ChatGPT
IndyDevDan
56 Introducing DIFFBRO - Your AI powered PEER REVIEWS in one command
Introducing DIFFBRO - Your AI powered PEER REVIEWS in one command
IndyDevDan
57 ONE Word Prompts - 3 INSTANTLY useful Prompt Engineering Techniques
ONE Word Prompts - 3 INSTANTLY useful Prompt Engineering Techniques
IndyDevDan
58 The Javascript Ecosystem Killer: Using Bun, to Learn Bun (with AIDER)
The Javascript Ecosystem Killer: Using Bun, to Learn Bun (with AIDER)
IndyDevDan
59 "With this prompt, I learned Pytest in 12 minutes" - Learn ANYTHING with LLMs
"With this prompt, I learned Pytest in 12 minutes" - Learn ANYTHING with LLMs
IndyDevDan
60 Prompt Engineering an ENTIRE codebase: Postgres Data Analytics AI Agent
Prompt Engineering an ENTIRE codebase: Postgres Data Analytics AI Agent
IndyDevDan

This video teaches how to read from Notion databases in Python using the Notion API, covering authentication, database creation, and data retrieval. The video provides a step-by-step guide on how to use the Notion API to retrieve data from Notion databases and store it in a JSON file.

Key Takeaways
  1. Create a Notion database
  2. Get the Notion database ID
  3. Use the Notion API to read database information
  4. Use the Notion API to read database rows
  5. Store the retrieved data in a JSON file
💡 The Notion API can be used to read data from Notion databases and store it in a JSON file, allowing for easy integration with other tools and services.

Related AI Lessons

Up next
This Cop Was Held Accountable For His Brutality! #police #lawyer
Hampton Law
Watch →