Skip to main content

Extract agent conversations from OpenCode SQLite database and export to JSON, Markdown, and HTML formats

Project description

openode_session_extractor — Extract agent conversations from OpenCode SQLite database.

PyPI Python Coverage RuffAsk DeepWiki

Install

pip install openode_session_extractor

Usage

from openode_session_extractor import export_session_json, export_session_markdown, export_session_html

# Export a session to JSON
export_session_json("/path/to/opencode.db", "session_id", "output.json")

# Export to Markdown
export_session_markdown("/path/to/opencode.db", "session_id", "output.md")

# Export to HTML
export_session_html("/path/to/opencode.db", "session_id", "output.html")

CLI

# List available sessions
openode_session_extractor --list

# Search sessions
openode_session_extractor --list --search "my project"

# Export a specific session to all formats
openode_session_extractor --session SESSION_ID --output-dir ./exports

# Export all sessions to Markdown only
openode_session_extractor --all --format markdown --output-dir ./exports

# Use custom database path
openode_session_extractor --db /path/to/custom.db --list

API

Core Functions

  • compute_file_hash(filepath: str) -> str - Compute SHA-256 hash of a file
  • compute_content_hash(content: str) -> str - Compute SHA-256 hash of string content
  • write_if_changed(output_path: str, content: str) -> bool - Write file only if content changed (hash-based collision detection)

Database Functions

  • get_sessions(db_path: str, limit: Optional[int], search: Optional[str]) -> List[dict] - Fetch sessions from database
  • get_messages(db_path: str, session_id: str) -> List[dict] - Fetch messages for a session
  • get_parts(db_path: str, message_id: str) -> List[dict] - Fetch parts for a message

Export Functions

  • export_session_json(db_path: str, session_id: str, output_path: str) -> bool - Export to JSON
  • export_session_markdown(db_path: str, session_id: str, output_path: str) -> bool - Export to Markdown
  • export_session_html(db_path: str, session_id: str, output_path: str) -> bool - Export to HTML

Formatting Functions

  • format_time(timestamp_ms: int) -> str - Convert millisecond timestamp to readable date
  • format_part(part_data: dict) -> str - Format a message part based on its type

Development

git clone https://github.com/daedalus/openode_session_extractor.git
cd openode_session_extractor
pip install -e ".[test]"

# run tests
pytest

# format
ruff format src/ tests/

# lint + type check (prospector runs ruff check + mypy together)
prospector --with-tool ruff --with-tool mypy src/
semgrep --config=auto --severity=ERROR src/

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

opencode_session_extractor-0.1.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

opencode_session_extractor-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for opencode_session_extractor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 393cba53fc56a639c49be5363f5dfb909f7b4440fb28ae9fb4dc297e24750edf
MD5 a3c98f4baeff0164e31323eaa0393321
BLAKE2b-256 3267b7a2a5da3c1c722ba8b987a3eaf3e41972b656bb860b96012c07e9d7225f

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_session_extractor-0.1.0.tar.gz:

Publisher: pypi-publish.yml on daedalus/opencode-session-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for opencode_session_extractor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a8fb9235c4c26d524df6f7f343aaa115d33aab61bfe9b5f99b28f42234d96fd
MD5 01c6a24115f3c7d84dae631a413e4bc7
BLAKE2b-256 9d8379619e4bb7ee8d8bf1935b3456f639625859b0746504694b3620671a7cd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_session_extractor-0.1.0-py3-none-any.whl:

Publisher: pypi-publish.yml on daedalus/opencode-session-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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