sagewiki
Typed Python client for sage-wiki's /v1 REST API.
Pre-1.0 — the API surface can change between releases. Pin a version:
pip install "sagewiki==0.1.*"
Sync and async clients, one shared implementation, httpx as the only
dependency, type hints throughout (py.typed shipped).
Install
pip install sagewiki # Python ≥ 3.9
Quickstart
Start the server: sage-wiki serve --ui --port 3333 (loopback needs no
token; non-loopback sets SAGE_WIKI_TOKEN).
from sagewiki import SageWiki
c = SageWiki() # SAGE_WIKI_URL / SAGE_WIKI_TOKEN from env, or pass url=/token=
# Search the compiled wiki + raw sources.
results = c.search("attention", limit=5)
for r in results.results:
print(r.final_score, r.content[:80])
# Compile-on-demand: matches that are only raw sources surface as
# uncompiled_sources > 0 — submit a topic compile and wait.
if results.uncompiled_sources > 0:
job = c.compile(topic="attention")
job.wait(timeout=600) # timeout is REQUIRED — no unbounded waits
# Capture knowledge back (spends LLM budget on the server).
c.capture("Self-attention computes pairwise token affinities.",
idempotency_key="note-1")
Async is identical, with await:
from sagewiki import AsyncSageWiki
async with AsyncSageWiki() as c:
results = await c.search("attention")
job = await c.compile(dry_run=True)
await job.wait(timeout=60)
Beyond search — the differentiators
This client is not an add/search pair. The parts worth knowing:
# Provenance: which sources back a compiled article (and vice versa).
prov = c.provenance(article="attention")
# Graph queries over the ontology — local neighborhoods or global
# community summaries, optionally time-scoped.
answer = c.graph_query("how does attention relate to transformers", hops=2)
# answer.answer, answer.cited, answer.seeds
# as_of needs ontology.temporal.enabled, mode="global" needs
# ontology.communities.enabled — both off by default. Calling without them
# raises FeatureDisabled (412) and its docstring names the fix.
history = c.graph_query("attention research", as_of="2026-01-01T00:00:00Z")
# Read the compiled wiki directly — human-readable, Obsidian-compatible.
article = c.read_article("concepts/attention.md")
Errors
Branch on the class (or .code), never on .message:
| Class | HTTP | code |
|---|---|---|
InvalidArgument |
400 | invalid_argument |
Unauthenticated |
401 | unauthenticated |
Forbidden |
403 | forbidden |
NotFound |
404 | not_found |
Conflict |
409 | conflict (.active_job_id when a compile is running) |
FeatureDisabled |
412 | feature_disabled |
PayloadTooLarge |
413 | payload_too_large |
RateLimited |
429 | rate_limited (reserved) |
InternalError |
500 | internal |
Unavailable |
503 | unavailable |
JobTimeout / JobFailed |
— | raised by Job.wait() |
Unknown future codes map to SageWikiError with the raw code intact.
Async jobs
compile() and lint() submit jobs; they don't block:
job = c.compile(topic="quantum computing", max_sources=20)
job = c.compile(dry_run=True) # full compile (flags)
job = c.lint(pass_="connections", fix=False)
job.refresh() # poll once
job.wait(timeout=300, poll_interval=2) # poll until done — raises JobTimeout,
# JobFailed; returns on cancelled
Submitting while a compile runs raises Conflict with .active_job_id —
poll that job instead. Pass idempotency_key= on submits and writes to
make retries safe (replays return the same job_id).
Retries & timeouts
Transport errors and 503s are retried only when you opt in (retries=N),
and never for a write without an idempotency_key. The HTTP request
timeout defaults to 30s (timeout= on the constructor) and is separate
from Job.wait(timeout=…).
Development
pip install -e ".[dev]"
pytest -q # unit tests (mocked transport)
eval "$(../../scripts/p4-fixture-server.sh)"
pytest -q -m contract # contract tests against a live server
Metadata
Release files for sagewiki 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sagewiki-0.1.0.tar.gz | 18.9 kB | With provenance | Details for sagewiki-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sagewiki-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sagewiki-0.1.0-py3-none-any.whl |
Total release size: 31.8 kB
Release files / sagewiki-0.1.0.tar.gz
| Download URL | sagewiki-0.1.0.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a13e4e4427156aca7c83f8e2220bbc3c3e4aa23ae7356cf8aba894748b5e3d1b
|
|
BLAKE2b-256 checksum How to use checksums |
b9fd8b90e6f40426667f5d96452eeba54fcb9ba9d00e30cc6ee80fdf73ebe654
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.
Transparency logRelease files / sagewiki-0.1.0-py3-none-any.whl
| Download URL | sagewiki-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7414cbca53b33e5377ed76f89bd2da83e3b6a19f0e6155e9da94539aa151383e
|
|
BLAKE2b-256 checksum How to use checksums |
ad04c0000c5ec11b132fa6590d46d710c95d95e1464e12b8743ba88e0c09d6eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.
Transparency logSecurity for sagewiki 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sagewiki-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.