Notion API Master Series 01 - Settings

소찬 (Chan)·2022년 7월 12일
0


Hello. I'm QA Specialist Chan, the first time for the Notion API master series. This series will serialize every Monday.

Python Packages for Notion API

Currently, public APIs are two kinds of APIs.

Now we will use the official Notion API, notion-sdk-py. We can try to use the Unofficial package, but the official API is more convenient, and the official API method is the exact phrase. cf> Notion API Reference

Python, use IDLE(Integrated Development Environment) for the easiest way. I use PyCharm (Because I'm a big fan of Jetbrains)

Install Python Package

The first time, we need to install two kinds of packages, the official Notion API and dotenv. dotenv is to bring secret key safely. If you are a PyCharm user, search in Python Packages and notion-client and click the install button.
Create API Secret Key
Access My Integrations, and you can find the API menu
1. Select New API Integration
2. Fill Mandatory field and create
3. Click the created API item
4. Check the created secret key

Now bring this secret key via dotenv and save environment value. Use it.

Set dotenv value

if you installed dotenv successfully, you could launch dotenv
Now set the secret key into dotenv.
dotenv launch in the directory, which is available to launch Python.

  • dotenv set NOTION_TOKEN secret_xxxxxxxx
    Fill the API secret key in secret_xxxxxxx value
  • dotenv list
    Check the secret key correctly in dotenv

Bring the Notion Secret Key-value via Python

Bring the secret key value below the command line
and make the object type from notion_client package, you can be ready to use Notion API in Python.
from dotenv import dotenv_values
from notion_client import Client

config = dotenv_values(".env")
notion_secret = config.get('NOTION_TOKEN')
notion = Client(auth=notion_secret)
profile
QA Specialist

0개의 댓글