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.
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 filecompute_content_hash(content: str) -> str- Compute SHA-256 hash of string contentwrite_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 databaseget_messages(db_path: str, session_id: str) -> List[dict]- Fetch messages for a sessionget_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 JSONexport_session_markdown(db_path: str, session_id: str, output_path: str) -> bool- Export to Markdownexport_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 dateformat_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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opencode_session_extractor-0.1.0.tar.gz.
File metadata
- Download URL: opencode_session_extractor-0.1.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
393cba53fc56a639c49be5363f5dfb909f7b4440fb28ae9fb4dc297e24750edf
|
|
| MD5 |
a3c98f4baeff0164e31323eaa0393321
|
|
| BLAKE2b-256 |
3267b7a2a5da3c1c722ba8b987a3eaf3e41972b656bb860b96012c07e9d7225f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opencode_session_extractor-0.1.0.tar.gz -
Subject digest:
393cba53fc56a639c49be5363f5dfb909f7b4440fb28ae9fb4dc297e24750edf - Sigstore transparency entry: 1440016580
- Sigstore integration time:
-
Permalink:
daedalus/opencode-session-extractor@bf33b5f6880ff02412e852346a52d4cf8cbf78c9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/daedalus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@bf33b5f6880ff02412e852346a52d4cf8cbf78c9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opencode_session_extractor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opencode_session_extractor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a8fb9235c4c26d524df6f7f343aaa115d33aab61bfe9b5f99b28f42234d96fd
|
|
| MD5 |
01c6a24115f3c7d84dae631a413e4bc7
|
|
| BLAKE2b-256 |
9d8379619e4bb7ee8d8bf1935b3456f639625859b0746504694b3620671a7cd1
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opencode_session_extractor-0.1.0-py3-none-any.whl -
Subject digest:
9a8fb9235c4c26d524df6f7f343aaa115d33aab61bfe9b5f99b28f42234d96fd - Sigstore transparency entry: 1440016602
- Sigstore integration time:
-
Permalink:
daedalus/opencode-session-extractor@bf33b5f6880ff02412e852346a52d4cf8cbf78c9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/daedalus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@bf33b5f6880ff02412e852346a52d4cf8cbf78c9 -
Trigger Event:
release
-
Statement type: