Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat(sdk): support Python 3.8 (#5158)
Jiahui Zhou0552debc5fdf
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.ymlindex 61a3f21e5..d0e736820 100644--- a/.github/workflows/pr.yml+++ b/.github/workflows/pr.yml@@ -140,6 +140,7 @@ jobs:cuvs_changed: ${{ steps.check.outputs.cuvs_changed }}langchain_changed: ${{ steps.check.outputs.langchain_changed }}openclaw_changed: ${{ steps.check.outputs.openclaw_changed }}+ sdk_python_changed: ${{ steps.check.outputs.sdk_python_changed }}steps:- uses: actions/checkout@v6with:@@ -203,11 +204,61 @@ jobs:echo "openclaw_changed=false" >> $GITHUB_OUTPUTfi+ SDK_PYTHON_PATTERN="sdk/python/|\.github/workflows/pr\.yml"+ SDK_PYTHON_CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E "$SDK_PYTHON_PATTERN" || true)++ if [ -n "$SDK_PYTHON_CHANGED_FILES" ]; then+ echo "Standalone Python SDK-related changes detected:"+ echo "$SDK_PYTHON_CHANGED_FILES"+ echo "sdk_python_changed=true" >> $GITHUB_OUTPUT+ else+ echo "No standalone Python SDK-related changes detected."+ echo "sdk_python_changed=false" >> $GITHUB_OUTPUT+ fi+build:needs: check-depsif: ${{ needs.check-deps.outputs.deps_changed == 'true' }}uses: ./.github/workflows/_build.yml+ sdk-python-tests:+ needs: check-deps+ if: ${{ needs.check-deps.outputs.sdk_python_changed == 'true' }}+ runs-on: ubuntu-24.04+ strategy:+ fail-fast: false+ matrix:+ python-version: ["3.8", "3.9", "3.10", "3.12"]+ steps:+ - uses: actions/checkout@v6++ - uses: actions/setup-python@v6+ with:+ python-version: ${{ matrix.python-version }}++ - name: Install standalone SDK test dependencies+ run: |+ python -m pip install --upgrade pip+ python -m pip install -e sdk/python "pytest<8" "pytest-asyncio<0.22"++ - name: Run standalone SDK tests+ run: |+ python -m pytest -q sdk/python/tests \+ -o addopts='' \+ --ignore=sdk/python/tests/test_legacy_shims.py \+ --ignore=sdk/python/tests/test_main_package_exports.py++ - name: Build and test installed wheel+ if: matrix.python-version == '3.8'+ run: |+ python -m pip install "build<1.3"+ python -m build sdk/python+ python -m venv /tmp/openviking-sdk-wheel+ WHEEL_PATH=$(find sdk/python/dist -name '*.whl' -print -quit)+ /tmp/openviking-sdk-wheel/bin/python -m pip install "$WHEEL_PATH"+ cd /tmp+ /tmp/openviking-sdk-wheel/bin/python -c "import openviking_sdk"+cuvs-tests:needs: check-depsif: ${{ needs.check-deps.outputs.cuvs_changed == 'true' }}diff --git a/sdk/python/README.md b/sdk/python/README.mdindex 5eac9eea3..fcbd7ae18 100644--- a/sdk/python/README.md+++ b/sdk/python/README.md@@ -12,7 +12,7 @@ pip install openviking-sdkRequirements:-- Python 3.10++- Python 3.8+- A reachable OpenViking HTTP server, for example `http://127.0.0.1:1933`## Package Name vs Import Namediff --git a/sdk/python/README_CN.md b/sdk/python/README_CN.mdindex 4ab814f54..8d7d59945 100644--- a/sdk/python/README_CN.md+++ b/sdk/python/README_CN.md@@ -12,7 +12,7 @@ pip install openviking-sdk要求:-- Python 3.10++- Python 3.8+- 一个可访问的 OpenViking HTTP 服务,例如 `http://127.0.0.1:1933`## 包名与导入名diff --git a/sdk/python/openviking_sdk/_utils.py b/sdk/python/openviking_sdk/_utils.pyindex a41530c1a..1f453ff4c 100644--- a/sdk/python/openviking_sdk/_utils.py+++ b/sdk/python/openviking_sdk/_utils.py@@ -4,6 +4,7 @@ import asyncioimport atexitimport osimport threading+from pathlib import Pathfrom typing import Any, Coroutine_worker_lock = threading.Lock()@@ -11,6 +12,14 @@ _worker_loop: asyncio.AbstractEventLoop | None = None_worker_thread: threading.Thread | None = None+def _path_is_relative_to(path: Path, root: Path) -> bool:+ try:+ path.relative_to(root)+ except ValueError:+ return False+ return True++async def _capture_result(coro: Coroutine[Any, Any, Any]) -> tuple[bool, Any]:try:return True, await corodiff --git a/sdk/python/openviking_sdk/client.py b/sdk/python/openviking_sdk/client.pyindex bed2d4bf4..f812e2495 100644--- a/sdk/python/openviking_sdk/client.py+++ b/sdk/python/openviking_sdk/client.py@@ -14,7 +14,7 @@ from urllib.parse import quoteimport httpx-from ._utils import run_async+from ._utils import _path_is_relative_to, run_asyncfrom .actor_peer import _request_actor_peer_headersfrom .config import resolve_client_configfrom .errors import (@@ -93,6 +93,14 @@ GATEWAY_TOKEN_HEADER = "X-Gateway-Token"_SESSION_CONFIG_UNSET = object()+def _option_keys(options_type: Type[Any]) -> set[str]:+ optional_keys = getattr(options_type, "__optional_keys__", None)+ required_keys = getattr(options_type, "__required_keys__", None)+ if optional_keys is not None and required_keys is not None:+ return set(optional_keys) | set(required_keys)+ return set(getattr(options_type, "__annotations__", {}))++def _image_mime_type(file_name: str = "") -> str:mime_type, _ = mimetypes.guess_type(file_name or "")if mime_type and mime_type.startswith("image/"):@@ -544,7 +552,7 @@ class AsyncHTTPClient:protected: Optional[set[str]] = None,) -> Dict[str, Any]:option_values = dict(options or {})- allowed = set(options_type.__optional_keys__) | set(options_type.__required_keys__)+ allowed = _option_keys(options_type)unknown = sorted(set(option_values) - allowed)if unknown:raise TypeError(@@ -582,7 +590,7 @@ class AsyncHTTPClient:option_values["context_type"])- allowed = set(options_type.__optional_keys__) | set(options_type.__required_keys__)+ allowed = _option_keys(options_type)allowed.discard("image")allowed.add("image_url")proxy_type = type(@@ -682,7 +690,7 @@ class AsyncHTTPClient:if file_path.is_symlink():continueif file_path.is_file():- if not file_path.resolve().is_relative_to(root):+ if not _path_is_relative_to(file_path.resolve(), root):continuearcname = str(file_path.relative_to(dir_path)).replace("\\", "/")zipf.write(file_path, arcname=arcname)diff --git a/sdk/python/openviking_sdk/uploads.py b/sdk/python/openviking_sdk/uploads.pyindex 083df3d9a..af86b6f16 100644--- a/sdk/python/openviking_sdk/uploads.py+++ b/sdk/python/openviking_sdk/uploads.py@@ -5,6 +5,8 @@ import uuidimport zipfilefrom pathlib import Path+from ._utils import _path_is_relative_to+def zip_directory(dir_path: str) -> str:path = Path(dir_path)@@ -19,7 +21,7 @@ def zip_directory(dir_path: str) -> str:if file_path.is_symlink():continueif file_path.is_file():- if not file_path.resolve().is_relative_to(root):+ if not _path_is_relative_to(file_path.resolve(), root):continuearcname = str(file_path.relative_to(path)).replace("\\", "/")zipf.write(file_path, arcname=arcname)diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex 315ab9413..811fb9ff1 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -7,10 +7,19 @@ name = "openviking-sdk"dynamic = ["version"]description = "Lightweight Python HTTP SDK for OpenViking"readme = "README.md"-requires-python = ">=3.10"+requires-python = ">=3.8"dependencies = ["httpx>=0.25.0",]+classifiers = [+ "Programming Language :: Python :: 3",+ "Programming Language :: Python :: 3.8",+ "Programming Language :: Python :: 3.9",+ "Programming Language :: Python :: 3.10",+ "Programming Language :: Python :: 3.11",+ "Programming Language :: Python :: 3.12",+ "Programming Language :: Python :: 3.13",+][tool.setuptools]package-dir = {"" = "."}diff --git a/sdk/python/tests/test_actor_peer.py b/sdk/python/tests/test_actor_peer.pyindex 6cd7a0e5e..d616899fb 100644--- a/sdk/python/tests/test_actor_peer.py+++ b/sdk/python/tests/test_actor_peer.py@@ -1,3 +1,5 @@+from __future__ import annotations+import asynciofrom concurrent.futures import ThreadPoolExecutordiff --git a/sdk/python/tests/test_async_client_behaviors.py b/sdk/python/tests/test_async_client_behaviors.pyindex 020fc39a5..930f0fa1b 100644--- a/sdk/python/tests/test_async_client_behaviors.py+++ b/sdk/python/tests/test_async_client_behaviors.py@@ -456,15 +456,13 @@ def test_sync_http_client_reindex_forwards_to_async_client():def test_sync_http_client_forwards_tags_to_filesystem_methods():client = SyncHTTPClient(url="http://localhost:1933")- with (- patch.object(client._async_client, "ls", return_value=[]) as mock_ls,- patch.object(client._async_client, "tree", return_value=[]) as mock_tree,- patch.object(client._async_client, "grep", return_value={}) as mock_grep,- patch("openviking_sdk.client.run_async", side_effect=[[], [], {}]),- ):- client.ls("viking://resources", tags=["env=prod"])- client.tree("viking://resources", tags=["env=prod"])- client.grep("viking://resources", "Sample", tags=["env=prod"])+ with patch.object(client._async_client, "ls", return_value=[]) as mock_ls:+ with patch.object(client._async_client, "tree", return_value=[]) as mock_tree:+ with patch.object(client._async_client, "grep", return_value={}) as mock_grep:+ with patch("openviking_sdk.client.run_async", side_effect=[[], [], {}]):+ client.ls("viking://resources", tags=["env=prod"])+ client.tree("viking://resources", tags=["env=prod"])+ client.grep("viking://resources", "Sample", tags=["env=prod"])assert mock_ls.call_args.kwargs["tags"] == ["env=prod"]assert mock_tree.call_args.kwargs["tags"] == ["env=prod"]diff --git a/sdk/python/tests/test_utils.py b/sdk/python/tests/test_utils.pyindex dd204deb5..fc52eafc8 100644--- a/sdk/python/tests/test_utils.py+++ b/sdk/python/tests/test_utils.py@@ -1,7 +1,26 @@import asyncio+from pathlib import Pathimport pytest-from openviking_sdk._utils import run_async+from openviking_sdk import AsyncHTTPClient+from openviking_sdk._utils import _path_is_relative_to, run_async+from openviking_sdk.options import FindOptions+++def test_path_is_relative_to_handles_paths_outside_root():+ root = Path("/tmp/openviking-sdk-root")++ assert _path_is_relative_to(root / "nested" / "file.txt", root)+ assert not _path_is_relative_to(Path("/tmp/openviking-sdk-other"), root)+++def test_options_payload_uses_typed_dict_fields_on_supported_python_versions():+ payload = AsyncHTTPClient._build_options_payload(+ {"node_limit": 3},+ FindOptions,+ )++ assert payload == {"node_limit": 3}def test_run_async_reuses_worker_loop_across_sync_and_async_contexts():