omnigraph 0.14.0a1__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.
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ checks:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ python-version: ["3.11", "3.12", "3.13"]
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: astral-sh/setup-uv@v6
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+ - run: uv sync --locked
23
+ - run: uv run ruff check .
24
+ - run: uv run ruff format --check .
25
+ - run: uv run mypy
26
+ - run: uv run python scripts/generate.py --check
27
+ - run: uv run pytest
28
+
29
+ e2e:
30
+ # Against the checksum-verified server release the SDK is pinned to.
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - uses: astral-sh/setup-uv@v6
35
+ with:
36
+ python-version: "3.12"
37
+ - run: uv sync --locked
38
+ - name: Install omnigraph-server
39
+ run: |
40
+ version=$(uv run python -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['tool']['omnigraph']['server-version'])")
41
+ base="https://github.com/ModernRelay/omnigraph/releases/download/v${version}"
42
+ mkdir -p "$RUNNER_TEMP/og" && cd "$RUNNER_TEMP/og"
43
+ curl -sSfL -o og.tar.gz "$base/omnigraph-linux-x86_64.tar.gz"
44
+ curl -sSfL -o og.sha256 "$base/omnigraph-linux-x86_64.sha256"
45
+ sed -i 's/omnigraph-linux-x86_64.tar.gz/og.tar.gz/' og.sha256
46
+ sha256sum -c og.sha256
47
+ tar xzf og.tar.gz omnigraph omnigraph-server
48
+ echo "OMNIGRAPH_BIN_DIR=$RUNNER_TEMP/og" >> "$GITHUB_ENV"
49
+ - run: uv run pytest tests/test_e2e.py
50
+ env:
51
+ OMNIGRAPH_TEST_SERVER: "1"
@@ -0,0 +1,40 @@
1
+ name: Release
2
+
3
+ # Publishes to PyPI through trusted publishing when a `v*` tag is pushed.
4
+ # Configure the PyPI project's trusted publisher for this repository and the
5
+ # `pypi` environment first; no API token is stored anywhere.
6
+ on:
7
+ push:
8
+ tags: ["v*"]
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: astral-sh/setup-uv@v6
19
+ - name: Check the tag matches the package version
20
+ run: |
21
+ version=$(uv run python -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
22
+ test "v${version}" = "${GITHUB_REF_NAME}"
23
+ - run: uv build
24
+ - uses: actions/upload-artifact@v4
25
+ with:
26
+ name: dist
27
+ path: dist/
28
+
29
+ publish:
30
+ needs: build
31
+ runs-on: ubuntu-latest
32
+ environment: pypi
33
+ permissions:
34
+ id-token: write
35
+ steps:
36
+ - uses: actions/download-artifact@v4
37
+ with:
38
+ name: dist
39
+ path: dist/
40
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ .mypy_cache/
6
+ .pytest_cache/
7
+ .ruff_cache/
@@ -0,0 +1,17 @@
1
+ # AGENTS.md
2
+
3
+ Python SDK for the Omnigraph HTTP API. Reference implementation: `ModernRelay/omnigraph-ts`
4
+ (`packages/sdk`), pinned to the same server release. Match its behaviour (contract header,
5
+ discovery, no retries, no redirects, receipt validation, error classes); use Python idioms
6
+ for names and shapes.
7
+
8
+ - The server version lives in `pyproject.toml` `[tool.omnigraph] server-version`. Bumping it:
9
+ `scripts/sync_spec.py`, then `scripts/generate.py`, then run the e2e suite against that
10
+ release's binaries.
11
+ - `src/omnigraph/_models.py` and `_version.py` are generated; never edit them by hand.
12
+ `scripts/generate.py --check` must pass.
13
+ - Public results are the generated `TypedDict`s; do not rename wire fields.
14
+ - Never add automatic retries. A lost write response is `outcome_unknown`, not a retry signal.
15
+ - Runtime dependency: `httpx` only.
16
+ - Checks: `uv run pytest`, `uv run mypy`, `uv run ruff check .`, `uv run ruff format --check .`;
17
+ e2e with `OMNIGRAPH_TEST_SERVER=1 OMNIGRAPH_BIN_DIR=...` (needs a free local port).
@@ -0,0 +1 @@
1
+ AGENTS.md
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Omnigraph Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.5
2
+ Name: omnigraph
3
+ Version: 0.14.0a1
4
+ Summary: Python client for the Omnigraph HTTP API
5
+ Project-URL: Homepage, https://github.com/ModernRelay/omnigraph-python
6
+ Project-URL: Issues, https://github.com/ModernRelay/omnigraph/issues
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Framework :: AsyncIO
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.11
14
+ Requires-Dist: httpx<1,>=0.27
15
+ Description-Content-Type: text/markdown
16
+
17
+ # omnigraph
18
+
19
+ Async Python client for the [Omnigraph](https://github.com/ModernRelay/omnigraph) HTTP API,
20
+ contract **0.14**. It mirrors the TypeScript SDK
21
+ [`@modernrelay/omnigraph`](https://github.com/ModernRelay/omnigraph-ts): the same routes, the
22
+ same contract checks, and the same error model, with Python names.
23
+
24
+ ```sh
25
+ pip install omnigraph
26
+ ```
27
+
28
+ ## Connect and query
29
+
30
+ ```python
31
+ from omnigraph import Omnigraph
32
+
33
+ async with Omnigraph("http://127.0.0.1:8080", graph_id="knowledge", token=TOKEN) as og:
34
+ result = await og.query(
35
+ "query find($name: String) { match { $p: Person { name: $name } } return { $p.name, $p.age } }",
36
+ params={"name": "Alice"},
37
+ )
38
+ print(result["rows"], result["graph_commit_id"])
39
+ ```
40
+
41
+ `base_url` is the server root, including any proxy prefix. Select a graph with `graph_id` or
42
+ `og.graph("beta")`, which shares the connection pool. Results are the server's JSON as
43
+ `TypedDict`s generated from the server's OpenAPI document; field names are the wire names.
44
+ Rows omit null-valued fields.
45
+
46
+ Every request carries `Omnigraph-Http-Api: 0.14`, every response is checked for it, and a
47
+ `HEAD /healthz` discovery precedes each data request. The client follows no redirects and
48
+ never retries. Upgrade the server and this package together: the SDK minor tracks the server
49
+ minor.
50
+
51
+ ## Write and verify
52
+
53
+ ```python
54
+ changed = await og.mutate(
55
+ "query rename($old: String, $name: String) { update Person set { name: $name } where name = $old }",
56
+ params={"old": "Alice", "name": "Alicia"},
57
+ if_graph_commit=result["graph_commit_id"],
58
+ )
59
+ ```
60
+
61
+ A successful mutation returns its commit receipt; `commit: None` is a successful no-op. With
62
+ `if_graph_commit` the conditional route refuses a moved head with `PreconditionFailedError`.
63
+
64
+ Branches, merges, and unpublished commits:
65
+
66
+ ```python
67
+ await og.branches.create("review")
68
+ await og.mutate(insert_query, params=..., branch="review")
69
+ merged = await og.branches.merge("review", delete_branch=True)
70
+ ```
71
+
72
+ Merge and mutation receipts are validated; a receipt that does not name the requested
73
+ operation raises `ApiContractError`.
74
+
75
+ ## Streams, loads, feeds, and blobs
76
+
77
+ ```python
78
+ # NDJSON, not buffered
79
+ async for row in og.export(type_names=["Person"]):
80
+ ...
81
+ # One commit, up to 32 MiB
82
+ await og.load_ndjson(ndjson_text, branch="main", mode="merge")
83
+ # One bounded feed page
84
+ page = await og.changes.poll(start="beginning", limit=100)
85
+ # A snapshot, then {"baseline": ...}
86
+ async for record in og.changes.baseline():
87
+ ...
88
+ await og.blobs.put(b"...", entity="node", type="Doc", id="d1", property="body")
89
+ await og.queries.invoke("people", params={"name": "Ada"})
90
+ ```
91
+
92
+ Ordinary JSON requests are limited to 1 MiB by the server; bulk loads go through
93
+ `load_ndjson`.
94
+
95
+ ## Errors
96
+
97
+ Every error is an `OmnigraphError` subclass chosen by status and `code` (`ConflictError`,
98
+ `PreconditionFailedError`, `PayloadTooLargeError`, `GraphUnavailableError`, ...). Each carries:
99
+
100
+ - `disposition`: the server's `effects` (`none`, `partial`, `unknown`) and next `action`;
101
+ - `request_dispatched`: whether the request may have reached the server;
102
+ - `outcome_unknown`: a write may have taken effect — reconcile before retrying.
103
+
104
+ The token never appears in a `repr` or an error message.
105
+
106
+ ## Cluster deployments
107
+
108
+ `og.cluster.plan/apply/status/get_deployment` submit and observe captured deployment bundles.
109
+ Bundles are opaque here, as in the TypeScript SDK; for operator work use
110
+ `omnigraph cluster plan/apply --target NAME --config DIR`.
111
+
112
+ ## Development
113
+
114
+ ```sh
115
+ uv sync
116
+ uv run pytest # unit tests (mocked transport)
117
+ OMNIGRAPH_TEST_SERVER=1 OMNIGRAPH_BIN_DIR=/path/to/v0.14.0 uv run pytest tests/test_e2e.py
118
+ uv run python scripts/generate.py --check # generated files match spec/openapi.json
119
+ uv run mypy && uv run ruff check . && uv run ruff format --check .
120
+ ```
121
+
122
+ `spec/openapi.json` is the pinned server release's document (`scripts/sync_spec.py` fetches it
123
+ for the version in `[tool.omnigraph]`); `scripts/generate.py` regenerates `_models.py` and
124
+ `_version.py` from it.
@@ -0,0 +1,108 @@
1
+ # omnigraph
2
+
3
+ Async Python client for the [Omnigraph](https://github.com/ModernRelay/omnigraph) HTTP API,
4
+ contract **0.14**. It mirrors the TypeScript SDK
5
+ [`@modernrelay/omnigraph`](https://github.com/ModernRelay/omnigraph-ts): the same routes, the
6
+ same contract checks, and the same error model, with Python names.
7
+
8
+ ```sh
9
+ pip install omnigraph
10
+ ```
11
+
12
+ ## Connect and query
13
+
14
+ ```python
15
+ from omnigraph import Omnigraph
16
+
17
+ async with Omnigraph("http://127.0.0.1:8080", graph_id="knowledge", token=TOKEN) as og:
18
+ result = await og.query(
19
+ "query find($name: String) { match { $p: Person { name: $name } } return { $p.name, $p.age } }",
20
+ params={"name": "Alice"},
21
+ )
22
+ print(result["rows"], result["graph_commit_id"])
23
+ ```
24
+
25
+ `base_url` is the server root, including any proxy prefix. Select a graph with `graph_id` or
26
+ `og.graph("beta")`, which shares the connection pool. Results are the server's JSON as
27
+ `TypedDict`s generated from the server's OpenAPI document; field names are the wire names.
28
+ Rows omit null-valued fields.
29
+
30
+ Every request carries `Omnigraph-Http-Api: 0.14`, every response is checked for it, and a
31
+ `HEAD /healthz` discovery precedes each data request. The client follows no redirects and
32
+ never retries. Upgrade the server and this package together: the SDK minor tracks the server
33
+ minor.
34
+
35
+ ## Write and verify
36
+
37
+ ```python
38
+ changed = await og.mutate(
39
+ "query rename($old: String, $name: String) { update Person set { name: $name } where name = $old }",
40
+ params={"old": "Alice", "name": "Alicia"},
41
+ if_graph_commit=result["graph_commit_id"],
42
+ )
43
+ ```
44
+
45
+ A successful mutation returns its commit receipt; `commit: None` is a successful no-op. With
46
+ `if_graph_commit` the conditional route refuses a moved head with `PreconditionFailedError`.
47
+
48
+ Branches, merges, and unpublished commits:
49
+
50
+ ```python
51
+ await og.branches.create("review")
52
+ await og.mutate(insert_query, params=..., branch="review")
53
+ merged = await og.branches.merge("review", delete_branch=True)
54
+ ```
55
+
56
+ Merge and mutation receipts are validated; a receipt that does not name the requested
57
+ operation raises `ApiContractError`.
58
+
59
+ ## Streams, loads, feeds, and blobs
60
+
61
+ ```python
62
+ # NDJSON, not buffered
63
+ async for row in og.export(type_names=["Person"]):
64
+ ...
65
+ # One commit, up to 32 MiB
66
+ await og.load_ndjson(ndjson_text, branch="main", mode="merge")
67
+ # One bounded feed page
68
+ page = await og.changes.poll(start="beginning", limit=100)
69
+ # A snapshot, then {"baseline": ...}
70
+ async for record in og.changes.baseline():
71
+ ...
72
+ await og.blobs.put(b"...", entity="node", type="Doc", id="d1", property="body")
73
+ await og.queries.invoke("people", params={"name": "Ada"})
74
+ ```
75
+
76
+ Ordinary JSON requests are limited to 1 MiB by the server; bulk loads go through
77
+ `load_ndjson`.
78
+
79
+ ## Errors
80
+
81
+ Every error is an `OmnigraphError` subclass chosen by status and `code` (`ConflictError`,
82
+ `PreconditionFailedError`, `PayloadTooLargeError`, `GraphUnavailableError`, ...). Each carries:
83
+
84
+ - `disposition`: the server's `effects` (`none`, `partial`, `unknown`) and next `action`;
85
+ - `request_dispatched`: whether the request may have reached the server;
86
+ - `outcome_unknown`: a write may have taken effect — reconcile before retrying.
87
+
88
+ The token never appears in a `repr` or an error message.
89
+
90
+ ## Cluster deployments
91
+
92
+ `og.cluster.plan/apply/status/get_deployment` submit and observe captured deployment bundles.
93
+ Bundles are opaque here, as in the TypeScript SDK; for operator work use
94
+ `omnigraph cluster plan/apply --target NAME --config DIR`.
95
+
96
+ ## Development
97
+
98
+ ```sh
99
+ uv sync
100
+ uv run pytest # unit tests (mocked transport)
101
+ OMNIGRAPH_TEST_SERVER=1 OMNIGRAPH_BIN_DIR=/path/to/v0.14.0 uv run pytest tests/test_e2e.py
102
+ uv run python scripts/generate.py --check # generated files match spec/openapi.json
103
+ uv run mypy && uv run ruff check . && uv run ruff format --check .
104
+ ```
105
+
106
+ `spec/openapi.json` is the pinned server release's document (`scripts/sync_spec.py` fetches it
107
+ for the version in `[tool.omnigraph]`); `scripts/generate.py` regenerates `_models.py` and
108
+ `_version.py` from it.
@@ -0,0 +1,54 @@
1
+ [project]
2
+ name = "omnigraph"
3
+ version = "0.14.0a1"
4
+ description = "Python client for the Omnigraph HTTP API"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.11"
9
+ dependencies = ["httpx>=0.27,<1"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Framework :: AsyncIO",
13
+ "Programming Language :: Python :: 3",
14
+ "Typing :: Typed",
15
+ ]
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/ModernRelay/omnigraph-python"
19
+ Issues = "https://github.com/ModernRelay/omnigraph/issues"
20
+
21
+ [tool.omnigraph]
22
+ # The server release this SDK is generated from and tested against. The SDK
23
+ # minor tracks the server minor; `spec/openapi.json` is that release's file.
24
+ server-version = "0.14.0"
25
+
26
+ [dependency-groups]
27
+ dev = [
28
+ "pytest>=8",
29
+ "pytest-asyncio>=0.24",
30
+ "mypy>=1.11",
31
+ "ruff>=0.6",
32
+ "datamodel-code-generator==0.34.0",
33
+ ]
34
+
35
+ [build-system]
36
+ requires = ["hatchling>=1.26"]
37
+ build-backend = "hatchling.build"
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src/omnigraph"]
41
+
42
+ [tool.pytest.ini_options]
43
+ asyncio_mode = "auto"
44
+ asyncio_default_fixture_loop_scope = "function"
45
+ testpaths = ["tests"]
46
+
47
+ [tool.mypy]
48
+ python_version = "3.11"
49
+ strict = true
50
+ files = ["src", "tests", "scripts"]
51
+
52
+ [tool.ruff]
53
+ line-length = 88
54
+ extend-exclude = ["src/omnigraph/_models.py"]
@@ -0,0 +1,96 @@
1
+ """Regenerate `src/omnigraph/_models.py` and `_version.py` from the pinned spec.
2
+
3
+ uv run python scripts/generate.py # write
4
+ uv run python scripts/generate.py --check # fail when the files are stale
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import subprocess
11
+ import sys
12
+ import tempfile
13
+ import tomllib
14
+ from pathlib import Path
15
+
16
+ ROOT = Path(__file__).resolve().parents[1]
17
+ SPEC = ROOT / "spec" / "openapi.json"
18
+ MODELS = ROOT / "src" / "omnigraph" / "_models.py"
19
+ VERSION = ROOT / "src" / "omnigraph" / "_version.py"
20
+
21
+ HEADER = '''\
22
+ """Wire models generated from spec/openapi.json. Do not edit by hand.
23
+
24
+ Regenerate with `uv run python scripts/generate.py`.
25
+ """
26
+
27
+ '''
28
+
29
+
30
+ def server_version() -> str:
31
+ data = tomllib.loads((ROOT / "pyproject.toml").read_text())
32
+ return str(data["tool"]["omnigraph"]["server-version"])
33
+
34
+
35
+ def render_models() -> str:
36
+ with tempfile.TemporaryDirectory() as tmp:
37
+ out = Path(tmp) / "models.py"
38
+ subprocess.run(
39
+ [
40
+ "datamodel-codegen",
41
+ "--input",
42
+ str(SPEC),
43
+ "--input-file-type",
44
+ "openapi",
45
+ "--output-model-type",
46
+ "typing.TypedDict",
47
+ "--target-python-version",
48
+ "3.11",
49
+ "--use-standard-collections",
50
+ "--use-union-operator",
51
+ "--enum-field-as-literal",
52
+ "all",
53
+ "--use-schema-description",
54
+ "--disable-timestamp",
55
+ "--output",
56
+ str(out),
57
+ ],
58
+ check=True,
59
+ )
60
+ body = out.read_text()
61
+ # Drop the generator's own banner; ours names the source and the command.
62
+ lines = body.splitlines(keepends=True)
63
+ while lines and (lines[0].startswith("#") or not lines[0].strip()):
64
+ lines.pop(0)
65
+ return HEADER + "".join(lines)
66
+
67
+
68
+ def render_version() -> str:
69
+ spec_version = json.loads(SPEC.read_text())["info"]["version"]
70
+ pinned = server_version()
71
+ if spec_version != pinned:
72
+ sys.exit(f"spec/openapi.json is {spec_version}, pyproject pins {pinned}")
73
+ major, minor, _ = pinned.split(".")
74
+ return (
75
+ '"""Generated by scripts/generate.py. Do not edit by hand."""\n\n'
76
+ f'SERVER_VERSION = "{pinned}"\n'
77
+ f'HTTP_API_CONTRACT = "{major}.{minor}"\n'
78
+ 'HTTP_API_CONTRACT_HEADER = "Omnigraph-Http-Api"\n'
79
+ )
80
+
81
+
82
+ def main() -> None:
83
+ check = "--check" in sys.argv[1:]
84
+ stale = []
85
+ for path, text in ((MODELS, render_models()), (VERSION, render_version())):
86
+ if check:
87
+ if not path.exists() or path.read_text() != text:
88
+ stale.append(path.relative_to(ROOT))
89
+ else:
90
+ path.write_text(text)
91
+ if stale:
92
+ sys.exit(f"stale generated files: {', '.join(map(str, stale))}")
93
+
94
+
95
+ if __name__ == "__main__":
96
+ main()
@@ -0,0 +1,23 @@
1
+ """Replace spec/openapi.json with the one from the pinned server release.
2
+
3
+ uv run python scripts/sync_spec.py
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import sys
9
+ import urllib.request
10
+
11
+ from generate import SPEC, server_version
12
+
13
+
14
+ def main() -> None:
15
+ tag = f"v{server_version()}"
16
+ url = f"https://raw.githubusercontent.com/ModernRelay/omnigraph/{tag}/openapi.json"
17
+ with urllib.request.urlopen(url, timeout=60) as resp:
18
+ SPEC.write_bytes(resp.read())
19
+ print(f"spec/openapi.json <- {url}", file=sys.stderr)
20
+
21
+
22
+ if __name__ == "__main__":
23
+ main()