Python CLI tutorial

Start with the ZIP download, then create, read, and edit a practice document. This guide covers Wikitide Python CLI 0.2.0.

Download and install

You need Python 3.10 or later. Download and extract the ZIP. The examples use a macOS or Linux terminal. Adjust the directory if you extracted it elsewhere.

cd ~/Downloads/wikitide-cli-0.2.0
python3 --version
python3 wikitide.py --version

The last line should print 0.2.0. To run the extracted script directly, replace the leading wikitide in the examples with python3 wikitide.py and run them from the extracted directory.

Install the command on your PATH (optional)

If you have pipx, run the first two lines from the extracted directory. Open a new terminal after pipx ensurepath and check the version. Use pipx install --force . to replace an older installation.

pipx install .
pipx ensurepath
wikitide --version

Connect and sign in

Use the site’s home address. For a self-hosted site, substitute its domain. Replace YOUR_USERNAME with your account name and enter your password when prompted.

wikitide config init --server https://wikitide.soulshea.vip
wikitide auth login --username YOUR_USERNAME
wikitide auth status
wikitide doctor

Check the doctor output. authenticated true means you are signed in. server_supports_cli_v2 true means the server provides the newer interfaces used here.

The default configuration file at ~/.config/wikitide/config.json holds your session. Use wikitide config show to see the current server, config path, and session status. Run wikitide auth logout before leaving a shared device.

Create your first document

List your existing spaces and their IDs. For a separate place to practice, create a new space. The new space is saved on the current site.

wikitide wiki +spaces
wikitide wiki +space-create --name "CLI practice"

Replace the example space ID 7 with your own. Choose a space where you can edit documents, then run the command to create a Markdown document.

wikitide docs +create --team 7 --title "CLI practice" \
  --content "$(printf '# CLI practice\n\n## Setup\n\nFirst note.\n')"

For an existing Markdown file, replace --content and its value with --file ./note.md. After creation, find the document ID at data.id in the JSON response. Replace the example document ID 42 below with that value.

wikitide docs +list --team 7
wikitide docs +fetch --doc team:7:42

Search and read by section

Omit --team to search accessible site notes. Add --team 7 to search that space. The default output includes titles and IDs you can use to pick a document.

wikitide docs +search --query "Markdown"
wikitide docs +search --team 7 --query "CLI practice"

Use team:SPACE_ID:DOCUMENT_ID for team documents and note:ID for site notes. You can also pass a document URL to --doc. Put the entire URL in quotes when it contains an ampersand.

Read the outline, then a section

wikitide docs +fetch --doc team:7:42 --scope outline --max-depth 3
wikitide docs +fetch --doc team:7:42 --scope section \
  --start-block-id HEADING_BLOCK_ID
wikitide docs +fetch --doc team:7:42 --scope keyword \
  --keyword "Setup|note" --context-before 1 --context-after 1
wikitide docs +fetch --doc team:7:42 --detail with-ids

Copy the heading id from data.blocks in the outline and substitute it for HEADING_BLOCK_ID. A pipe in the keyword list matches any listed term. The default fetch returns HTML for read-only site notes. Reading sections or blocks requires access to the Markdown source.

Edit with version checks

Preview before appending

Fetch the document again and note its current version. This example assumes you just created version 1. Run the command with --dry-run to inspect the target and request, then remove that flag to save.

wikitide docs +update --doc team:7:42 --version 1 \
  --command append --content "Added from the CLI." --dry-run

Use prepend to add text at the beginning, str_replace to replace a unique text match, or block_replace, block_insert_after, and block_delete to edit particular blocks. Overwrite replaces the entire body. Read the current text before choosing an operation.

wikitide docs +update --doc team:7:42 --command str_replace \
  --pattern "First note." --content "Updated note." --dry-run

When editing from a previously fetched copy, pass --version for team documents or --base-sha for site notes. If you get a 409 conflict, fetch the latest text and merge your changes before trying again. Fetch fresh block IDs after the body changes.

Inspect changes and restore a revision

After saving, use history to find revisions and diff to compare one with the current body. To restore an older revision, preview the request and verify the revision before removing --dry-run. Restoring creates a new current version.

wikitide docs +history --doc team:7:42
wikitide docs +diff --doc team:7:42 --base 1
wikitide docs +restore --doc team:7:42 --revision 1 --dry-run

For team documents, revision is the historical version number. For site notes, it is the history record ID.

Import and export files

Direct import parses and saves Markdown, DOCX, PDF, or a ZIP containing one Markdown file into a team space. Each file can be up to 10 MB. PDF import extracts text by default. Add --note-format pdf to preserve the original file and layout.

wikitide docs +import --team 7 --file ./report.docx
wikitide docs +import --team 7 --file ./paper.pdf --note-format pdf

To review a parse first, stage the file with drive +upload. Compare the original and extracted text in Import documents, or export the extracted Markdown with the CLI. Replace the example job ID 12 with the ID returned by upload. Commit when the job reports ready.

wikitide drive +upload --file ./paper.pdf --wait
wikitide drive +status --job 12 --wait
wikitide drive +download --job 12 --export-format md \
  --output ./extracted.md
wikitide drive +commit --job 12 --team 7

For scanned PDFs, text extraction with --ocr requires server-side OCR. If the wait times out, keep the job ID the command returns and check it with drive +status.

Save a document to a local file

wikitide docs +export --doc team:7:42 --output ./practice.md
wikitide docs +export --doc team:7:42 --doc-format html \
  --output ./practice.html

JSON export is also available. If the document has an original PDF, choose --doc-format pdf and supply --output to download it. Choose a new name to avoid replacing an existing file.

Team comments and attachments

Comment and attachment commands target team documents and follow the site’s space permissions. When adding a comment, use --quote to include an excerpt from the document.

wikitide drive +list-comments --doc team:7:42 --page-all
wikitide drive +add-comment --doc team:7:42 \
  --content "Please add an example."
wikitide drive +upload-media --doc team:7:42 --file ./diagram.png
wikitide drive +list-media --doc team:7:42
wikitide drive +download-media --doc team:7:42 --attachment 18 \
  --output ./downloaded-diagram.png

Replace the example attachment ID 18 with the actual ID. Attachments can be PNG, JPEG, GIF, WebP, or PDF, up to 4 MB per file. Use the returned url in a Markdown image or link.

Scripts and agent integration

Use table for interactive reading, or the default JSON or ndjson in scripts. Use --fields to select fields. --page-all follows pages, --page-limit caps the number fetched, and --page-delay sets the interval in milliseconds.

wikitide docs +list --team 7 --fields id,title,version --format table
wikitide docs +list --team 7 --page-all --page-limit 5 \
  --fields id,title --format csv --output ./documents.csv

Use schema to inspect command arguments or export instructions for an agent that supports SKILL.md. Both work offline. In an agent workflow, have it find the document and fetch its current version before previewing and confirming edits.

wikitide schema docs.+update
wikitide skills show
wikitide skills install --path ./agent-skills --dry-run

After verifying the output path, remove --dry-run to generate wikitide-docs/SKILL.md. Scripts for multiple sites or accounts can use distinct files via --config. By default, results go to stdout and errors go to stderr. When using --output to save CSV, look for the resulting file.

Troubleshooting

The wikitide command was not found
Open a new terminal, or return to the extracted directory and run python3 wikitide.py --version.
Missing or expired session (401, exit code 3)
Check the configured server, sign in again, and run wikitide doctor.
Permission denied or missing resource (403 / 404, exit code 4)
Check the space and document IDs and verify the current account has access. If older commands work and a new command returns 404, check server_supports_cli_v2 in doctor.
Version conflict (409, exit code 5)
Fetch the document and version again, refresh block IDs if needed, then merge your edits.
Connection failed (exit code 6)
Check the domain, network connection, and whether the site opens in your browser. See the reference below for all exit codes and legacy commands.
Release Notes

WIKITIDE / WHAT’S NEW

View release history