Skip to main content

SDK for interacting with Cursor editor's local SQLite usage data database

Project description

CursorData SDK

Tests Python Version License Codecov

⚠️ Disclaimer: This is an unofficial project not connected with or endorsed by AnySphere (Cursor). This SDK is developed independently and provided as-is. Use at your own risk. The Cursor editor and its database structure are property of AnySphere.

A well-documented Python SDK for interacting with the local SQLite database that contains all Cursor editor usage data on your computer.

Features

  • 🔍 Strongly Typed: Full type hints and dataclasses for all data models
  • 📊 Comprehensive Access: Query AI code tracking, composer sessions, bubble conversations, and more
  • 🎯 Platform Support: Automatically detects database location on macOS, Windows, and Linux
  • 📚 Well Documented: Auto-generated API documentation with Sphinx
  • 🔒 Type Safe: Full mypy type checking support

Installation

pip install cursordata-sdk

Or using uv:

uv pip install cursordata-sdk

Quick Start

from cursordata import CursorDataClient
from datetime import datetime, timedelta

# Initialize the client (automatically finds the database)
with CursorDataClient() as client:
    # Get usage statistics
    stats = client.get_usage_stats()
    print(f"Total tracking entries: {stats.total_tracking_entries}")
    print(f"Total scored commits: {stats.total_scored_commits}")
    print(f"Composer sessions: {stats.composer_sessions}")
    
    # Query data using the query builder (primary API)
    # Get recent bubbles with code changes
    week_ago = datetime.now() - timedelta(days=7)
    bubbles = (
        client.query()
        .bubbles()
        .where(created_after=week_ago, has_code_blocks=True)
        .limit(10)
        .execute()
    )
    print(f"Found {len(bubbles)} recent bubbles with code changes")
    
    # Get composer sessions for Python files
    sessions = (
        client.query()
        .composer_sessions()
        .where(file_extension=".py")
        .execute()
    )
    for session in sessions:
        print(f"Session {session.composer_id}: {session.entries_count} entries")
        print(f"  Files: {len(session.files_modified)}")
        print(f"  Extensions: {', '.join(session.file_extensions)}")
    
    # Get database info
    info = client.get_database_info()
    print(f"Database path: {info.path}")
    print(f"ItemTable entries: {info.item_table_count}")
    print(f"CursorDiskKV entries: {info.cursor_disk_kv_count}")

Data Models

The SDK provides strongly-typed data models:

UsageStats

Aggregated usage statistics including total tracking entries, scored commits, and file extension usage.

AICodeTrackingEntry

Individual AI code tracking entries with metadata about source, composer ID, file extension, and file name.

ComposerSession

Composer sessions grouped by session ID with associated files and code entries.

BubbleConversation

Bubble conversations stored in the database.

DatabaseInfo

Information about the database file including counts and last modified time.

API Reference

See the full API documentation (generated with Sphinx) for detailed information about all classes and methods.

Examples

Analyzing File Extension Usage

from cursordata import CursorDataClient

with CursorDataClient() as client:
    stats = client.get_usage_stats()
    
    # Get most used file extensions
    extensions = sorted(
        stats.most_used_file_extensions.items(),
        key=lambda x: x[1],
        reverse=True
    )
    
    print("Most used file extensions:")
    for ext, count in extensions[:10]:
        print(f"  {ext}: {count} entries")

Finding Files Modified by Composer

from cursordata import CursorDataClient

with CursorDataClient() as client:
    sessions = client.get_composer_sessions()
    
    # Collect all unique files
    all_files = set()
    for session in sessions:
        all_files.update(session.files_modified)
    
    print(f"Total unique files modified: {len(all_files)}")
    for file_path in sorted(all_files)[:20]:
        print(f"  {file_path}")

Querying with Filters

from datetime import datetime, timedelta
from cursordata import CursorDataClient

with CursorDataClient() as client:
    # Query bubbles from last week
    week_ago = datetime.now() - timedelta(days=7)
    recent_bubbles = (
        client.query()
        .bubbles()
        .where(created_after=week_ago, has_code_blocks=True)
        .limit(10)
        .execute()
    )
    print(f"Found {len(recent_bubbles)} recent bubbles with code changes")
    
    # Query composer sessions for Python files
    python_sessions = (
        client.query()
        .composer_sessions()
        .where(file_extension=".py")
        .execute()
    )
    print(f"Found {len(python_sessions)} Python composer sessions")

Development

Setup

# Install development dependencies
uv pip install -e ".[dev,docs]"

# Or with pip
pip install -e ".[dev,docs]"

Running Tests

pytest

Building Documentation

cd docs
make html
# Documentation will be in docs/_build/html/

Code Quality

# Format code
black src/

# Lint
ruff check src/

# Type check
mypy src/

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

cursordata_sdk-0.1.0.tar.gz (61.0 kB view details)

Uploaded Source

Built Distribution

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

cursordata_sdk-0.1.0-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file cursordata_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: cursordata_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 61.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cursordata_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b711633c1e589848ae8c6b0bfb0efd39d9b411d551a2da9e8877106aee3ef9e2
MD5 d03ebb71465023ddd85e4233a10bc3df
BLAKE2b-256 fccc04895611e0909e737729f2fa29c11a75d4d1875e181a89ea332f13fe56df

See more details on using hashes here.

File details

Details for the file cursordata_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cursordata_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cursordata_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 acbd47b503ab6dc73cebf156c8cc65b5f1c3b16f2ad1f0aa5c17e057a4aee7be
MD5 5dd78f795f39c0ac2820c434ae3b0f8a
BLAKE2b-256 13883ecf1222b7166b13fc37bd3d8838817c392fdf30c1dc0d9000b868001b76

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