nodii-document-cloud-client 0.0.2__tar.gz → 0.2.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.
- nodii_document_cloud_client-0.2.0/.gitignore +89 -0
- nodii_document_cloud_client-0.2.0/LICENSE +15 -0
- nodii_document_cloud_client-0.2.0/PKG-INFO +15 -0
- nodii_document_cloud_client-0.2.0/README.md +17 -0
- nodii_document_cloud_client-0.2.0/pyproject.toml +68 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/__init__.py +45 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/body.py +72 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/client.py +387 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/errors.py +106 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/proto/nodii/document_cloud/v1/document_cloud.proto +445 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/proto.py +56 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/py.typed +1 -0
- nodii_document_cloud_client-0.2.0/src/nodii_document_cloud_client/upload_http.py +59 -0
- nodii_document_cloud_client-0.2.0/tests/test_integration.py +144 -0
- nodii_document_cloud_client-0.2.0/tests/test_parity_vectors.py +46 -0
- nodii_document_cloud_client-0.2.0/tests/test_unit.py +113 -0
- nodii_document_cloud_client-0.2.0/tests/test_upload_http.py +94 -0
- nodii_document_cloud_client-0.0.2/PKG-INFO +0 -11
- nodii_document_cloud_client-0.0.2/README.md +0 -3
- nodii_document_cloud_client-0.0.2/pyproject.toml +0 -14
- nodii_document_cloud_client-0.0.2/src/nodii_document_cloud_client/__init__.py +0 -2
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
build/
|
|
4
|
+
coverage/
|
|
5
|
+
.DS_Store
|
|
6
|
+
*.log
|
|
7
|
+
.env
|
|
8
|
+
.env.local
|
|
9
|
+
.env.*.local
|
|
10
|
+
.turbo/
|
|
11
|
+
.bun/
|
|
12
|
+
|
|
13
|
+
# AI review loop artifacts (scripts/review/ai-review.ts)
|
|
14
|
+
.claude-pre-review.md
|
|
15
|
+
.claude-pre-review.json
|
|
16
|
+
.claude/pending-patches/
|
|
17
|
+
# Review-tooling scratch. `scripts/review/ai-review.ts` writes a snapshot of
|
|
18
|
+
# the diff under review into .claude/ on every run; a `git add -A` then commits
|
|
19
|
+
# a copy of the PR into the PR. Seven of these were already tracked on main
|
|
20
|
+
# before this rule existed — untracking those is a separate cleanup.
|
|
21
|
+
.claude/claim-audit-diff-*.patch
|
|
22
|
+
.claude/review-diff-*.patch
|
|
23
|
+
.claude/review-claude-last.json
|
|
24
|
+
|
|
25
|
+
# Agent session state (not committed; per-session)
|
|
26
|
+
.claude/endpoints-snapshot.json
|
|
27
|
+
.agent-todo.md
|
|
28
|
+
|
|
29
|
+
# Python (uv)
|
|
30
|
+
.venv/
|
|
31
|
+
__pycache__/
|
|
32
|
+
*.pyc
|
|
33
|
+
*.pyo
|
|
34
|
+
*.egg-info/
|
|
35
|
+
.mypy_cache/
|
|
36
|
+
.ruff_cache/
|
|
37
|
+
.pytest_cache/
|
|
38
|
+
htmlcov/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage.*
|
|
41
|
+
coverage.xml
|
|
42
|
+
|
|
43
|
+
# Go
|
|
44
|
+
*.test
|
|
45
|
+
*.out
|
|
46
|
+
go.work.sum
|
|
47
|
+
|
|
48
|
+
# Generated proto artifacts (regenerate via `bun proto:gen`)
|
|
49
|
+
ts/_generated/
|
|
50
|
+
python/_generated/
|
|
51
|
+
go/_generated/
|
|
52
|
+
|
|
53
|
+
# Test-stack volumes (docker-compose persistent data)
|
|
54
|
+
infra/test-stack/data/
|
|
55
|
+
# synthetic consumer go binaries
|
|
56
|
+
synthetic-consumers/telemetry/go/nodii-synthetic-telemetry
|
|
57
|
+
synthetic-consumers/pii/go/nodii-synthetic-pii
|
|
58
|
+
synthetic-consumers/auth-sdk/go/nodii-synthetic-auth-sdk
|
|
59
|
+
.claude-claim-audit.md
|
|
60
|
+
.claude-claim-audit.json
|
|
61
|
+
|
|
62
|
+
# Compiled synthetic-consumer Go binaries — CLASS RULE, not a name list.
|
|
63
|
+
#
|
|
64
|
+
# `go build` / `go run .` in synthetic-consumers/<lib>/go/ emits a binary named
|
|
65
|
+
# after the directory or the module's last path element, which the `*.test` /
|
|
66
|
+
# `*.out` rules above do not match. The rules here used to name them one at a
|
|
67
|
+
# time (role-catalog, nodii-synthetic-telemetry, nodii-synthetic-pii,
|
|
68
|
+
# nodii-synthetic-auth-sdk, plus a `*/[a-z]*-go` glob) and that is exactly how
|
|
69
|
+
# FOUR of them ended up committed anyway, 77 MB in total:
|
|
70
|
+
#
|
|
71
|
+
# synthetic-consumers/audit-chain/go/audit-chain 13 MB
|
|
72
|
+
# synthetic-consumers/replica-consumer/go/replica-consumer 14 MB
|
|
73
|
+
# synthetic-consumers/grpc-interceptors/go/nodii-synthetic-grpc-... 22 MB
|
|
74
|
+
# synthetic-consumers/bean-app-cluster/go/auth-svc/bean-auth-svc-go 26 MB
|
|
75
|
+
#
|
|
76
|
+
# The last of those DID match the old `*/[a-z]*-go` glob — a rule cannot save a
|
|
77
|
+
# file that was already tracked when it landed, which is why they were removed
|
|
78
|
+
# with `git rm --cached` in the same commit as this rule.
|
|
79
|
+
#
|
|
80
|
+
# HOW IT WORKS: every real source file under these directories has an extension
|
|
81
|
+
# (.go, .mod, .sum) — verified, zero tracked extensionless files under
|
|
82
|
+
# synthetic-consumers/*/go/ — so "extensionless file" is a sound proxy for
|
|
83
|
+
# "build artefact". Directories and any dotted filename are re-included, so
|
|
84
|
+
# cmd/, internal/ and friends keep working. Naming a NEW binary can no longer
|
|
85
|
+
# defeat it; that was the whole failure mode.
|
|
86
|
+
synthetic-consumers/**/go/**
|
|
87
|
+
!synthetic-consumers/**/go/**/
|
|
88
|
+
!synthetic-consumers/**/go/**/*.*
|
|
89
|
+
!synthetic-consumers/**/go/*.*
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Nodii
|
|
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.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: nodii-document-cloud-client
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Authenticated Document Cloud client with replay-safe direct object-store uploads
|
|
5
|
+
Project-URL: Homepage, https://github.com/cognion-nucleus/nodii-libs
|
|
6
|
+
Project-URL: Repository, https://github.com/cognion-nucleus/nodii-libs
|
|
7
|
+
Author-email: Nodii <ops@nodii.co>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: grpcio-tools>=1.60
|
|
12
|
+
Requires-Dist: grpcio>=1.60
|
|
13
|
+
Requires-Dist: httpx>=0.27
|
|
14
|
+
Requires-Dist: nodii-grpc-auth>=0.16.0
|
|
15
|
+
Requires-Dist: protobuf>=4.25
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# nodii-document-cloud-client
|
|
2
|
+
|
|
3
|
+
The Python twin of `@nodii/document-cloud-client`. It authenticates every RPC,
|
|
4
|
+
streams upload hashing to bounded storage, and sends document bytes directly to
|
|
5
|
+
the signed object-store URL.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
client = create_document_cloud_client(address=DOCUMENT_CLOUD,
|
|
9
|
+
get_s2s_token=get_token, tenant_id=tenant_id, service_name="hr")
|
|
10
|
+
result = await client.upload_document(folder_path="HR/Payslips/2026",
|
|
11
|
+
title="October payslip", body=payslip, content_type="application/pdf",
|
|
12
|
+
idempotency_key=f"payslip:{employee_id}:2026-10", contexts=[{
|
|
13
|
+
"context_kind": "hr.employee", "context_ref": employee_id,
|
|
14
|
+
"source_type": "api",
|
|
15
|
+
}])
|
|
16
|
+
await client.close()
|
|
17
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "nodii-document-cloud-client"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Authenticated Document Cloud client with replay-safe direct object-store uploads"
|
|
5
|
+
requires-python = ">=3.11"
|
|
6
|
+
license = { text = "MIT" }
|
|
7
|
+
authors = [{ name = "Nodii", email = "ops@nodii.co" }]
|
|
8
|
+
dependencies = [
|
|
9
|
+
"grpcio>=1.60",
|
|
10
|
+
"grpcio-tools>=1.60",
|
|
11
|
+
"httpx>=0.27",
|
|
12
|
+
"nodii-grpc-auth>=0.16.0",
|
|
13
|
+
"protobuf>=4.25",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[tool.uv.sources]
|
|
17
|
+
nodii-grpc-auth = { workspace = true }
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/cognion-nucleus/nodii-libs"
|
|
21
|
+
Repository = "https://github.com/cognion-nucleus/nodii-libs"
|
|
22
|
+
|
|
23
|
+
[build-system]
|
|
24
|
+
requires = ["hatchling"]
|
|
25
|
+
build-backend = "hatchling.build"
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.wheel]
|
|
28
|
+
packages = ["src/nodii_document_cloud_client"]
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.sdist]
|
|
31
|
+
include = ["src/", "tests/", "README.md", "LICENSE", "pyproject.toml"]
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.sdist.force-include]
|
|
34
|
+
"../../ts/grpc-interfaces/proto/nodii/document_cloud/v1/document_cloud.proto" = "src/nodii_document_cloud_client/proto/nodii/document_cloud/v1/document_cloud.proto"
|
|
35
|
+
|
|
36
|
+
[dependency-groups]
|
|
37
|
+
dev = [
|
|
38
|
+
"boto3>=1.35",
|
|
39
|
+
"mypy>=1.13",
|
|
40
|
+
"pytest>=8.3",
|
|
41
|
+
"pytest-asyncio>=0.24",
|
|
42
|
+
"ruff>=0.7",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[tool.ruff]
|
|
46
|
+
line-length = 100
|
|
47
|
+
target-version = "py311"
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint]
|
|
50
|
+
select = ["E", "W", "F", "I", "B", "C4", "UP", "N", "ASYNC", "S", "PT", "RET", "SIM"]
|
|
51
|
+
ignore = ["S101"]
|
|
52
|
+
|
|
53
|
+
[tool.ruff.lint.per-file-ignores]
|
|
54
|
+
"tests/**/*.py" = ["S101", "S105", "S106", "B017", "PT011"]
|
|
55
|
+
"tests/test_integration.py" = ["N802"]
|
|
56
|
+
|
|
57
|
+
[tool.mypy]
|
|
58
|
+
strict = true
|
|
59
|
+
python_version = "3.11"
|
|
60
|
+
|
|
61
|
+
[[tool.mypy.overrides]]
|
|
62
|
+
module = ["grpc", "grpc.*", "grpc_tools", "grpc_tools.*", "google.protobuf", "google.protobuf.*"]
|
|
63
|
+
ignore_missing_imports = true
|
|
64
|
+
|
|
65
|
+
[tool.pytest.ini_options]
|
|
66
|
+
testpaths = ["tests"]
|
|
67
|
+
asyncio_mode = "auto"
|
|
68
|
+
addopts = ["-ra", "--strict-markers", "--strict-config"]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from .client import (
|
|
2
|
+
DocumentCloudClient,
|
|
3
|
+
UploadResult,
|
|
4
|
+
create_document_cloud_client,
|
|
5
|
+
validate_contexts,
|
|
6
|
+
)
|
|
7
|
+
from .errors import (
|
|
8
|
+
ChecksumMismatchError,
|
|
9
|
+
ContextRefLooksLikePiiError,
|
|
10
|
+
DocumentCloudConflictError,
|
|
11
|
+
DocumentCloudError,
|
|
12
|
+
DocumentCloudInvalidArgumentError,
|
|
13
|
+
DocumentCloudNotFoundError,
|
|
14
|
+
DocumentCloudPermissionDeniedError,
|
|
15
|
+
DocumentCloudPreconditionError,
|
|
16
|
+
DocumentCloudUnauthenticatedError,
|
|
17
|
+
DocumentCloudUnavailableError,
|
|
18
|
+
S3UnavailableError,
|
|
19
|
+
SizeMismatchError,
|
|
20
|
+
UploadAbortedError,
|
|
21
|
+
UploadHttpError,
|
|
22
|
+
UploadTimeoutError,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"ChecksumMismatchError",
|
|
27
|
+
"ContextRefLooksLikePiiError",
|
|
28
|
+
"DocumentCloudClient",
|
|
29
|
+
"DocumentCloudConflictError",
|
|
30
|
+
"DocumentCloudError",
|
|
31
|
+
"DocumentCloudInvalidArgumentError",
|
|
32
|
+
"DocumentCloudNotFoundError",
|
|
33
|
+
"DocumentCloudPermissionDeniedError",
|
|
34
|
+
"DocumentCloudPreconditionError",
|
|
35
|
+
"DocumentCloudUnauthenticatedError",
|
|
36
|
+
"DocumentCloudUnavailableError",
|
|
37
|
+
"S3UnavailableError",
|
|
38
|
+
"SizeMismatchError",
|
|
39
|
+
"UploadAbortedError",
|
|
40
|
+
"UploadHttpError",
|
|
41
|
+
"UploadResult",
|
|
42
|
+
"UploadTimeoutError",
|
|
43
|
+
"create_document_cloud_client",
|
|
44
|
+
"validate_contexts",
|
|
45
|
+
]
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import hashlib
|
|
5
|
+
import os
|
|
6
|
+
import tempfile
|
|
7
|
+
from collections.abc import AsyncIterable, AsyncIterator, Iterable
|
|
8
|
+
from contextlib import suppress
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import BinaryIO, TypeAlias
|
|
12
|
+
|
|
13
|
+
DocumentBody: TypeAlias = (
|
|
14
|
+
bytes | bytearray | memoryview | BinaryIO | Iterable[bytes] | AsyncIterable[bytes]
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(slots=True)
|
|
19
|
+
class PreparedBody:
|
|
20
|
+
size_bytes: int
|
|
21
|
+
checksum_sha256: str
|
|
22
|
+
_bytes: bytes | None = None
|
|
23
|
+
_path: Path | None = None
|
|
24
|
+
|
|
25
|
+
def open(self) -> BinaryIO:
|
|
26
|
+
if self._path is not None:
|
|
27
|
+
return self._path.open("rb")
|
|
28
|
+
from io import BytesIO
|
|
29
|
+
|
|
30
|
+
return BytesIO(self._bytes or b"")
|
|
31
|
+
|
|
32
|
+
def cleanup(self) -> None:
|
|
33
|
+
if self._path is not None:
|
|
34
|
+
self._path.unlink(missing_ok=True)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def _chunks(body: DocumentBody) -> AsyncIterator[bytes]:
|
|
38
|
+
if isinstance(body, (bytes, bytearray, memoryview)):
|
|
39
|
+
yield bytes(body)
|
|
40
|
+
elif hasattr(body, "__aiter__"):
|
|
41
|
+
async for chunk in body:
|
|
42
|
+
yield bytes(chunk)
|
|
43
|
+
elif hasattr(body, "read"):
|
|
44
|
+
while chunk := await asyncio.to_thread(body.read, 1024 * 1024):
|
|
45
|
+
yield bytes(chunk)
|
|
46
|
+
else:
|
|
47
|
+
for chunk in body:
|
|
48
|
+
yield bytes(chunk)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
async def prepare_body(body: DocumentBody, declared_size: int | None = None) -> PreparedBody:
|
|
52
|
+
if isinstance(body, (bytes, bytearray, memoryview)):
|
|
53
|
+
data = bytes(body)
|
|
54
|
+
if declared_size is not None and declared_size != len(data):
|
|
55
|
+
raise ValueError(f"size_bytes {declared_size} does not match body size {len(data)}")
|
|
56
|
+
return PreparedBody(len(data), hashlib.sha256(data).hexdigest(), _bytes=data)
|
|
57
|
+
fd, name = tempfile.mkstemp(prefix="nodii-document-cloud-")
|
|
58
|
+
digest = hashlib.sha256()
|
|
59
|
+
size = 0
|
|
60
|
+
try:
|
|
61
|
+
with os.fdopen(fd, "wb") as target:
|
|
62
|
+
async for chunk in _chunks(body):
|
|
63
|
+
digest.update(chunk)
|
|
64
|
+
size += len(chunk)
|
|
65
|
+
target.write(chunk)
|
|
66
|
+
if declared_size is not None and declared_size != size:
|
|
67
|
+
raise ValueError(f"size_bytes {declared_size} does not match body size {size}")
|
|
68
|
+
return PreparedBody(size, digest.hexdigest(), _path=Path(name))
|
|
69
|
+
except BaseException:
|
|
70
|
+
with suppress(FileNotFoundError):
|
|
71
|
+
os.unlink(name)
|
|
72
|
+
raise
|