docspan
Push and pull markdown to Google Docs and Confluence from a single CLI. docspan provides bidirectional sync with three-way merge conflict detection, structural diff push that preserves comments on unchanged paragraphs, and a simple YAML-based configuration file.
The config file is named markgate.yaml — this name is preserved for backward compatibility and will be renamed in v0.2.0.
Supported Backends
| Backend | Push | Pull |
|---|---|---|
| Google Docs | yes | yes |
| Confluence | yes | yes |
Install
pip install docspan
Quick start
1. Create markgate.yaml:
backends:
google_docs:
credentials_path: /path/to/service-account.json
mappings:
- local: docs/design-doc.md
backend: google_docs
remote_id: YOUR_GOOGLE_DOC_ID
direction: both
2. Set up authentication:
docspan auth setup google_docs
# or
docspan auth setup confluence
3. Push and pull:
docspan push # push all mappings
docspan pull # pull all mappings
docspan status # show mapping table
4. Resolve conflicts (if any):
docspan conflicts list
docspan conflicts resolve docs/design-doc.md --accept remote
Configuration (markgate.yaml)
backends:
google_docs:
credentials_path: /path/to/service-account.json # or use env ACCOUNT_A_CREDENTIALS_PATH
confluence:
base_url: https://yourorg.atlassian.net
username: you@example.com
api_token: your-api-token # or env CONFLUENCE_API_TOKEN
mappings:
- local: docs/notes.md
backend: google_docs
remote_id: YOUR_GOOGLE_DOC_ID
direction: both # push | pull | both
- local: docs/page.md
backend: confluence
remote_id: YOUR_CONFLUENCE_PAGE_ID
direction: both
Note: markgate.yaml is gitignored by default because it may contain API tokens. Commit a markgate.yaml.example template alongside it.
Central config & XDG storage
By default docspan stores its config, sync state, and credentials under the XDG base directories, and a central config lets you register multiple projects by prefix and run docspan from anywhere.
$XDG_CONFIG_HOME/docspan/config.yaml # central config (project registry)
$XDG_CONFIG_HOME/docspan/<prefix>/… # cached OAuth token
$XDG_STATE_HOME/docspan/<prefix>/… # sync state + base store, per project
Central config (~/.config/docspan/config.yaml):
default_prefix: design-docs
projects:
design-docs:
markgate: ~/Documents/design-docs/markgate.yaml
Register and use projects:
docspan config add design-docs ~/Documents/design-docs/markgate.yaml # register (prefix → markgate.yaml)
docspan config show # list projects + active resolution
docspan push --prefix design-docs # or DOCSPAN_PREFIX, or default_prefix, or cwd match
docspan migrate-xdg --prefix design-docs # move legacy in-repo state to XDG + register
Prefix resolution order: --config PATH (legacy — storage stays beside the file) → --prefix → DOCSPAN_PREFIX → cwd inside a registered project → default_prefix. If nothing matches, docspan falls back to a local ./markgate.yaml with beside-the-file storage (fully backward-compatible).
Command Reference
docspan push
docspan push [FILES]... [--dry-run] [--config PATH]
Push local markdown files to remote docs. Skips mappings with direction = "pull". Accepts an optional list of local file paths to restrict which mappings are pushed.
docspan pull
docspan pull [FILES]... [--dry-run] [--config PATH]
Pull remote documents into local markdown files with three-way merge. Writes conflict markers to the file if automatic merge fails. For Google Docs, also writes a {file}.comments.md sidecar of the doc's comments (open + resolved, with quoted selections and reply threads) unless pull_comments: false.
docspan status
docspan status [--config PATH]
Display all configured mappings in a table showing local file, backend, remote ID, and direction.
docspan auth setup
docspan auth setup BACKEND [--config PATH]
Interactive authentication setup. BACKEND is one of google_docs or confluence.
For Google Docs, run it with no flags for a guided flow:
docspan auth setup google_docs
It detects your current state, lets you pick Personal (OAuth) [recommended] or Service account, auto-detects a client_secret.json (scanning ., .markgate/, ~/Downloads) or prompts for the path with validation, runs the browser sign-in, verifies the connection, and offers to persist the choice into markgate.yaml so you never repeat it. In a non-TTY/CI environment it prints manual instructions instead of prompting.
Everything is scriptable — any answer can be supplied as a flag: --oauth / --service-account, --client-secret PATH, --credentials PATH. If a docspan push/pull runs without credentials in an interactive terminal, it offers to run setup inline and then continues.
For Confluence, prompts for base URL, username, and API token, then prints a YAML snippet to add to markgate.yaml.
docspan conflicts list
docspan conflicts list [--config PATH]
Scan all tracked files for unresolved merge conflict markers (<<<<<<< ). Prints a table of conflicted files and conflict block counts.
docspan conflicts resolve
docspan conflicts resolve FILE --accept remote|local|merged [--config PATH]
Resolve a merge conflict in a tracked file.
| Strategy | Behavior |
|---|---|
remote |
Re-fetch the remote version and overwrite the local file |
local |
Restore the pre-merge local content from the .orig backup |
merged |
Accept the current file contents as the resolved version (conflict markers must be removed first) |
Configuration Reference
backends.google_docs
| Field | Type | Default | Description |
|---|---|---|---|
credentials_path |
string | null | Path to a Google service account JSON key |
oauth_client_secret_path |
string | null | Path to an OAuth client secret JSON (Desktop app) for per-user auth |
token_path |
string | $XDG_CONFIG_HOME/docspan/google_token.json |
Where the cached OAuth user token is stored/refreshed (out of the repo) |
pull_comments |
bool | true |
On pull, write a {file}.comments.md sidecar of the doc's comments |
Auth resolution order: credentials_path → ACCOUNT_A_CREDENTIALS[_PATH] env → per-user OAuth (oauth_client_secret_path, or an already-cached token_path).
Environment variable alternatives (service account):
ACCOUNT_A_CREDENTIALS_PATH— path to service account JSONACCOUNT_A_CREDENTIALS— inline service account JSON string
backends.confluence
| Field | Type | Default | Description |
|---|---|---|---|
base_url |
string | null | Confluence base URL, e.g. https://yourorg.atlassian.net |
username |
string | null | Atlassian account email |
api_token |
string | null | API token from id.atlassian.com |
Environment variable alternatives:
CONFLUENCE_BASE_URLATLASSIAN_USER_NAMECONFLUENCE_API_TOKEN
mappings[]
| Field | Type | Default | Required | Description |
|---|---|---|---|---|
local |
string | — | yes | Relative path to local markdown file |
backend |
string | — | yes | "google_docs" or "confluence" |
remote_id |
string | — | yes | Google Doc ID or Confluence page ID |
direction |
enum | "both" |
no | "push", "pull", or "both" |
tab_id |
string | null |
no | Google Docs tab id (e.g. "t.moqlkhpwn82e") to target on a multi-tab doc. Ignored by the Confluence backend. If unset and the doc has more than one tab, push/pull still succeed but report a "warning" naming the tabs found, instead of silently syncing whichever tab is first. |
State Files
docspan generates these files in your project directory after first sync:
| File | Description |
|---|---|
.markgate-state.json |
Sync state tracking (content hashes, remote versions) |
.markgate-base/ |
Content-addressed store of merge bases |
{file}.orig |
Backup of local file before merge; deleted after conflict resolution |
{file}.comments.md |
Comment sidecar (Google Docs + Confluence); written during pull if comments exist |
Known Limitations
[!NOTE] Known limitations in v0.1.0
- Google Docs: comments on edited paragraphs are lost on push (paragraph-level structural diff; comments on unchanged paragraphs are preserved).
docspan push --dry-runand a default fail-closed--force-gated block now warn before this happens — it is still not prevented.- Push: no image support — local images cannot be pushed to Google Docs or Confluence
- Push: no table support — markdown tables are not rendered in Google Docs
- Confluence: requires an Atlassian API token; no OAuth flow
- Confluence: the comment sidecar (
{file}.comments.md) is informational only; comments cannot be pushed back- Checklist state (
- [ ]/- [x]) round-trips as literal text — Google Docs' native checkbox glyph is intentionally not used because its checked/unchecked state cannot be read back via the API (see ADR-001)push --dry-runnow shows a real structural diff and flags paragraphs with open comments at risk;pushblocks by default on a flagged paragraph unless--forceis passed- If a push succeeds but a post-push check finds the open-comment count dropped, docspan reports this as a
⚠warning — never a plain green success — so it's never mistaken for a clean push- Google Docs: multi-tab docs need
tab_idset explicitly per mapping — find it in the doc's URL (...#tab=t.XXXXXXXXXXafter clicking the tab) or from the warning message docspan prints whentab_idis left unset. Without it, pull/push default to the doc's first tab (pull's default path additionally can't target a tab at all — it uses Drive's HTML export, which only ever returns the first tab; settab_idto instead pull via the structural API, which can target any tab)- Google Docs OAuth requires each user to create their own GCP project (
docspan auth setup google_docs→ Personal/OAuth) and stays in Google's "Testing" publishing status — capped at 100 test users, with Google's "app isn't verified" warning shown on first sign-in. This avoids the annual CASA security assessment required to verify apps requesting Drive/Docs' restricted read-write scopes (a real recurring cost), at the price of a few extra manual setup minutes per user instead of a single embedded, zero-config client. Revisit if/when adoption outgrows a per-user-project model — options are paying for verification, or narrowing to the unrestricteddrive.filescope via Google's Picker API (bigger rework: requires the user to explicitly select their doc through a picker rather than referencing it by ID in config)
License
MIT. See LICENSE for details.
For contribution guidelines, see CONTRIBUTING.md. For the full change history, see CHANGELOG.md.
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 docspan-0.3.0.tar.gz.
File metadata
- Download URL: docspan-0.3.0.tar.gz
- Upload date:
- Size: 659.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
565c4def9aca862adb5f94f9d344cb6d1e61de78fea40b97904f51fbf2db7372
|
|
| MD5 |
d107843db8c4636ab5409f115b212b41
|
|
| BLAKE2b-256 |
27c426e16d7ec3467a680e13ca7ef3d73a4a9a9730113cc3020ff93b2eaad3e6
|
Provenance
The following attestation bundles were made for docspan-0.3.0.tar.gz:
Publisher:
publish.yml on tstapler/docspan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docspan-0.3.0.tar.gz -
Subject digest:
565c4def9aca862adb5f94f9d344cb6d1e61de78fea40b97904f51fbf2db7372 - Sigstore transparency entry: 2457589399
- Sigstore integration time:
-
Permalink:
tstapler/docspan@e76ffb8547bfd7d2d2b453a64a5fb3899445fc5f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tstapler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e76ffb8547bfd7d2d2b453a64a5fb3899445fc5f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file docspan-0.3.0-py3-none-any.whl.
File metadata
- Download URL: docspan-0.3.0-py3-none-any.whl
- Upload date:
- Size: 246.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ce07bfe04485e50bcf4d0e3dbde5168e046ed41e499a852928e5997de6f9de9
|
|
| MD5 |
79dd157bb96d6239857688d581f01f26
|
|
| BLAKE2b-256 |
64c5a8c65eec645d953d06b8ce04f78a0e3744905277bbe86137e61428026418
|
Provenance
The following attestation bundles were made for docspan-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on tstapler/docspan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docspan-0.3.0-py3-none-any.whl -
Subject digest:
2ce07bfe04485e50bcf4d0e3dbde5168e046ed41e499a852928e5997de6f9de9 - Sigstore transparency entry: 2457589426
- Sigstore integration time:
-
Permalink:
tstapler/docspan@e76ffb8547bfd7d2d2b453a64a5fb3899445fc5f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tstapler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e76ffb8547bfd7d2d2b453a64a5fb3899445fc5f -
Trigger Event:
workflow_dispatch
-
Statement type: