No project description provided
Project description
CachedNotion 🔧
CachedNotion offers an enhanced, caching-enabled interface for interacting with Notion APIs. While it's a work in progress 🚧, its core functionality is fully operational, ensuring efficient and smooth integration.
What's New 🌟
- Critical Caching Issue Resolved: We've tackled a significant caching problem to ensure more reliable and faster access to your Notion data.
- Stay tuned for ongoing updates and improvements! 💼
Installation 📦
CachedNotion is currently available on TestPyPI. You can install it using either pip or Poetry.
Using pip
To install CachedNotion
using pip, run the following command:
pip install cached-notion
Using Poetry
For those using Poetry, you can add CachedNotion
to your project as follows:
poetry add cached-notion
New Feature: Notion to Markdown Conversion 📝
CachedNotion now offers an innovative feature to convert Notion pages into Markdown format. This is invaluable for users wanting to document, backup, or share their Notion content in a standardized format.
Function Overview
url_to_md
: Converts a Notion URL into a Markdown string. It handles nested content up to a specified depth, making it perfect for diverse documentation needs.id_to_md
: A complementary function tourl_to_md
, handling individual IDs and managing content depth.
Understanding Parameters
max_depth
: This parameter inurl_to_md
specifies the recursive depth for crawling through the Notion content. A value of-1
indicates no limit, ensuring a comprehensive conversion that includes all nested elements. Adjust this parameter to control how deep the function traverses through nested pages or blocks.subs
: Short for "sub-items," this parameter represents the remaining sub-items that are yet to be processed for further depths. It's crucial for managing and tracking the conversion process across nested levels of content.
Using url_to_md
Quickly convert any Notion page into Markdown:
from cached_notion.utils import url_to_md
# Initialize CachedClient
client = CachedClient(auth=os.environ["NOTION_TOKEN"], cache_delta=24)
# Convert a Notion URL to Markdown, specifying the depth of content to include
notion_url = "https://www.notion.so/xxx/xxx"
markdown_string, remaining_subs = url_to_md(client, notion_url, max_depth=-1)
# Markdown string is now ready, along with any remaining sub-items for further processing
print(markdown_string)
This function is especially useful for thorough documentation, platform exports, or content backups.
Using id_to_md
id_to_md
can also be used independently for tailored Markdown generation processes, providing flexibility and control over the depth and content of the conversion.
Basic Usage 📖
Effortlessly replace NotionClient
with CachedClient
for an optimized experience:
from cached_notion.cached_client import CachedClient
from cached_notion.utils import normalize_url, get_id_with_object_type
import os
# Initialize CachedClient with your Notion token and desired cache settings
client = CachedClient(auth=os.environ["NOTION_TOKEN"], cache_delta=24)
url = "https://www.notion.so/xxx/xxx"
normalized_url = normalize_url(url)
nid, object_type = get_id_with_object_type(normalized_url)
# Use CachedClient to interact with Notion by providing the Notion ID
page = client.pages.retrieve(nid)
database = client.databases.retrieve(nid)
block = client.blocks.retrieve(nid)
Utility Functions 🛠️
Maximize your productivity with these handy functions:
from cached_notion.cached_client import CachedClient
from cached_notion.utils import normalize_url, get_id_with_object_type, retrieve_object
import os
client = CachedClient(auth=os.environ["NOTION_TOKEN"], cache_delta=24)
# Normalize the URL and extract the Notion ID and object type
url = "https://www.notion.so/xxx/xxx"
normalized_url = normalize_url(url)
nid, object_type = get_id_with_object_type(normalized_url)
# Use the retrieve_object utility function to get the object from Notion
obj = retrieve_object(client, nid, object_type)
# Now you can work with the retrieved object
print(obj)
from cached_notion.cached_client import CachedClient
from cached_notion.utils import normalize_url, get_id_with_object_type, retrieve_all_content
import os
client = CachedClient(auth=os.environ["NOTION_TOKEN"], cache_delta=24)
# Normalize the URL and extract the Notion ID and object type
url = "https://www.notion.so/xxx/xxx"
normalized_url = normalize_url(url)
nid, object_type = get_id_with_object_type(normalized_url)
# Use the retrieve_all_content function to get the full content from Notion
full_content = retrieve_all_content(client, nid, object_type)
# Now you can work with the full content retrieved from Notion
print(full_content)
Enhanced Caching Strategy 💡
- Cache Delta Explained: Set
cache_delta
to manage how often the API calls the Notion API. A positive value uses cached content within the specified hours, reducing API calls. A zero value always fetches fresh content but minimizes API usage when used withretrieve_all_content
.
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
Built Distribution
Hashes for cached_notion-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6304a5c13cb7d1532d49bc330c686d8fb2ad3e7b5421c74e5956a472972771b2 |
|
MD5 | 12f1c0160b223ed352f25a71a169eb60 |
|
BLAKE2b-256 | f37be735532a97de28833a07b42b24acdd4e150ac8d3132f3a336d1bc611ceff |