knowledge2 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. knowledge2-0.4.0/.github/workflows/pypi-release.yml +104 -0
  2. knowledge2-0.4.0/AGENTS.md +31 -0
  3. knowledge2-0.4.0/CHANGELOG.md +79 -0
  4. knowledge2-0.4.0/PKG-INFO +556 -0
  5. knowledge2-0.4.0/README.md +528 -0
  6. knowledge2-0.4.0/__init__.py +70 -0
  7. knowledge2-0.4.0/_async_base.py +525 -0
  8. knowledge2-0.4.0/_async_paging.py +57 -0
  9. knowledge2-0.4.0/_base.py +541 -0
  10. knowledge2-0.4.0/_logging.py +41 -0
  11. knowledge2-0.4.0/_paging.py +73 -0
  12. knowledge2-0.4.0/_preview.py +70 -0
  13. knowledge2-0.4.0/_raw_response.py +25 -0
  14. knowledge2-0.4.0/_request_options.py +51 -0
  15. knowledge2-0.4.0/_transport.py +144 -0
  16. knowledge2-0.4.0/_validation.py +25 -0
  17. knowledge2-0.4.0/_validation_response.py +36 -0
  18. knowledge2-0.4.0/_version.py +3 -0
  19. knowledge2-0.4.0/async_client.py +320 -0
  20. knowledge2-0.4.0/async_resources/__init__.py +45 -0
  21. knowledge2-0.4.0/async_resources/_mixin_base.py +42 -0
  22. knowledge2-0.4.0/async_resources/a2a.py +230 -0
  23. knowledge2-0.4.0/async_resources/agents.py +489 -0
  24. knowledge2-0.4.0/async_resources/audit.py +145 -0
  25. knowledge2-0.4.0/async_resources/auth.py +133 -0
  26. knowledge2-0.4.0/async_resources/console.py +409 -0
  27. knowledge2-0.4.0/async_resources/corpora.py +276 -0
  28. knowledge2-0.4.0/async_resources/deployments.py +106 -0
  29. knowledge2-0.4.0/async_resources/documents.py +592 -0
  30. knowledge2-0.4.0/async_resources/feeds.py +248 -0
  31. knowledge2-0.4.0/async_resources/indexes.py +208 -0
  32. knowledge2-0.4.0/async_resources/jobs.py +165 -0
  33. knowledge2-0.4.0/async_resources/metadata.py +48 -0
  34. knowledge2-0.4.0/async_resources/models.py +102 -0
  35. knowledge2-0.4.0/async_resources/onboarding.py +538 -0
  36. knowledge2-0.4.0/async_resources/orgs.py +37 -0
  37. knowledge2-0.4.0/async_resources/pipelines.py +523 -0
  38. knowledge2-0.4.0/async_resources/projects.py +90 -0
  39. knowledge2-0.4.0/async_resources/search.py +262 -0
  40. knowledge2-0.4.0/async_resources/training.py +357 -0
  41. knowledge2-0.4.0/async_resources/usage.py +91 -0
  42. knowledge2-0.4.0/client.py +417 -0
  43. knowledge2-0.4.0/config.py +182 -0
  44. knowledge2-0.4.0/errors.py +178 -0
  45. knowledge2-0.4.0/examples/auth_factory.py +34 -0
  46. knowledge2-0.4.0/examples/batch_operations.py +57 -0
  47. knowledge2-0.4.0/examples/document_upload.py +56 -0
  48. knowledge2-0.4.0/examples/e2e_lifecycle.py +213 -0
  49. knowledge2-0.4.0/examples/error_handling.py +61 -0
  50. knowledge2-0.4.0/examples/pagination.py +64 -0
  51. knowledge2-0.4.0/examples/quickstart.py +36 -0
  52. knowledge2-0.4.0/examples/request_options.py +44 -0
  53. knowledge2-0.4.0/examples/search.py +64 -0
  54. knowledge2-0.4.0/integrations/__init__.py +57 -0
  55. knowledge2-0.4.0/integrations/_client.py +101 -0
  56. knowledge2-0.4.0/integrations/langchain/__init__.py +6 -0
  57. knowledge2-0.4.0/integrations/langchain/retriever.py +166 -0
  58. knowledge2-0.4.0/integrations/langchain/tools.py +108 -0
  59. knowledge2-0.4.0/integrations/llamaindex/__init__.py +11 -0
  60. knowledge2-0.4.0/integrations/llamaindex/filters.py +78 -0
  61. knowledge2-0.4.0/integrations/llamaindex/retriever.py +162 -0
  62. knowledge2-0.4.0/integrations/llamaindex/tools.py +109 -0
  63. knowledge2-0.4.0/integrations/llamaindex/vector_store.py +320 -0
  64. knowledge2-0.4.0/knowledge2.egg-info/PKG-INFO +556 -0
  65. knowledge2-0.4.0/knowledge2.egg-info/SOURCES.txt +281 -0
  66. knowledge2-0.4.0/knowledge2.egg-info/dependency_links.txt +1 -0
  67. knowledge2-0.4.0/knowledge2.egg-info/requires.txt +10 -0
  68. knowledge2-0.4.0/knowledge2.egg-info/top_level.txt +1 -0
  69. knowledge2-0.4.0/models/__init__.py +18 -0
  70. knowledge2-0.4.0/models/_base.py +24 -0
  71. knowledge2-0.4.0/models/_registry.py +457 -0
  72. knowledge2-0.4.0/models/a2a.py +92 -0
  73. knowledge2-0.4.0/models/agents.py +109 -0
  74. knowledge2-0.4.0/models/audit.py +28 -0
  75. knowledge2-0.4.0/models/auth.py +49 -0
  76. knowledge2-0.4.0/models/chunks.py +20 -0
  77. knowledge2-0.4.0/models/common.py +14 -0
  78. knowledge2-0.4.0/models/console.py +103 -0
  79. knowledge2-0.4.0/models/corpora.py +48 -0
  80. knowledge2-0.4.0/models/deployments.py +13 -0
  81. knowledge2-0.4.0/models/documents.py +126 -0
  82. knowledge2-0.4.0/models/embeddings.py +24 -0
  83. knowledge2-0.4.0/models/evaluation.py +17 -0
  84. knowledge2-0.4.0/models/feedback.py +9 -0
  85. knowledge2-0.4.0/models/feeds.py +57 -0
  86. knowledge2-0.4.0/models/indexes.py +36 -0
  87. knowledge2-0.4.0/models/jobs.py +52 -0
  88. knowledge2-0.4.0/models/models.py +26 -0
  89. knowledge2-0.4.0/models/onboarding.py +323 -0
  90. knowledge2-0.4.0/models/orgs.py +11 -0
  91. knowledge2-0.4.0/models/pipelines.py +147 -0
  92. knowledge2-0.4.0/models/projects.py +19 -0
  93. knowledge2-0.4.0/models/search.py +149 -0
  94. knowledge2-0.4.0/models/training.py +57 -0
  95. knowledge2-0.4.0/models/usage.py +39 -0
  96. knowledge2-0.4.0/namespaces.py +386 -0
  97. knowledge2-0.4.0/py.typed +0 -0
  98. knowledge2-0.4.0/pyproject.toml +56 -0
  99. knowledge2-0.4.0/resources/__init__.py +45 -0
  100. knowledge2-0.4.0/resources/_mixin_base.py +40 -0
  101. knowledge2-0.4.0/resources/a2a.py +230 -0
  102. knowledge2-0.4.0/resources/agents.py +487 -0
  103. knowledge2-0.4.0/resources/audit.py +144 -0
  104. knowledge2-0.4.0/resources/auth.py +138 -0
  105. knowledge2-0.4.0/resources/console.py +411 -0
  106. knowledge2-0.4.0/resources/corpora.py +269 -0
  107. knowledge2-0.4.0/resources/deployments.py +105 -0
  108. knowledge2-0.4.0/resources/documents.py +597 -0
  109. knowledge2-0.4.0/resources/feeds.py +246 -0
  110. knowledge2-0.4.0/resources/indexes.py +210 -0
  111. knowledge2-0.4.0/resources/jobs.py +164 -0
  112. knowledge2-0.4.0/resources/metadata.py +53 -0
  113. knowledge2-0.4.0/resources/models.py +99 -0
  114. knowledge2-0.4.0/resources/onboarding.py +542 -0
  115. knowledge2-0.4.0/resources/orgs.py +35 -0
  116. knowledge2-0.4.0/resources/pipeline_builder.py +257 -0
  117. knowledge2-0.4.0/resources/pipelines.py +520 -0
  118. knowledge2-0.4.0/resources/projects.py +87 -0
  119. knowledge2-0.4.0/resources/search.py +277 -0
  120. knowledge2-0.4.0/resources/training.py +358 -0
  121. knowledge2-0.4.0/resources/usage.py +92 -0
  122. knowledge2-0.4.0/setup.cfg +4 -0
  123. knowledge2-0.4.0/specification.md +129 -0
  124. knowledge2-0.4.0/types/__init__.py +366 -0
  125. knowledge2-0.4.0/types/a2a.py +88 -0
  126. knowledge2-0.4.0/types/agents.py +133 -0
  127. knowledge2-0.4.0/types/audit.py +26 -0
  128. knowledge2-0.4.0/types/auth.py +45 -0
  129. knowledge2-0.4.0/types/chunks.py +18 -0
  130. knowledge2-0.4.0/types/common.py +10 -0
  131. knowledge2-0.4.0/types/console.py +99 -0
  132. knowledge2-0.4.0/types/corpora.py +42 -0
  133. knowledge2-0.4.0/types/deployments.py +11 -0
  134. knowledge2-0.4.0/types/documents.py +104 -0
  135. knowledge2-0.4.0/types/embeddings.py +22 -0
  136. knowledge2-0.4.0/types/evaluation.py +15 -0
  137. knowledge2-0.4.0/types/feedback.py +7 -0
  138. knowledge2-0.4.0/types/feeds.py +61 -0
  139. knowledge2-0.4.0/types/indexes.py +30 -0
  140. knowledge2-0.4.0/types/jobs.py +50 -0
  141. knowledge2-0.4.0/types/models.py +22 -0
  142. knowledge2-0.4.0/types/onboarding.py +395 -0
  143. knowledge2-0.4.0/types/orgs.py +9 -0
  144. knowledge2-0.4.0/types/pipelines.py +177 -0
  145. knowledge2-0.4.0/types/projects.py +14 -0
  146. knowledge2-0.4.0/types/search.py +116 -0
  147. knowledge2-0.4.0/types/training.py +55 -0
  148. knowledge2-0.4.0/types/usage.py +37 -0
@@ -0,0 +1,104 @@
1
+ name: pypi-release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "py-sdk-v*.*.*"
7
+
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+
12
+ jobs:
13
+ build-test-publish:
14
+ runs-on: ubuntu-24.04
15
+ environment: pypi-publish
16
+ steps:
17
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18
+
19
+ - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
20
+ with:
21
+ python-version: "3.11"
22
+
23
+ - name: Install build dependencies
24
+ run: |
25
+ python -I -m pip install \
26
+ "setuptools>=68.0" \
27
+ setuptools-scm \
28
+ wheel \
29
+ build==1.2.2.post1 \
30
+ twine==6.1.0
31
+
32
+ - name: Version guard
33
+ run: |
34
+ TAG_VERSION="${GITHUB_REF_NAME#py-sdk-v}"
35
+ PKG_VERSION=$(python -I -c "
36
+ import re, pathlib, sys
37
+ text = pathlib.Path('pyproject.toml').read_text()
38
+ m = re.search(r'^version\s*=\s*\"(.+?)\"', text, re.MULTILINE)
39
+ if not m:
40
+ print('ERROR: Could not find version in pyproject.toml', file=sys.stderr)
41
+ sys.exit(1)
42
+ print(m.group(1))
43
+ ")
44
+ echo "Tag version: ${TAG_VERSION}"
45
+ echo "Package version: ${PKG_VERSION}"
46
+ if [ "${TAG_VERSION}" != "${PKG_VERSION}" ]; then
47
+ echo "::error::Tag version (${TAG_VERSION}) does not match pyproject.toml version (${PKG_VERSION})"
48
+ exit 1
49
+ fi
50
+
51
+ - name: Publish metadata guard
52
+ run: |
53
+ python -I - <<'PY'
54
+ import pathlib
55
+ import sys
56
+ import tomllib
57
+
58
+ project = tomllib.loads(pathlib.Path("pyproject.toml").read_text(encoding="utf-8"))["project"]
59
+ urls = project.get("urls", {})
60
+ expected = {
61
+ "Repository": "https://github.com/knowledge2-ai/knowledge2-python-sdk",
62
+ "Changelog": "https://github.com/knowledge2-ai/knowledge2-python-sdk/blob/main/CHANGELOG.md",
63
+ }
64
+ for key, value in expected.items():
65
+ if key not in urls:
66
+ print(f"::error::{key} URL missing from pyproject.toml")
67
+ sys.exit(1)
68
+ if urls[key] != value:
69
+ print(
70
+ f"::error::{key} URL must be {value}, found {urls[key]}",
71
+ )
72
+ sys.exit(1)
73
+ PY
74
+
75
+ - name: Build package
76
+ run: python -I -m build --no-isolation . --outdir dist/
77
+
78
+ - name: Metadata guard
79
+ run: twine check dist/*
80
+
81
+ - name: Smoke test
82
+ run: |
83
+ python -I -m venv /tmp/smoke-test
84
+ python -I - <<'PY' >/tmp/smoke-test-requirements.txt
85
+ import pathlib
86
+ import tomllib
87
+
88
+ project = tomllib.loads(pathlib.Path("pyproject.toml").read_text(encoding="utf-8"))["project"]
89
+ for dependency in project.get("dependencies", []):
90
+ print(dependency)
91
+ PY
92
+ if [ -s /tmp/smoke-test-requirements.txt ]; then
93
+ /tmp/smoke-test/bin/python -I -m pip install -r /tmp/smoke-test-requirements.txt
94
+ fi
95
+ /tmp/smoke-test/bin/python -I -m pip install --no-index --find-links dist/ --no-deps dist/*.whl
96
+ /tmp/smoke-test/bin/python -I -c "from sdk import Knowledge2; print(Knowledge2)"
97
+
98
+ - name: Hide stdlib-shadowing package for publish action
99
+ run: mv types _types_publish_hidden
100
+
101
+ - name: Publish to PyPI
102
+ uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3
103
+ with:
104
+ packages-dir: dist/
@@ -0,0 +1,31 @@
1
+ # AGENTS.md
2
+
3
+ ## Scope
4
+ - This file documents the Python SDK in isolation; assume no context from other folders.
5
+ - For system-level architecture and deployment strategy, read `../AGENTS.md` and `../docs/flux_release_branches.md`.
6
+
7
+ ## Repo release strategy (deployment-impacting changes)
8
+ - Promotion is merge-forward only: `dev` -> `staging` -> `prod`.
9
+ - Flux branch wiring and overlay mapping are documented in `../docs/flux_release_branches.md`.
10
+ - Keep environment config isolated (Auth0 tenant/domain/client, callback URLs, and secrets must remain environment-specific).
11
+
12
+ ## What this library is
13
+ - Minimal Python client for the API service.
14
+ - Used by external apps and examples to call the REST API.
15
+
16
+ ## Entry point
17
+ - Client: `sdk/client.py`.
18
+
19
+ ## Key files
20
+ - `sdk/_base.py`: HTTP plumbing and shared request logic.
21
+ - `sdk/types/`: data model types for responses.
22
+ - `sdk/errors.py`: exception types.
23
+ - `sdk/examples/`: runnable usage samples.
24
+
25
+ ## External dependencies (treat as contracts)
26
+ - Expects API base URL and `X-API-Key` auth.
27
+ - API request/response shapes must match server endpoints.
28
+
29
+ ## When changing this library
30
+ - Keep backwards compatibility for public client methods.
31
+ - If the API contract changes, update `sdk/types/` and regenerate examples.
@@ -0,0 +1,79 @@
1
+ # Changelog
2
+
3
+ All notable changes to the Knowledge2 Python SDK will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.0] - 2026-03-30
9
+
10
+ ### Added
11
+
12
+ - **Async parallel uploads**: `upload_documents_parallel()` on `AsyncDocumentsMixin`, bringing parity with the sync client.
13
+ - **Typed response models**: New response types for agents (`sdk/types/agents.py`), feeds (`sdk/types/feeds.py`), and pipelines (`sdk/types/pipelines.py`).
14
+ - **Comprehensive unit tests**: 339 unit tests covering all SDK resource modules.
15
+ - **PyPI release pipeline**: Public-repo `pypi-release.yml` GitHub Actions workflow for automated publishing.
16
+ - **Python 3.13 classifier**: Added `Programming Language :: Python :: 3.13` to package metadata.
17
+ - **Changelog URL**: Added changelog link to `pyproject.toml` project URLs.
18
+ - Mark agents, feeds, pipelines, and A2A resources as preview — emits
19
+ `RuntimeWarning` on first call to indicate feature-flag dependency
20
+
21
+ ### Fixed
22
+
23
+ - **Python version badge**: README badge now correctly states Python 3.11+ (was 3.10+).
24
+
25
+ ## [0.2.0] - 2026-03-12
26
+
27
+ ### Added
28
+
29
+ - **`ClientTimeouts`** (#713): Per-phase HTTP timeout configuration (connect, read, write, pool). Accepts `ClientTimeouts` dataclass, `float`, or `httpx.Timeout`.
30
+ - **`require_str()` param guard** (#714): Validates non-empty, non-whitespace resource IDs at call site before API request.
31
+ - **SDK User-Agent** (#715): Auto-injected `User-Agent: k2-python-sdk/{version}` header on every request. Customizable via `user_agent` parameter.
32
+ - **`is_authenticated()` health check** (#716): Returns `True` if any auth credential (API key, bearer token, admin token, or factory) is configured.
33
+ - **`Page[T]` pagination** (#717): `list_*` methods return `Page[T]` frozen dataclass with `items`, `total`, `offset`, `limit`. Supports `len()`, iteration, and boolean check.
34
+ - **`SyncPager[T]`** (#717): Lazy paginator with `next_page()`, `iter_pages()`, and item-level iteration for `iter_*` methods.
35
+ - **`bearer_token_factory`** (#718): Callable-based dynamic auth for OAuth/OIDC. Thread-safe double-check locking with configurable `token_cache_ttl` (default 300s, 0 to disable). Auto-refreshes on 401.
36
+ - **Two-step delete guard** (#719): `delete_corpus()` requires `confirm=True` to execute. Raises `ValueError` if not confirmed.
37
+ - **`K2Config` frozen config** (#720): Pydantic-settings based configuration from environment variables (`K2_*` prefix), JSON/YAML files, or named profiles.
38
+ - **Sub-client namespaces** (#721): `client.documents.*`, `client.corpora.*`, `client.search_ns.*`, etc. Lightweight cached proxies — flat methods still work.
39
+ - **Parallel uploads** (#722): `upload_documents_parallel()` using `ThreadPoolExecutor` for concurrent document ingestion.
40
+ - **Pydantic response validation** (#723): Optional `validate_responses=True` or `Knowledge2Validated` class. Requires `pip install knowledge2[pydantic]`.
41
+ - **`AsyncKnowledge2` client** (#724): Native async client using `httpx.AsyncClient`. `AsyncPager[T]` for async pagination. Factory methods: `create()`, `from_env()`, `from_file()`, `from_profile()`.
42
+ - **`RequestOptions`** (#732): Per-call overrides for timeout, retries, and passthrough headers. `request_options` parameter on all public methods.
43
+ - **`with_raw_response`** (#733): `client.with_raw_response.<method>(...)` returns `RawResponse[T]` with `status_code`, `headers`, and `parsed` body. Thread-safe (sync) and task-safe (async).
44
+ - **Custom `httpx.Client` injection** (#734): `http_client` parameter for custom TLS, proxies, or observability middleware. Explicit ownership — SDK never closes caller-supplied clients.
45
+
46
+ ### Changed
47
+
48
+ - **`list_*` methods return `Page[T]`** instead of raw dicts. This is a breaking change for code that accessed the raw dict keys directly. Use `page.items` instead.
49
+
50
+ ## [0.1.0] - 2026-02-13
51
+
52
+ ### Added
53
+
54
+ - **Error hierarchy**: 10 exception types (`AuthenticationError`, `RateLimitError`,
55
+ `ServerError`, `APIConnectionError`, `APITimeoutError`, etc.) with `retryable`
56
+ property. All subclass `Knowledge2Error` for backward compatibility.
57
+ - **Automatic retry**: Exponential backoff with jitter for 5xx, 429, connection
58
+ errors, and timeouts. Configurable via `max_retries` (default: 2). Rate limit
59
+ 429 responses honor `Retry-After` header.
60
+ - **Pagination iterators**: `iter_*` methods for all paginated `list_*` endpoints
61
+ (e.g., `iter_documents`, `iter_corpora`, `iter_jobs`). Lazy page fetching.
62
+ - **Debug logging**: Logger named `knowledge2` with credential redaction.
63
+ `set_debug()` convenience method.
64
+ - **Typed config parameters**: Search methods accept TypedDict types
65
+ (`SearchHybridConfig`, `SearchRerankConfig`, etc.) alongside `dict[str, Any]`.
66
+ - **Comprehensive docstrings**: Google-style docstrings on all public methods.
67
+ - **Standalone package**: `pyproject.toml` for independent `pip install`.
68
+ - **SDK versioning**: `__version__` attribute and this changelog.
69
+ - **Focused examples**: Quick-start, search, document upload, error handling,
70
+ pagination, and batch operations examples.
71
+ - **Comprehensive README**: Installation, authentication, configuration, error
72
+ handling, pagination, and resource overview.
73
+
74
+ ### Changed
75
+
76
+ - `fetch_whoami()` renamed to `get_whoami()` for consistency. `fetch_whoami()`
77
+ is now a deprecated alias.
78
+ - `reconcile_jobs()` and `cancel_tuning_run()` return typed responses instead
79
+ of `dict[str, Any]`.