Declarative thread sync for Slack, Discord, and Bluesky
Project description
thrds
Declarative thread sync for Slack, Discord, and Bluesky.
Given a desired thread state (list of message contents), diffs against existing messages and applies minimal edits/posts/deletes to converge.
Install
pip install thrds # Core only (zero deps)
pip install thrds[bsky] # + Bluesky (atproto)
Slack and Discord clients use only stdlib (urllib) and curl subprocess respectively — no extra deps needed.
Usage
from thrds import SlackClient, Thread
slack = SlackClient(token="xoxb-...", channel="C0AQC2VKEJF")
thread = Thread(messages=["OP text", "Reply 1", "Reply 2"])
# Create new thread
result = slack.sync(thread)
# Update existing thread (edits changed messages, appends new, deletes extras)
result = slack.sync(thread, thread_ts="1775516040.743629")
Discord
from thrds import DiscordClient, Thread
discord = DiscordClient(token="your-bot-token", channel_id="1489279547689140505")
thread = Thread(messages=["OP text", "Reply 1", "Reply 2"])
result = discord.sync(thread, thread_id="1490821926288097503")
Bluesky
from thrds import BskyClient, Thread
bsky = BskyClient(handle="you.bsky.social", password="app-password")
thread = Thread(messages=["Root post", "Reply 1"])
result = bsky.sync(thread)
Bluesky doesn't support editing posts — the sync algorithm automatically falls back to delete+repost when content changes.
Linked summary threads
Post summary bullets that link to detail messages in the same thread:
from thrds import LinkedThread, Section
linked = LinkedThread(
summary_prefix="# Daily Digest",
sections=[
Section(title="Topic A", summary="Brief summary", body="Full detail text..."),
Section(title="Topic B", summary="Another summary", body="More details..."),
],
)
# Discord: summary bullets use [**Title**](url) markdown links
result = discord.sync_linked(linked, thread_id="...", guild_id="...")
# Slack: summary bullets use <url|*Title*> mrkdwn links
result = slack.sync_linked(linked, thread_ts="...")
Two-phase sync: posts all messages with placeholder links, then edits summaries with real links once message IDs are known.
Dry run / diff preview
result = slack.sync(thread, thread_ts="...", dry_run=True)
print(result.format_preview(color=True, prefix="thread: "))
thread: SKIP [0] (unchanged)
thread: EDIT [1]
thread: -old message text
thread: +new message text
thread: POST [2]
thread: +entirely new message
Each Action carries prior_content (for EDIT/DELETE) alongside content, enabling colored unified-diff output via action.format().
Sync algorithm
Given desired messages M and existing thread messages N:
- Delete extras from the end (backwards — replies before OP)
- Edit overlapping messages where content changed (skip unchanged)
- Post new messages at the end
Foreign (non-editable) messages — e.g. human replies in a bot thread — are automatically skipped. The sync only operates on the bot's own messages, leaving everyone else's untouched.
Features
- Foreign message preservation: Non-bot messages in threads are skipped during sync (no more
cant_update_messageerrors) - Rate limit handling: Slack 429 retry with
Retry-After, configurablepaceandjitterbetween API calls - Edit rate limit fallback: Discord's 30046 error (edit limit on old messages) triggers automatic delete+repost
- Linked summary threads:
sync_linked()for summary-with-links threads on Discord and Slack - Diff preview:
Action.format()andSyncResult.format_preview()for colored diff output - Orphan guard: Slack
delete()checks for thread replies before deleting (raisesOrphanedRepliesError) - Unfurl/embed suppression: Slack link previews and Discord embeds suppressed via options
- Discord system message filtering: Thread starter messages filtered from
list_messages - Bot token prefix: Discord
Botprefix auto-prepended - Metadata support: Slack message metadata passthrough
Used by
- hudcostreets/nj-crashes — Slack crash-notification threads (
SlackClient.sync()) - Open-Athena/marin-discord — Discord summary threads (
DiscordClient.sync_linked())
API
SyncResult
@dataclass
class SyncResult:
thread_id: str # thread_ts (Slack), thread channel ID (Discord), AT URI (Bluesky)
message_ids: list[str] # Per-message IDs
actions: list[Action] # What was done: Edit, Post, Delete, Skip
Action
@dataclass
class Action:
type: ActionType # SKIP, EDIT, POST, DELETE
index: int
message_id: str | None
content: str | None # Desired text (POST, EDIT, SKIP)
prior_content: str | None # Previous text (EDIT, DELETE)
SyncOptions
| Option | Default | Description |
|---|---|---|
dry_run |
False |
Print actions without executing |
pace |
0.0 |
Seconds between mutating API calls |
jitter |
0.0 |
Random additional delay (0 to jitter) added to pace |
suppress_embeds |
False |
Discord: suppress link previews |
suppress_unfurls |
True |
Slack: suppress link previews |
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
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 thrds-0.3.0.tar.gz.
File metadata
- Download URL: thrds-0.3.0.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ef316f6069425d491f3bc9c11feccc22f516b5fc9b952fd0b5416a4608c47e7
|
|
| MD5 |
4501435e4b787c11acd183fefc3d4bff
|
|
| BLAKE2b-256 |
05f0ca45fbdc453f052f261d987ec4fa41bfddf1aed59ca855cf0a98a212b344
|
Provenance
The following attestation bundles were made for thrds-0.3.0.tar.gz:
Publisher:
release.yml on runsascoded/thrds
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thrds-0.3.0.tar.gz -
Subject digest:
5ef316f6069425d491f3bc9c11feccc22f516b5fc9b952fd0b5416a4608c47e7 - Sigstore transparency entry: 1340571022
- Sigstore integration time:
-
Permalink:
runsascoded/thrds@ea670ac9e2751f8c879db36ddd16c8d4782f0316 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/runsascoded
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ea670ac9e2751f8c879db36ddd16c8d4782f0316 -
Trigger Event:
push
-
Statement type:
File details
Details for the file thrds-0.3.0-py3-none-any.whl.
File metadata
- Download URL: thrds-0.3.0-py3-none-any.whl
- Upload date:
- Size: 16.2 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 |
79b7629c8f45b38ce3ae8c8aeb2bc1dde14f1d0afa87cb5f6818e0a9262059ed
|
|
| MD5 |
625b84c12fa4e045d5adad2ef58f138f
|
|
| BLAKE2b-256 |
3a11d32521162fe2facd5a5b050d9fd48764bf31998a8577b32536573403ee7e
|
Provenance
The following attestation bundles were made for thrds-0.3.0-py3-none-any.whl:
Publisher:
release.yml on runsascoded/thrds
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thrds-0.3.0-py3-none-any.whl -
Subject digest:
79b7629c8f45b38ce3ae8c8aeb2bc1dde14f1d0afa87cb5f6818e0a9262059ed - Sigstore transparency entry: 1340571024
- Sigstore integration time:
-
Permalink:
runsascoded/thrds@ea670ac9e2751f8c879db36ddd16c8d4782f0316 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/runsascoded
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ea670ac9e2751f8c879db36ddd16c8d4782f0316 -
Trigger Event:
push
-
Statement type: