A very easy-to-use Notion API
Project description
easyNotion API
English|简体中文
:muscle: Function Introduction
- 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.
:bangbang: Usage Limitations
- 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.
:wrench: Quick Start
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(database_id='database_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(col="column_name", content="column_content", update_col="update_column_name", update_content="new_value", isTitle=False)
# Delete data
res = db.delete(col="column_name", content="column_content")
# Close the session
db.closeSession()
Class: easyNotion
Constructor
def __init__(self, database_id, token)
- Initializes a new instance of the
easyNotion
class. - Parameters:
database_id
(str): The ID of the Notion database.token
(str): The API token used to access the Notion API.
Class Attributes
baseUrl
- Type: String
- Description: The base URL of the API.
database_id
- Type: String
- Description: The ID of the database.
headers
- Type: Dictionary
- Description: Request headers, including Accept, Notion-Version, Content-Type, Authorization, etc.
session
- Type:
requests.Session
object - Description: Session object used to send HTTP requests.
table
- Type: List
- Description: Processed data table containing all rows from the database.
Methods
getTableAll()
def getTableAll(self) -> dict
- Retrieves the raw data table from the Notion database.
- Returns:
- JSON object containing all raw data from the database.
getTable()
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
queryCol(col: str) -> list
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.
queryRow(col: str, content: str) -> dict
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
getRowCnt() -> int
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.
insert(data: dict)
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.
update(col: str, content: str, update_col: str, update_content: str, isTitle=False)
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 toTrue
if the column being updated is the title column.
- Returns:
- Response object of the API request.
delete(col: str, content: str)
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.
closeSession()
def closeSession(self)
- Closes the session used for API requests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
easyNotion-0.2.1.tar.gz
(15.1 kB
view details)
File details
Details for the file easyNotion-0.2.1.tar.gz
.
File metadata
- Download URL: easyNotion-0.2.1.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70b79b8ec886378e43998af1603718745798ba83322532adec8a2bc7051a8df0 |
|
MD5 | a3a029c4a3fb5d6ff7ea4ed677ccc554 |
|
BLAKE2b-256 | cdf5d6f5af7236c378bfe8238f48778f4c7b93c11d9c1e2c61c9241f4e25e429 |