sdk/python/README.md
Lightweight Python HTTP SDK for OpenViking.
openviking-sdk is the small package for users who only need to call an existing OpenViking server over HTTP. It avoids the heavier local-runtime, server, and CLI dependencies from the main openviking package.
pip install openviking-sdk
Requirements:
http://127.0.0.1:1933openviking-sdkopenviking_sdkfrom openviking_sdk import AsyncHTTPClient, SyncHTTPClient
You can configure the SDK in three ways, with this precedence:
OPENVIKING_URL, OPENVIKING_API_KEY, OPENVIKING_ACCOUNT, OPENVIKING_USER, OPENVIKING_ACTOR_PEER_ID, and OPENVIKING_TIMEOUTovcli.conf, either from OPENVIKING_CLI_CONFIG_FILE or the default path ~/.openviking/ovcli.confThis means existing setups that relied on ovcli.conf continue to work after the SDK split.
Most deployments use API key authentication.
Common client fields:
url: OpenViking server base URLapi_key: root key or user keyaccount: optional account override, usually only needed with a root keyuser: optional user override, usually only needed with a root keyuser_id: legacy alias for useractor_peer_id: optional actor peer overrideagent_id: legacy alias for actor_peer_idCompatibility notes:
user_id and agent_id are still accepted for legacy callersactor_peer_id and agent_id cannot be passed togetherExample:
from openviking_sdk import SyncHTTPClient
client = SyncHTTPClient(
url="http://127.0.0.1:1933",
api_key="your-user-or-root-key",
)
If you are using a root key and want to act as a specific tenant user:
from openviking_sdk import SyncHTTPClient
client = SyncHTTPClient(
url="http://127.0.0.1:1933",
api_key="your-root-key",
account="demo-account",
user="demo-user",
)
from openviking_sdk import SyncHTTPClient
client = SyncHTTPClient(
url="http://127.0.0.1:1933",
api_key="your-user-key",
)
healthy = client.health()
print("health:", healthy)
session = client.create_session("demo-session")
print("session:", session)
client.session("demo-session").add_message("user", "hello from sdk")
context = client.session("demo-session").get_session_context(token_budget=4096)
print("context:", context)
import asyncio
from openviking_sdk import AsyncHTTPClient
async def main() -> None:
client = AsyncHTTPClient(
url="http://127.0.0.1:1933",
api_key="your-user-key",
)
healthy = await client.health()
print("health:", healthy)
session = await client.create_session("demo-session-async")
print("session:", session)
session_client = client.session("demo-session-async")
await session_client.add_message("user", "hello from async sdk")
context = await session_client.get_session_context(token_budget=4096)
print("context:", context)
await client.close()
asyncio.run(main())
from openviking_sdk import SyncHTTPClient
client = SyncHTTPClient(url="http://127.0.0.1:1933", api_key="your-user-key")
result = client.create_session("demo-session")
print(result)
add_resource handles file upload for local paths automatically.
from openviking_sdk import SyncHTTPClient
client = SyncHTTPClient(url="http://127.0.0.1:1933", api_key="your-user-key")
result = client.add_resource(
"/path/to/notes.md",
to="viking://resources/demo-notes",
reason="knowledge import",
wait=True,
)
print(result)
from openviking_sdk import SyncHTTPClient
client = SyncHTTPClient(url="http://127.0.0.1:1933", api_key="your-user-key")
client.mkdir("viking://resources/demo-dir")
print(client.ls("viking://resources"))
print(client.read("viking://resources/demo-dir/example.md"))
from openviking_sdk import SyncHTTPClient
client = SyncHTTPClient(url="http://127.0.0.1:1933", api_key="your-user-key")
result = client.find("hello", limit=5)
print(result)
If you connect with a root key, the SDK also exposes admin APIs such as:
admin_create_accountadmin_register_useradmin_list_accountsadmin_list_usersadmin_regenerate_keyadmin_delete_accountExample:
from openviking_sdk import SyncHTTPClient
root_client = SyncHTTPClient(
url="http://127.0.0.1:1933",
api_key="your-root-key",
)
result = root_client.admin_create_account(
account_id="demo-account",
admin_user_id="demo-admin",
)
print(result)
The SDK maps server-side error codes to Python exceptions.
from openviking_sdk import OpenVikingError, SyncHTTPClient
client = SyncHTTPClient(url="http://127.0.0.1:1933", api_key="your-user-key")
try:
print(client.read("viking://resources/not-exists.md"))
except OpenVikingError as exc:
print(type(exc).__name__, exc)
openvikingUse openviking-sdk when you want:
Use openviking when you want:
Install from source:
cd sdk/python
pip install -e .
Build distributions:
cd sdk/python
python -m build
The SDK version is derived from git tags with this format:
That tag namespace is independent from the main package release tags such as:
v0.3.26
The repository is configured so SDK releases can be driven by SDK-only tags.
Typical flow:
[email protected].sdk/python.openviking-sdk to PyPI.