English|简体中文
- A simpler and faster Notion API wrapper compared to other existing ones.
- Closes proxies when sending requests.
- Provides basic CRUD (Create, Read, Update, Delete) operations.
- Only applicable to Notion pages of type "Database - Full page".
- All column properties in the database, except the title column, must be of type "text".
- There is no asynchronous version available.
First, you need to obtain the Token and database_id for integrating with Notion. To learn how to obtain the Token, please refer to this link. To get the database_id, check the URL of the database page in the Notion documentation.
from easyNotion import easyNotion
db = easyNotion(notion_id='notion_id', token='token')
# Get the entire table (unprocessed)
table_all = db.getTableAll()
# Get the processed table
table = db.getTable()
# Query a specific column based on the column name
ret = db.queryCol(col="column_name")
# Query rows based on a specific column
row = db.queryRow(col="column_name", content="column_content")
# Get the total number of rows
row_count = db.getRowCnt()
# Insert data
data = {"title": "test_title", "column_name1": "value1", "column_name2": "value2"}
res = db.insert(data=data)
# Update data
res = db.update(,
# Delete data
res = db.delete()
# Close the session
db.closeSession()def __init__(self, database_id, token)- Initializes a new instance of the
easyNotionclass. - Parameters:
database_id(str): The ID of the Notion database.token(str): The API token used to access the Notion API.
- Type: String
- Description: The base URL of the API.
- Type: String
- Description: The ID of the database.
- Type: Dictionary
- Description: Request headers, including Accept, Notion-Version, Content-Type, Authorization, etc.
- Type:
requests.Sessionobject - Description: Session object used to send HTTP requests.
- Type: List
- Description: Processed data table containing all rows from the database.
def getTableAll(self) -> dict- Retrieves the raw data table from the Notion database.
- Returns:
- JSON object containing all raw data from the database.
def getTable(self) -> list- Retrieves the processed data table from the Notion database.
- Returns:
- List of dictionaries representing the processed data table.
- Note:
- This method internally calls
getTableAll()to retrieve the raw data and process it to obtain the final data table.
- This method internally calls
def queryCol(self, col: str) -> list- Queries a specific column in the data table and returns its values.
- Parameters:
col(str): Name of the column to query.
- Returns:
- List of strings containing the values in the specified column.
def queryRow(self, col: str, content: str) -> dict- Queries a row in the data table based on a specific column and its content.
- Parameters:
col(str): Name of the column to search.content(str): Value to search in the specified column.
- Returns:
- Dictionary representing the raw data of the matching row.
- Note:
- If no matching row is found, an empty dictionary
{}is returned.
- If no matching row is found, an empty dictionary
def getRowCnt(self) -> int- Retrieves the total number of rows in the data table.
- Returns:
- Integer representing the total number of rows in the table.
def insert(self, data: dict)- Inserts data into the Notion database.
- Parameters:
data(dict): Data to insert. The first value in the dictionary must correspond to the value of the "title" column.
- Returns:
- Response object of the API request.
def update(self, col: str, content: str, update_col: str, update_content: str, isTitle=False)- Updates a specific column of a row in the data table.
- Parameters:
col(str): Column used to identify the row.content(str): Content of the specified column used to identify the row.update_col(str): Name of the column to update.update_content(str): New content to update in the specified column.isTitle(bool): Indicates whether the specified column is the title column. Default isFalse. Set toTrueif the column being updated is the title column.
- Returns:
- Response object of the API request.
def delete(self, col: str, content: str)- Deletes a row from the data table based on a specific column and its content.
- Parameters:
col(str): Name of the column to delete.content(str): Value that identifies the row to delete in the specified column.
- Returns:
- Response object of the API request.
def closeSession(self)- Closes the session used for API requests.
