Skip to main content

A Python library for syncing and managing Pinboard bookmarks

Project description

pinboard-tools

PyPI version Python versions License

A Python library for syncing and managing Pinboard bookmarks.

Features

  • Efficient incremental sync with Pinboard.in API
  • SQLite database for local bookmark storage
  • Tag analysis and similarity detection
  • Smart conflict resolution for sync operations
  • Rate limiting and optimized API usage
  • Chunking utilities for LLM processing

Installation

pip install pinboard-tools

Quick Start

from pinboard_tools import (
    init_database,
    get_session,
    BidirectionalSync,
)

# Initialize database
init_database("bookmarks.db")

# Create sync engine
db = get_session()
sync = BidirectionalSync(db=db, api_token="your-pinboard-api-token")

# Perform efficient incremental sync
stats = sync.sync()
print(f"Local to remote: {stats['local_to_remote']}")
print(f"Remote to local: {stats['remote_to_local']}")
print(f"Conflicts resolved: {stats['conflicts_resolved']}")

Core Components

Database Models

  • Bookmark - Bookmark entity with all Pinboard fields
  • Tag - Tag entity with normalization
  • BookmarkTag - Many-to-many relationship
  • SyncStatus - Track sync state

Sync Engine

  • PinboardAPI - API client with rate limiting and incremental fetching
  • BidirectionalSync - Efficient incremental sync with conflict resolution
  • upsert_pinboard_post - Mirror a Pinboard API post into the local database

Tag Analysis

  • TagSimilarityDetector - Find similar tags
  • TagConsolidator - Merge duplicate tags

Utilities

  • chunk_bookmarks_for_llm - Prepare data for LLM processing
  • DateTime helpers for Pinboard format

Database Schema

The library uses a normalized SQLite schema:

-- See schema.sql for complete structure
bookmarks (url, title, description, tags, time, ...)
tags (name, normalized_name)
bookmark_tags (bookmark_id, tag_id)
sync_status (last_sync, last_update)

API Reference

Initialization

# Initialize database with schema
init_database(db_path: str)

# Get database session
with get_session() as session:
    # Use session for queries

Syncing

# Create sync client  
sync = BidirectionalSync(db=session, api_token="your-token")

# Efficient incremental sync (only fetches changed bookmarks)
stats = sync.sync()

# Sync only local changes to remote
stats = sync.sync(direction=SyncDirection.LOCAL_TO_REMOTE)

# Sync only remote changes to local
stats = sync.sync(direction=SyncDirection.REMOTE_TO_LOCAL)

Local mirroring

Use upsert_pinboard_post when another application has already written a bookmark to Pinboard and wants to keep the local SQLite database in step without running a full sync:

from pinboard_tools import PinboardAPI, get_session, init_database, upsert_pinboard_post

init_database("bookmarks.db")
db = get_session()
api = PinboardAPI("your-token")

api.add_post(
    url="https://example.com",
    description="Example",
    extended="A useful example.",
    tags="examples docs",
)
posts = api.get_post(url="https://example.com")
if posts:
    upsert_pinboard_post(db, posts[0])

The mirrored bookmark is marked synced, tags are normalized through the same tag tables as sync, and last_synced_at is updated.

Tag Analysis

# Find similar tags
detector = TagSimilarityDetector(session)
similar_groups = detector.find_similar_tags(threshold=0.8)

# Consolidate tags
consolidator = TagConsolidator(session)
consolidator.consolidate_tags(old_tag="python3", new_tag="python")

License

Apache License 2.0 - see LICENSE file for details

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

pinboard_tools-0.1.10.tar.gz (93.8 kB view details)

Uploaded Source

Built Distribution

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

pinboard_tools-0.1.10-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file pinboard_tools-0.1.10.tar.gz.

File metadata

  • Download URL: pinboard_tools-0.1.10.tar.gz
  • Upload date:
  • Size: 93.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pinboard_tools-0.1.10.tar.gz
Algorithm Hash digest
SHA256 2c958bded2b94b3229cd8556227693af6851120f3e99227ca06b41a804ea4c07
MD5 bfb70de46403aebe3a920b684c9cc9c9
BLAKE2b-256 eeaebf1d44ba14adfe7d6f60283642d2fb3d4a0f403d9e8ce7a30e6988d2582d

See more details on using hashes here.

File details

Details for the file pinboard_tools-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for pinboard_tools-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 377a4259ce416f2576f8bd233c82c0fb813e1815d2113c0d5891ab92d196f4f0
MD5 f4a8a8bd31584b64897437604793ae95
BLAKE2b-256 a0e301b1843bb62206863501148aaa343f71568834523c4a4b0c27d121e6427a

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