Skip to main content

A rust based python client for Notion's database

Project description

NotionDBRS 🦀

A high-performance Notion database client built with Rust and exposed to Python via PyO3. Handles bulk data operations efficiently with parallel processing.

Features

  • Rust-powered backend with Tokio async runtime for parallel operations
  • Smart data merging - only uploads new/changed records
  • Bulk operations - efficiently handle large datasets
  • Dynamic database creation - create Notion databases programmatically
  • Type-safe - comprehensive error handling across Python-Rust boundary

Installation

# from pypi
pip install notiondbrs
# Clone and build
git clone https://github.com/yourusername/notiondbrs.git
cd notiondbrs
chmod +x run.sh
./run.sh

Configuration

Create a .env file:

NOTION_TOKEN=your_notion_integration_token
DB_ID=your_database_id
PAGE_ID=your_page_id  # For creating new databases

Usage

Basic Setup

from notion_utils import NotionClient
import os
from dotenv import load_dotenv

load_dotenv()
client = NotionClient(os.environ.get("NOTION_TOKEN"))

List Databases

databases = client.get_all_databases()
for db_id, db_name in databases:
    print(f"{db_name}: {db_id}")

Get Data from Database

data = client.get_data_from_database("your-database-id")
print(f"Retrieved {len(next(iter(data.values())))} rows")
print(f"Columns: {list(data.keys())}")

Bulk Data Upload

import uuid
import random
import time

# Prepare data
upload_data = {
    "name": [f"Item_{i}" for i in range(1000)],
    "id": [str(uuid.uuid4()) for _ in range(1000)],
    "value": [str(random.randint(1, 1000)) for _ in range(1000)]
}

# Upload with timing
start_time = time.time()
client.insert_data(upload_data, "your-database-id")
duration = time.time() - start_time

print(f"Uploaded 1000 rows in {duration:.2f} seconds")
print(f"Throughput: {1000/duration:.0f} rows/second")

Smart Data Merging

# Only new records will be uploaded
merge_data = {
    "name": ["Existing_Item", "New_Item_1", "New_Item_2"],
    "id": ["existing-123", "new-456", "new-789"],
    "value": ["100", "200", "300"]
}

client.merge_data(merge_data, "your-database-id")

Create New Database

new_data = {
    "title": ["Entry 1", "Entry 2"],
    "status": ["Active", "Pending"],
    "date": ["2024-01-01", "2024-01-02"]
}

# Creates database and uploads data
client.insert_data(new_data, "your-page-id", new_db=True)

Performance

Typical performance on standard datasets:

Records Time
100 ~8s
1,000 ~30s
Data Retrieval <1s

Architecture

The Rust backend uses Tokio for async parallel processing while maintaining a simple Python interface:

# Python layer - simple and clean
client.insert_data(data, db_id)

# Rust layer handles:
# - Parallel HTTP requests
# - Memory-efficient data processing
# - Error handling and retries

Development

Project Structure

src/                 # Rust implementation
├── lib.rs          # PyO3 module
├── notion_class.rs # Python interface
├── notion_utils.rs # Core API logic
└── utils.rs        # Data processing

notiondbrs-py/      # Python wrapper
├── examples.py         # Usage examples
└── notion_utils.py # Python interface

Building

# Development build
maturin develop

# Release build (optimized)
maturin develop --release

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notiondbrs-0.1.1.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notiondbrs-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file notiondbrs-0.1.1.tar.gz.

File metadata

  • Download URL: notiondbrs-0.1.1.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for notiondbrs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3a5ffcaa1495cea3cfcc335469b9bb771abd94a81044eca897fbdc7c97deec20
MD5 534ecee2549a008a9ccdf23705959ab4
BLAKE2b-256 9e2fef4c1d524100ed5b59d44b8c7ec355dbeb86e786b84f2df04093ef2d557d

See more details on using hashes here.

File details

Details for the file notiondbrs-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for notiondbrs-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5d322cccc4b541ebbee4ee4ab0a38070910de28292799c87ada8276f1748f3f
MD5 363b753ffe5af4db3c0a07055fd29953
BLAKE2b-256 a040432caf3408c950ec26c34711c081fd09e44d21163dd86dd2d9dc3bb73d47

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page