prismax 0.1.0__py3-none-any.whl
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.
- prismax/__init__.py +28 -0
- prismax/cli.py +107 -0
- prismax/client.py +158 -0
- prismax/errors.py +14 -0
- prismax/manifest.py +36 -0
- prismax/scanner.py +191 -0
- prismax/upload.py +240 -0
- prismax-0.1.0.dist-info/METADATA +203 -0
- prismax-0.1.0.dist-info/RECORD +13 -0
- prismax-0.1.0.dist-info/WHEEL +5 -0
- prismax-0.1.0.dist-info/entry_points.txt +2 -0
- prismax-0.1.0.dist-info/licenses/LICENSE +132 -0
- prismax-0.1.0.dist-info/top_level.txt +1 -0
prismax/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from .client import PrismaXClient
|
|
2
|
+
from .errors import (
|
|
3
|
+
PrismaxApiError,
|
|
4
|
+
PrismaxAuthError,
|
|
5
|
+
PrismaxError,
|
|
6
|
+
PrismaxValidationError,
|
|
7
|
+
)
|
|
8
|
+
from .scanner import episode_keys, scan_folder, select_primary_video_paths, validate_mcap_mp4
|
|
9
|
+
from .upload import resume, status, upload, wait_for_upload
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"PrismaXClient",
|
|
15
|
+
"PrismaxApiError",
|
|
16
|
+
"PrismaxAuthError",
|
|
17
|
+
"PrismaxError",
|
|
18
|
+
"PrismaxValidationError",
|
|
19
|
+
"__version__",
|
|
20
|
+
"episode_keys",
|
|
21
|
+
"resume",
|
|
22
|
+
"scan_folder",
|
|
23
|
+
"select_primary_video_paths",
|
|
24
|
+
"status",
|
|
25
|
+
"upload",
|
|
26
|
+
"validate_mcap_mp4",
|
|
27
|
+
"wait_for_upload",
|
|
28
|
+
]
|
prismax/cli.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from .errors import PrismaxError
|
|
6
|
+
from .upload import resume, status, upload
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _print_json(payload):
|
|
10
|
+
print(json.dumps(payload, indent=2, default=str))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(argv=None):
|
|
14
|
+
parser = argparse.ArgumentParser(prog="prismax")
|
|
15
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
16
|
+
|
|
17
|
+
upload_parser = subparsers.add_parser("upload")
|
|
18
|
+
upload_parser.add_argument("folder")
|
|
19
|
+
upload_parser.add_argument("--task-id", required=True, type=int)
|
|
20
|
+
upload_parser.add_argument("--serial-number", required=True)
|
|
21
|
+
upload_parser.add_argument("--api-key")
|
|
22
|
+
upload_parser.add_argument("--base-url")
|
|
23
|
+
upload_parser.add_argument("--wait", action="store_true")
|
|
24
|
+
upload_parser.add_argument("--max-wait", type=int, default=1800)
|
|
25
|
+
upload_parser.add_argument("--poll-interval", type=int, default=10)
|
|
26
|
+
upload_parser.add_argument("--timeout", type=int, default=60)
|
|
27
|
+
upload_parser.add_argument("--retries", type=int, default=3)
|
|
28
|
+
upload_parser.add_argument("--max-poll-errors", type=int, default=3)
|
|
29
|
+
upload_parser.add_argument("--concurrency", type=int, default=5)
|
|
30
|
+
|
|
31
|
+
resume_parser = subparsers.add_parser("resume")
|
|
32
|
+
resume_parser.add_argument("upload_id", type=int)
|
|
33
|
+
resume_parser.add_argument("folder")
|
|
34
|
+
resume_parser.add_argument("--api-key")
|
|
35
|
+
resume_parser.add_argument("--base-url")
|
|
36
|
+
resume_parser.add_argument("--wait", action="store_true")
|
|
37
|
+
resume_parser.add_argument("--max-wait", type=int, default=1800)
|
|
38
|
+
resume_parser.add_argument("--poll-interval", type=int, default=10)
|
|
39
|
+
resume_parser.add_argument("--timeout", type=int, default=60)
|
|
40
|
+
resume_parser.add_argument("--retries", type=int, default=3)
|
|
41
|
+
resume_parser.add_argument("--max-poll-errors", type=int, default=3)
|
|
42
|
+
resume_parser.add_argument("--concurrency", type=int, default=5)
|
|
43
|
+
|
|
44
|
+
status_parser = subparsers.add_parser("status")
|
|
45
|
+
status_parser.add_argument("upload_id", type=int)
|
|
46
|
+
status_parser.add_argument("--api-key")
|
|
47
|
+
status_parser.add_argument("--base-url")
|
|
48
|
+
status_parser.add_argument("--timeout", type=int, default=60)
|
|
49
|
+
status_parser.add_argument("--retries", type=int, default=3)
|
|
50
|
+
|
|
51
|
+
args = parser.parse_args(argv)
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
if args.command == "upload":
|
|
55
|
+
result = upload(
|
|
56
|
+
args.folder,
|
|
57
|
+
task_id=args.task_id,
|
|
58
|
+
serial_number=args.serial_number,
|
|
59
|
+
api_key=args.api_key,
|
|
60
|
+
base_url=args.base_url,
|
|
61
|
+
wait=args.wait,
|
|
62
|
+
poll_interval=args.poll_interval,
|
|
63
|
+
max_wait=args.max_wait,
|
|
64
|
+
max_poll_errors=args.max_poll_errors,
|
|
65
|
+
timeout=args.timeout,
|
|
66
|
+
concurrency=args.concurrency,
|
|
67
|
+
retries=args.retries,
|
|
68
|
+
)
|
|
69
|
+
_print_json(result)
|
|
70
|
+
return 0
|
|
71
|
+
|
|
72
|
+
if args.command == "resume":
|
|
73
|
+
result = resume(
|
|
74
|
+
args.upload_id,
|
|
75
|
+
args.folder,
|
|
76
|
+
api_key=args.api_key,
|
|
77
|
+
base_url=args.base_url,
|
|
78
|
+
wait=args.wait,
|
|
79
|
+
poll_interval=args.poll_interval,
|
|
80
|
+
max_wait=args.max_wait,
|
|
81
|
+
max_poll_errors=args.max_poll_errors,
|
|
82
|
+
timeout=args.timeout,
|
|
83
|
+
concurrency=args.concurrency,
|
|
84
|
+
retries=args.retries,
|
|
85
|
+
)
|
|
86
|
+
_print_json(result)
|
|
87
|
+
return 0
|
|
88
|
+
|
|
89
|
+
if args.command == "status":
|
|
90
|
+
_print_json(status(
|
|
91
|
+
args.upload_id,
|
|
92
|
+
api_key=args.api_key,
|
|
93
|
+
base_url=args.base_url,
|
|
94
|
+
timeout=args.timeout,
|
|
95
|
+
retries=args.retries,
|
|
96
|
+
))
|
|
97
|
+
return 0
|
|
98
|
+
except PrismaxError as exc:
|
|
99
|
+
print(f"prismax: {exc}", file=sys.stderr)
|
|
100
|
+
return 1
|
|
101
|
+
|
|
102
|
+
parser.error(f"Unknown command: {args.command}")
|
|
103
|
+
return 2
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
if __name__ == "__main__":
|
|
107
|
+
raise SystemExit(main())
|
prismax/client.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
from urllib.parse import urlparse
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
from .errors import PrismaxApiError, PrismaxAuthError, PrismaxValidationError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
DEFAULT_BASE_URL = "https://data.prismaxserver.com"
|
|
14
|
+
LOCAL_HOSTS = {"127.0.0.1", "localhost", "::1"}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _sdk_version():
|
|
18
|
+
try:
|
|
19
|
+
return version("prismax")
|
|
20
|
+
except PackageNotFoundError:
|
|
21
|
+
return "0.1.0"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _validate_base_url(base_url):
|
|
25
|
+
parsed = urlparse(base_url)
|
|
26
|
+
if parsed.scheme not in ("http", "https"):
|
|
27
|
+
raise PrismaxValidationError(
|
|
28
|
+
f"base_url must start with https:// (got: {base_url!r})."
|
|
29
|
+
)
|
|
30
|
+
host = parsed.hostname or ""
|
|
31
|
+
if parsed.scheme != "https" and host not in LOCAL_HOSTS:
|
|
32
|
+
raise PrismaxValidationError(
|
|
33
|
+
"base_url must use https:// for non-local hosts "
|
|
34
|
+
f"(got: {base_url!r}). Plain http is only allowed for localhost."
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class PrismaXClient:
|
|
39
|
+
def __init__(self, api_key=None, base_url=None, timeout=60, concurrency=5, retries=3):
|
|
40
|
+
self.api_key = api_key or os.getenv("PRISMAX_API_KEY")
|
|
41
|
+
if not self.api_key:
|
|
42
|
+
raise PrismaxAuthError("api_key is required or PRISMAX_API_KEY must be set.")
|
|
43
|
+
self.base_url = (base_url or DEFAULT_BASE_URL).rstrip("/")
|
|
44
|
+
_validate_base_url(self.base_url)
|
|
45
|
+
self.timeout = timeout
|
|
46
|
+
self.concurrency = max(1, int(concurrency))
|
|
47
|
+
self.retries = max(1, int(retries))
|
|
48
|
+
|
|
49
|
+
def _headers(self):
|
|
50
|
+
return {
|
|
51
|
+
"X-API-Key": self.api_key,
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
"User-Agent": f"prismax-sdk/{_sdk_version()}",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
def _request(self, method, path, **kwargs):
|
|
57
|
+
url = f"{self.base_url}{path}"
|
|
58
|
+
try:
|
|
59
|
+
response = requests.request(
|
|
60
|
+
method,
|
|
61
|
+
url,
|
|
62
|
+
headers=self._headers(),
|
|
63
|
+
timeout=self.timeout,
|
|
64
|
+
**kwargs,
|
|
65
|
+
)
|
|
66
|
+
except requests.RequestException as exc:
|
|
67
|
+
raise PrismaxApiError(f"PrismaX API request failed: {exc}") from exc
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
payload = response.json()
|
|
71
|
+
except ValueError:
|
|
72
|
+
payload = {"success": False, "msg": response.text}
|
|
73
|
+
|
|
74
|
+
if not response.ok or payload.get("success") is False:
|
|
75
|
+
message = payload.get("msg") or payload.get("error") or f"PrismaX API request failed: {response.status_code}"
|
|
76
|
+
if response.status_code in (401, 403):
|
|
77
|
+
raise PrismaxAuthError(message)
|
|
78
|
+
raise PrismaxApiError(message)
|
|
79
|
+
return payload.get("data", payload)
|
|
80
|
+
|
|
81
|
+
def create_upload_session(self, *, task_id, serial_number, files):
|
|
82
|
+
return self._request(
|
|
83
|
+
"POST",
|
|
84
|
+
"/v1/data/upload-sessions",
|
|
85
|
+
json={
|
|
86
|
+
"task_id": task_id,
|
|
87
|
+
"serial_number": serial_number,
|
|
88
|
+
"files": files,
|
|
89
|
+
},
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def resume_upload_session(self, *, upload_id, files):
|
|
93
|
+
return self._request(
|
|
94
|
+
"POST",
|
|
95
|
+
f"/v1/data/upload-sessions/{upload_id}/resume",
|
|
96
|
+
json={"files": files},
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def get_upload(self, upload_id):
|
|
100
|
+
return self._request("GET", f"/v1/data/uploads/{upload_id}")
|
|
101
|
+
|
|
102
|
+
def upload_file_to_signed_url(self, *, signed_url, path, content_type, relative_path=None):
|
|
103
|
+
display_path = relative_path or path
|
|
104
|
+
for attempt in range(1, self.retries + 1):
|
|
105
|
+
try:
|
|
106
|
+
with open(path, "rb") as handle:
|
|
107
|
+
response = requests.put(
|
|
108
|
+
signed_url,
|
|
109
|
+
data=handle,
|
|
110
|
+
headers={"Content-Type": content_type or "application/octet-stream"},
|
|
111
|
+
timeout=self.timeout,
|
|
112
|
+
)
|
|
113
|
+
if response.ok:
|
|
114
|
+
return
|
|
115
|
+
message = f"Upload failed with status {response.status_code}: {response.text[:200]}"
|
|
116
|
+
except requests.RequestException as exc:
|
|
117
|
+
message = str(exc)
|
|
118
|
+
|
|
119
|
+
if attempt == self.retries:
|
|
120
|
+
raise PrismaxApiError(f"Failed to upload {display_path}: {message}")
|
|
121
|
+
time.sleep(min(2 ** attempt, 10))
|
|
122
|
+
|
|
123
|
+
def upload_json_to_signed_url(self, *, signed_url, payload):
|
|
124
|
+
body = json.dumps(payload, indent=2).encode("utf-8")
|
|
125
|
+
for attempt in range(1, self.retries + 1):
|
|
126
|
+
try:
|
|
127
|
+
response = requests.put(
|
|
128
|
+
signed_url,
|
|
129
|
+
data=body,
|
|
130
|
+
headers={"Content-Type": "application/json"},
|
|
131
|
+
timeout=self.timeout,
|
|
132
|
+
)
|
|
133
|
+
if response.ok:
|
|
134
|
+
return
|
|
135
|
+
message = f"Manifest upload failed with status {response.status_code}: {response.text[:200]}"
|
|
136
|
+
except requests.RequestException as exc:
|
|
137
|
+
message = str(exc)
|
|
138
|
+
|
|
139
|
+
if attempt == self.retries:
|
|
140
|
+
raise PrismaxApiError(message)
|
|
141
|
+
time.sleep(min(2 ** attempt, 10))
|
|
142
|
+
|
|
143
|
+
def upload_files(self, upload_items):
|
|
144
|
+
if not upload_items:
|
|
145
|
+
return
|
|
146
|
+
with ThreadPoolExecutor(max_workers=self.concurrency) as executor:
|
|
147
|
+
futures = [
|
|
148
|
+
executor.submit(
|
|
149
|
+
self.upload_file_to_signed_url,
|
|
150
|
+
signed_url=item["signed_url"],
|
|
151
|
+
path=item["path"],
|
|
152
|
+
content_type=item["content_type"],
|
|
153
|
+
relative_path=item.get("relative_path"),
|
|
154
|
+
)
|
|
155
|
+
for item in upload_items
|
|
156
|
+
]
|
|
157
|
+
for future in as_completed(futures):
|
|
158
|
+
future.result()
|
prismax/errors.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class PrismaxError(Exception):
|
|
2
|
+
"""Base SDK error."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PrismaxAuthError(PrismaxError):
|
|
6
|
+
"""Raised when an API key is missing or rejected."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PrismaxValidationError(PrismaxError):
|
|
10
|
+
"""Raised when local upload input is invalid."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PrismaxApiError(PrismaxError):
|
|
14
|
+
"""Raised when the PrismaX API returns an error."""
|
prismax/manifest.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from datetime import datetime, timezone
|
|
2
|
+
|
|
3
|
+
from .scanner import LocalFile
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def manifest_placeholder(episode_key: str) -> dict:
|
|
7
|
+
return {
|
|
8
|
+
"relative_path": f"{episode_key}/_MANIFEST.json",
|
|
9
|
+
"size_bytes": None,
|
|
10
|
+
"content_type": "application/json",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_manifest_payload(
|
|
15
|
+
*,
|
|
16
|
+
episode_key: str,
|
|
17
|
+
upload_id,
|
|
18
|
+
machine_id,
|
|
19
|
+
task_id,
|
|
20
|
+
files: list[LocalFile],
|
|
21
|
+
) -> dict:
|
|
22
|
+
episode_files = []
|
|
23
|
+
for item in files:
|
|
24
|
+
relative_path = item.relative_path
|
|
25
|
+
if relative_path == f"{episode_key}.mcap" or relative_path.startswith(f"{episode_key}/"):
|
|
26
|
+
episode_files.append(item.as_api_payload())
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
"manifest_version": 1,
|
|
30
|
+
"upload_id": upload_id,
|
|
31
|
+
"episode_key": episode_key,
|
|
32
|
+
"machine_id": machine_id,
|
|
33
|
+
"task_id": task_id,
|
|
34
|
+
"created_at_utc": datetime.now(timezone.utc).isoformat(),
|
|
35
|
+
"files": episode_files,
|
|
36
|
+
}
|
prismax/scanner.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import mimetypes
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from .errors import PrismaxValidationError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
MANIFEST_FILENAME = "_MANIFEST.json"
|
|
9
|
+
MIN_VIDEO_COUNT = 3
|
|
10
|
+
VIDEO_SLOTS = ("env", "left", "right")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class LocalFile:
|
|
15
|
+
relative_path: str
|
|
16
|
+
path: Path
|
|
17
|
+
size_bytes: int
|
|
18
|
+
content_type: str
|
|
19
|
+
|
|
20
|
+
def as_api_payload(self):
|
|
21
|
+
return {
|
|
22
|
+
"relative_path": self.relative_path,
|
|
23
|
+
"size_bytes": self.size_bytes,
|
|
24
|
+
"content_type": self.content_type,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _content_type(path: Path) -> str:
|
|
29
|
+
suffix = path.suffix.lower()
|
|
30
|
+
if suffix == ".mp4":
|
|
31
|
+
return "video/mp4"
|
|
32
|
+
if suffix == ".json":
|
|
33
|
+
return "application/json"
|
|
34
|
+
guessed, _ = mimetypes.guess_type(str(path))
|
|
35
|
+
return guessed or "application/octet-stream"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _video_slot(file_name: str) -> str:
|
|
39
|
+
normalized = file_name.lower()
|
|
40
|
+
if "left" in normalized:
|
|
41
|
+
return "left"
|
|
42
|
+
if "right" in normalized:
|
|
43
|
+
return "right"
|
|
44
|
+
return "env"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _primary_sort_key(file_name: str, slot: str):
|
|
48
|
+
base_name = Path(str(file_name or "")).name.lower()
|
|
49
|
+
stem = base_name.rsplit(".", 1)[0]
|
|
50
|
+
exact_primary = {
|
|
51
|
+
"env": {"high", "env"},
|
|
52
|
+
"left": {"left"},
|
|
53
|
+
"right": {"right"},
|
|
54
|
+
}
|
|
55
|
+
return (0 if stem in exact_primary.get(slot, set()) else 1, base_name)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _is_hidden_path(path: Path) -> bool:
|
|
59
|
+
return any(part.startswith(".") for part in path.parts)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def select_primary_video_paths(video_paths: list[str]) -> dict[str, str]:
|
|
63
|
+
"""Return the deterministic primary env/left/right paths from a list of mp4 paths."""
|
|
64
|
+
grouped = {slot: [] for slot in VIDEO_SLOTS}
|
|
65
|
+
for path in video_paths:
|
|
66
|
+
if not str(path).endswith(".mp4"):
|
|
67
|
+
continue
|
|
68
|
+
slot = _video_slot(Path(str(path)).name)
|
|
69
|
+
grouped[slot].append(path)
|
|
70
|
+
selected = {}
|
|
71
|
+
for slot in VIDEO_SLOTS:
|
|
72
|
+
candidates = sorted(grouped[slot], key=lambda item: _primary_sort_key(Path(str(item)).name, slot))
|
|
73
|
+
if candidates:
|
|
74
|
+
selected[slot] = candidates[0]
|
|
75
|
+
return selected
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def scan_folder(folder) -> list[LocalFile]:
|
|
79
|
+
root = Path(folder).expanduser().resolve()
|
|
80
|
+
if not root.exists():
|
|
81
|
+
raise PrismaxValidationError(f"Folder does not exist: {root}")
|
|
82
|
+
if not root.is_dir():
|
|
83
|
+
raise PrismaxValidationError(f"Path must be a folder: {root}")
|
|
84
|
+
|
|
85
|
+
files = []
|
|
86
|
+
for path in sorted(root.rglob("*")):
|
|
87
|
+
if not path.is_file():
|
|
88
|
+
continue
|
|
89
|
+
relative_path = path.relative_to(root).as_posix()
|
|
90
|
+
if _is_hidden_path(Path(relative_path)):
|
|
91
|
+
continue
|
|
92
|
+
if relative_path == MANIFEST_FILENAME or relative_path.endswith(f"/{MANIFEST_FILENAME}"):
|
|
93
|
+
continue
|
|
94
|
+
files.append(LocalFile(
|
|
95
|
+
relative_path=relative_path,
|
|
96
|
+
path=path,
|
|
97
|
+
size_bytes=path.stat().st_size,
|
|
98
|
+
content_type=_content_type(path),
|
|
99
|
+
))
|
|
100
|
+
|
|
101
|
+
if not files:
|
|
102
|
+
raise PrismaxValidationError("No uploadable files found.")
|
|
103
|
+
return files
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def validate_mcap_mp4(files: list[LocalFile]) -> list[str]:
|
|
107
|
+
errors = []
|
|
108
|
+
stats = {}
|
|
109
|
+
|
|
110
|
+
def ensure_episode(episode_key):
|
|
111
|
+
if episode_key not in stats:
|
|
112
|
+
stats[episode_key] = {
|
|
113
|
+
"mcap_count": 0,
|
|
114
|
+
"mp4_count": 0,
|
|
115
|
+
"video_paths": [],
|
|
116
|
+
}
|
|
117
|
+
return stats[episode_key]
|
|
118
|
+
|
|
119
|
+
for item in files:
|
|
120
|
+
relative_path = item.relative_path
|
|
121
|
+
if "/" in relative_path:
|
|
122
|
+
parts = relative_path.split("/")
|
|
123
|
+
if len(parts) != 2:
|
|
124
|
+
errors.append(f"Nested folders are not allowed: {relative_path}")
|
|
125
|
+
continue
|
|
126
|
+
folder_name, file_name = parts
|
|
127
|
+
if not folder_name or not file_name:
|
|
128
|
+
errors.append(f"Invalid path: {relative_path}")
|
|
129
|
+
continue
|
|
130
|
+
if folder_name.endswith(".mcap"):
|
|
131
|
+
errors.append(f"Video folder name must not end with .mcap: {folder_name}")
|
|
132
|
+
continue
|
|
133
|
+
if not file_name.endswith(".mp4"):
|
|
134
|
+
errors.append(f"Only .mp4 files are allowed inside episode folders: {relative_path}")
|
|
135
|
+
continue
|
|
136
|
+
episode_stats = ensure_episode(folder_name)
|
|
137
|
+
episode_stats["mp4_count"] += 1
|
|
138
|
+
episode_stats["video_paths"].append(relative_path)
|
|
139
|
+
continue
|
|
140
|
+
|
|
141
|
+
if relative_path.endswith(".mcap"):
|
|
142
|
+
episode_key = relative_path[:-5]
|
|
143
|
+
if not episode_key:
|
|
144
|
+
errors.append(f"Invalid .mcap filename at root: {relative_path}")
|
|
145
|
+
continue
|
|
146
|
+
ensure_episode(episode_key)["mcap_count"] += 1
|
|
147
|
+
continue
|
|
148
|
+
|
|
149
|
+
errors.append(f"Only .mcap files are allowed at root: {relative_path}")
|
|
150
|
+
|
|
151
|
+
episode_keys = sorted(stats.keys())
|
|
152
|
+
if not episode_keys:
|
|
153
|
+
errors.append(
|
|
154
|
+
"No valid episodes found. Expected {episode}.mcap at root and at least "
|
|
155
|
+
"3 .mp4 files under {episode}/."
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
for episode_key in episode_keys:
|
|
159
|
+
episode_stats = stats[episode_key]
|
|
160
|
+
if episode_stats["mcap_count"] != 1:
|
|
161
|
+
errors.append(
|
|
162
|
+
f"Episode {episode_key} must have exactly 1 .mcap file "
|
|
163
|
+
f"(found {episode_stats['mcap_count']})."
|
|
164
|
+
)
|
|
165
|
+
if episode_stats["mp4_count"] < MIN_VIDEO_COUNT:
|
|
166
|
+
errors.append(
|
|
167
|
+
f"Episode {episode_key} must have at least {MIN_VIDEO_COUNT} "
|
|
168
|
+
f".mp4 files (found {episode_stats['mp4_count']})."
|
|
169
|
+
)
|
|
170
|
+
else:
|
|
171
|
+
primary_videos = select_primary_video_paths(episode_stats["video_paths"])
|
|
172
|
+
missing_slots = [slot for slot in VIDEO_SLOTS if slot not in primary_videos]
|
|
173
|
+
if missing_slots:
|
|
174
|
+
errors.append(
|
|
175
|
+
f"Episode {episode_key} must include primary env/high, left, and right MP4s "
|
|
176
|
+
f"(missing: {', '.join(missing_slots)}). Use one filename containing "
|
|
177
|
+
'"left", one containing "right", and one containing neither.'
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
return errors
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def episode_keys(files: list[LocalFile]) -> list[str]:
|
|
184
|
+
keys = set()
|
|
185
|
+
for item in files:
|
|
186
|
+
path = item.relative_path
|
|
187
|
+
if path.endswith(".mcap") and "/" not in path:
|
|
188
|
+
keys.add(path[:-5])
|
|
189
|
+
elif path.endswith(".mp4") and "/" in path:
|
|
190
|
+
keys.add(path.split("/", 1)[0])
|
|
191
|
+
return sorted(keys, key=lambda item: (len(item), item))
|
prismax/upload.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from .client import PrismaXClient
|
|
4
|
+
from .errors import PrismaxApiError, PrismaxValidationError
|
|
5
|
+
from .manifest import build_manifest_payload, manifest_placeholder
|
|
6
|
+
from .scanner import scan_folder, validate_mcap_mp4, episode_keys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
TERMINAL_STATUSES = {
|
|
10
|
+
"DERIVED_READY",
|
|
11
|
+
"DERIVED_VALIDATION_FAILED",
|
|
12
|
+
"FAILED",
|
|
13
|
+
"DERIVED_PARTIALLY_READY",
|
|
14
|
+
}
|
|
15
|
+
DEFAULT_POLL_ERROR_LIMIT = 3
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _build_files_payload(files, keys):
|
|
19
|
+
payload = [item.as_api_payload() for item in files]
|
|
20
|
+
payload.extend(manifest_placeholder(key) for key in keys)
|
|
21
|
+
return payload
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def upload(
|
|
25
|
+
folder,
|
|
26
|
+
*,
|
|
27
|
+
task_id,
|
|
28
|
+
serial_number,
|
|
29
|
+
api_key=None,
|
|
30
|
+
base_url=None,
|
|
31
|
+
wait=False,
|
|
32
|
+
poll_interval=10,
|
|
33
|
+
max_wait=1800,
|
|
34
|
+
max_poll_errors=DEFAULT_POLL_ERROR_LIMIT,
|
|
35
|
+
timeout=60,
|
|
36
|
+
concurrency=5,
|
|
37
|
+
retries=3,
|
|
38
|
+
):
|
|
39
|
+
if task_id is None:
|
|
40
|
+
raise PrismaxValidationError("task_id is required.")
|
|
41
|
+
if not serial_number:
|
|
42
|
+
raise PrismaxValidationError("serial_number is required.")
|
|
43
|
+
client = PrismaXClient(
|
|
44
|
+
api_key=api_key,
|
|
45
|
+
base_url=base_url,
|
|
46
|
+
timeout=timeout,
|
|
47
|
+
concurrency=concurrency,
|
|
48
|
+
retries=retries,
|
|
49
|
+
)
|
|
50
|
+
files = scan_folder(folder)
|
|
51
|
+
errors = validate_mcap_mp4(files)
|
|
52
|
+
if errors:
|
|
53
|
+
raise PrismaxValidationError("; ".join(errors))
|
|
54
|
+
|
|
55
|
+
keys = episode_keys(files)
|
|
56
|
+
session = client.create_upload_session(
|
|
57
|
+
task_id=task_id,
|
|
58
|
+
serial_number=serial_number,
|
|
59
|
+
files=_build_files_payload(files, keys),
|
|
60
|
+
)
|
|
61
|
+
resolved_machine_id = session.get("machine_id")
|
|
62
|
+
try:
|
|
63
|
+
_upload_session_files(
|
|
64
|
+
client=client,
|
|
65
|
+
session=session,
|
|
66
|
+
files=files,
|
|
67
|
+
episode_keys_value=keys,
|
|
68
|
+
task_id=task_id,
|
|
69
|
+
machine_id=resolved_machine_id,
|
|
70
|
+
)
|
|
71
|
+
except PrismaxApiError as exc:
|
|
72
|
+
upload_id = session.get("upload_id")
|
|
73
|
+
raise PrismaxApiError(
|
|
74
|
+
f"Upload {upload_id} was created but file upload failed. "
|
|
75
|
+
f"Resume with: prismax resume {upload_id} {folder}. Original error: {exc}"
|
|
76
|
+
) from exc
|
|
77
|
+
|
|
78
|
+
if wait:
|
|
79
|
+
return wait_for_upload(
|
|
80
|
+
session["upload_id"],
|
|
81
|
+
api_key=api_key,
|
|
82
|
+
base_url=base_url,
|
|
83
|
+
poll_interval=poll_interval,
|
|
84
|
+
max_wait=max_wait,
|
|
85
|
+
max_poll_errors=max_poll_errors,
|
|
86
|
+
timeout=timeout,
|
|
87
|
+
retries=retries,
|
|
88
|
+
)
|
|
89
|
+
return _public_session_result(session)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def resume(
|
|
93
|
+
upload_id,
|
|
94
|
+
folder,
|
|
95
|
+
*,
|
|
96
|
+
api_key=None,
|
|
97
|
+
base_url=None,
|
|
98
|
+
wait=False,
|
|
99
|
+
poll_interval=10,
|
|
100
|
+
max_wait=1800,
|
|
101
|
+
max_poll_errors=DEFAULT_POLL_ERROR_LIMIT,
|
|
102
|
+
timeout=60,
|
|
103
|
+
concurrency=5,
|
|
104
|
+
retries=3,
|
|
105
|
+
):
|
|
106
|
+
client = PrismaXClient(
|
|
107
|
+
api_key=api_key,
|
|
108
|
+
base_url=base_url,
|
|
109
|
+
timeout=timeout,
|
|
110
|
+
concurrency=concurrency,
|
|
111
|
+
retries=retries,
|
|
112
|
+
)
|
|
113
|
+
files = scan_folder(folder)
|
|
114
|
+
errors = validate_mcap_mp4(files)
|
|
115
|
+
if errors:
|
|
116
|
+
raise PrismaxValidationError("; ".join(errors))
|
|
117
|
+
|
|
118
|
+
keys = episode_keys(files)
|
|
119
|
+
session = client.resume_upload_session(
|
|
120
|
+
upload_id=upload_id,
|
|
121
|
+
files=_build_files_payload(files, keys),
|
|
122
|
+
)
|
|
123
|
+
try:
|
|
124
|
+
_upload_session_files(
|
|
125
|
+
client=client,
|
|
126
|
+
session=session,
|
|
127
|
+
files=files,
|
|
128
|
+
episode_keys_value=keys,
|
|
129
|
+
task_id=session.get("task_id"),
|
|
130
|
+
machine_id=session.get("machine_id"),
|
|
131
|
+
)
|
|
132
|
+
except PrismaxApiError as exc:
|
|
133
|
+
raise PrismaxApiError(
|
|
134
|
+
f"Resume for upload {upload_id} failed while uploading files. "
|
|
135
|
+
f"Retry with: prismax resume {upload_id} {folder}. Original error: {exc}"
|
|
136
|
+
) from exc
|
|
137
|
+
|
|
138
|
+
if wait:
|
|
139
|
+
return wait_for_upload(
|
|
140
|
+
upload_id,
|
|
141
|
+
api_key=api_key,
|
|
142
|
+
base_url=base_url,
|
|
143
|
+
poll_interval=poll_interval,
|
|
144
|
+
max_wait=max_wait,
|
|
145
|
+
max_poll_errors=max_poll_errors,
|
|
146
|
+
timeout=timeout,
|
|
147
|
+
retries=retries,
|
|
148
|
+
)
|
|
149
|
+
return _public_session_result(session)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def status(upload_id, *, api_key=None, base_url=None, timeout=60, retries=3):
|
|
153
|
+
client = PrismaXClient(api_key=api_key, base_url=base_url, timeout=timeout, retries=retries)
|
|
154
|
+
return client.get_upload(upload_id)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def wait_for_upload(
|
|
158
|
+
upload_id,
|
|
159
|
+
*,
|
|
160
|
+
api_key=None,
|
|
161
|
+
base_url=None,
|
|
162
|
+
poll_interval=10,
|
|
163
|
+
max_wait=1800,
|
|
164
|
+
timeout=60,
|
|
165
|
+
retries=3,
|
|
166
|
+
max_poll_errors=DEFAULT_POLL_ERROR_LIMIT,
|
|
167
|
+
):
|
|
168
|
+
client = PrismaXClient(api_key=api_key, base_url=base_url, timeout=timeout, retries=retries)
|
|
169
|
+
started_at = time.monotonic()
|
|
170
|
+
last_status = None
|
|
171
|
+
poll_errors = 0
|
|
172
|
+
while True:
|
|
173
|
+
try:
|
|
174
|
+
current = client.get_upload(upload_id)
|
|
175
|
+
poll_errors = 0
|
|
176
|
+
last_status = str(current.get("status") or "").upper()
|
|
177
|
+
if last_status in TERMINAL_STATUSES:
|
|
178
|
+
return current
|
|
179
|
+
except PrismaxApiError as exc:
|
|
180
|
+
poll_errors += 1
|
|
181
|
+
if max_poll_errors is not None and poll_errors >= int(max_poll_errors):
|
|
182
|
+
raise PrismaxApiError(
|
|
183
|
+
f"Failed to poll upload {upload_id} status after {poll_errors} consecutive errors: {exc}"
|
|
184
|
+
) from exc
|
|
185
|
+
if max_wait is not None and time.monotonic() - started_at >= int(max_wait):
|
|
186
|
+
raise PrismaxApiError(
|
|
187
|
+
f"Timed out waiting for upload {upload_id} after {int(max_wait)} seconds "
|
|
188
|
+
f"(last status: {last_status or 'unknown'})."
|
|
189
|
+
)
|
|
190
|
+
time.sleep(max(1, int(poll_interval)))
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _upload_session_files(*, client, session, files, episode_keys_value, task_id, machine_id):
|
|
194
|
+
signed_urls = session.get("signed_urls") or []
|
|
195
|
+
signed_url_by_path = {
|
|
196
|
+
item.get("relative_path"): item
|
|
197
|
+
for item in signed_urls
|
|
198
|
+
if item.get("relative_path") and item.get("signed_url")
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
raw_uploads = []
|
|
202
|
+
local_file_by_relative_path = {item.relative_path: item for item in files}
|
|
203
|
+
for local_file in files:
|
|
204
|
+
signed_item = signed_url_by_path.get(local_file.relative_path)
|
|
205
|
+
if not signed_item:
|
|
206
|
+
continue
|
|
207
|
+
raw_uploads.append({
|
|
208
|
+
"signed_url": signed_item["signed_url"],
|
|
209
|
+
"relative_path": local_file.relative_path,
|
|
210
|
+
"path": local_file.path,
|
|
211
|
+
"content_type": local_file.content_type,
|
|
212
|
+
})
|
|
213
|
+
client.upload_files(raw_uploads)
|
|
214
|
+
|
|
215
|
+
upload_id = session.get("upload_id")
|
|
216
|
+
for episode_key in episode_keys_value:
|
|
217
|
+
manifest_path = f"{episode_key}/_MANIFEST.json"
|
|
218
|
+
signed_item = signed_url_by_path.get(manifest_path)
|
|
219
|
+
if not signed_item:
|
|
220
|
+
continue
|
|
221
|
+
payload = build_manifest_payload(
|
|
222
|
+
episode_key=episode_key,
|
|
223
|
+
upload_id=upload_id,
|
|
224
|
+
machine_id=machine_id,
|
|
225
|
+
task_id=task_id,
|
|
226
|
+
files=list(local_file_by_relative_path.values()),
|
|
227
|
+
)
|
|
228
|
+
client.upload_json_to_signed_url(
|
|
229
|
+
signed_url=signed_item["signed_url"],
|
|
230
|
+
payload=payload,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _public_session_result(session):
|
|
235
|
+
hidden = {"signed_urls"}
|
|
236
|
+
return {
|
|
237
|
+
key: value
|
|
238
|
+
for key, value in session.items()
|
|
239
|
+
if key not in hidden
|
|
240
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prismax
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: PrismaX Python SDK for data uploads
|
|
5
|
+
Author: PrismaX
|
|
6
|
+
License: PolyForm Noncommercial License 1.0.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ChrisPrismax/prismax-sdk-python
|
|
8
|
+
Project-URL: Repository, https://github.com/ChrisPrismax/prismax-sdk-python
|
|
9
|
+
Project-URL: Issues, https://github.com/ChrisPrismax/prismax-sdk-python/issues
|
|
10
|
+
Keywords: prismax,upload,sdk,robotics,mcap
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: Other/Proprietary License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: requests>=2.31.0
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# PrismaX Python SDK
|
|
28
|
+
|
|
29
|
+
Minimal upload SDK for PrismaX data uploads.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
This SDK is source-available for noncommercial use under the PolyForm
|
|
34
|
+
Noncommercial License 1.0.0. Commercial use is not permitted unless PrismaX
|
|
35
|
+
grants a separate commercial license.
|
|
36
|
+
|
|
37
|
+
## Quickstart
|
|
38
|
+
|
|
39
|
+
You need:
|
|
40
|
+
|
|
41
|
+
- a PrismaX upload API key with the `pxu_` prefix
|
|
42
|
+
- a PrismaX task ID
|
|
43
|
+
- the robot serial number for the machine that produced the data
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install prismax
|
|
47
|
+
export PRISMAX_API_KEY="pxu_your_upload_api_key"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Download API keys are not valid for uploads.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import prismax
|
|
54
|
+
|
|
55
|
+
result = prismax.upload("./data", task_id=123, serial_number="robot_serial_number")
|
|
56
|
+
print(result["upload_id"])
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The SDK scans the folder, creates an upload session, uploads raw files to signed
|
|
60
|
+
Google Cloud URLs, generates episode manifests in memory, uploads manifests last,
|
|
61
|
+
and returns the upload summary.
|
|
62
|
+
|
|
63
|
+
You can also pass the API key directly:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import prismax
|
|
67
|
+
|
|
68
|
+
result = prismax.upload(
|
|
69
|
+
"./data",
|
|
70
|
+
task_id=123,
|
|
71
|
+
serial_number="robot_serial_number",
|
|
72
|
+
api_key="pxu_your_upload_api_key",
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Expected Folder Structure
|
|
77
|
+
|
|
78
|
+
```text
|
|
79
|
+
data/
|
|
80
|
+
1.mcap
|
|
81
|
+
1/
|
|
82
|
+
high.mp4
|
|
83
|
+
left.mp4
|
|
84
|
+
right.mp4
|
|
85
|
+
high2.mp4
|
|
86
|
+
left2.mp4
|
|
87
|
+
right2.mp4
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Each episode must contain one root `{episode}.mcap` file and at least three MP4
|
|
91
|
+
files under `{episode}/`: one primary filename containing `left`, one containing
|
|
92
|
+
`right`, and one environment/high video filename containing neither. Additional
|
|
93
|
+
MP4 files are uploaded as raw files, included in downloads, and checked for
|
|
94
|
+
duration consistency. A duration mismatch across any episode videos can fail the
|
|
95
|
+
upload. Only the primary three videos are processed for derived previews, QA,
|
|
96
|
+
and duplicate detection.
|
|
97
|
+
|
|
98
|
+
Use lowercase `.mp4` extensions. Uppercase variants such as `.MP4` are rejected
|
|
99
|
+
so client validation, worker processing, and download manifests choose the same
|
|
100
|
+
primary videos. Hidden files are ignored, including macOS metadata files such as
|
|
101
|
+
`.DS_Store` and `._left.mp4`.
|
|
102
|
+
|
|
103
|
+
Primary video selection is based on filename:
|
|
104
|
+
|
|
105
|
+
- filenames containing `left` are treated as left videos
|
|
106
|
+
- filenames containing `right` are treated as right videos
|
|
107
|
+
- other MP4 files are treated as environment/high videos
|
|
108
|
+
- exact names are preferred, for example `high.mp4`, `left.mp4`, and
|
|
109
|
+
`right.mp4` are selected before `high2.mp4`, `left2.mp4`, and `right2.mp4`
|
|
110
|
+
|
|
111
|
+
Example:
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
data/
|
|
115
|
+
1.mcap
|
|
116
|
+
1/
|
|
117
|
+
high.mp4
|
|
118
|
+
left.mp4
|
|
119
|
+
right.mp4
|
|
120
|
+
high2.mp4
|
|
121
|
+
left2.mp4
|
|
122
|
+
right2.mp4
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Primary videos:
|
|
126
|
+
|
|
127
|
+
```text
|
|
128
|
+
env/high: high.mp4
|
|
129
|
+
left: left.mp4
|
|
130
|
+
right: right.mp4
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Additional videos:
|
|
134
|
+
|
|
135
|
+
```text
|
|
136
|
+
high2.mp4
|
|
137
|
+
left2.mp4
|
|
138
|
+
right2.mp4
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## CLI
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
prismax upload ./data --task-id 123 --serial-number robot_serial_number
|
|
145
|
+
prismax status 123
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Use `--wait` to wait for the worker to finish. The default maximum wait time is
|
|
149
|
+
30 minutes.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
prismax upload ./data --task-id 123 --serial-number robot_serial_number --wait
|
|
153
|
+
prismax upload ./data --task-id 123 --serial-number robot_serial_number --wait --max-wait 3600
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Useful CLI options:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
prismax upload ./data --task-id 123 --serial-number robot_serial_number --timeout 120 --retries 5
|
|
160
|
+
prismax upload ./data --task-id 123 --serial-number robot_serial_number --wait --poll-interval 5 --max-poll-errors 3
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Status and Resume
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import prismax
|
|
167
|
+
|
|
168
|
+
upload_status = prismax.status(123)
|
|
169
|
+
|
|
170
|
+
resume_result = prismax.resume(
|
|
171
|
+
123,
|
|
172
|
+
"./data",
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
prismax status 123
|
|
178
|
+
prismax resume 123 ./data
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Resume expects the same complete upload folder/file list, not only the files
|
|
182
|
+
that are missing from cloud storage. The SDK will ask the API which files still
|
|
183
|
+
need signed upload URLs. Resume is only allowed while the upload is still in
|
|
184
|
+
`UPLOADING` status; once processing has started or the upload reaches a terminal
|
|
185
|
+
status, create a new upload instead.
|
|
186
|
+
|
|
187
|
+
## Error Handling
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
import prismax
|
|
191
|
+
|
|
192
|
+
try:
|
|
193
|
+
prismax.upload("./data", task_id=123, serial_number="robot_serial_number")
|
|
194
|
+
except prismax.PrismaxValidationError as exc:
|
|
195
|
+
print(f"Invalid upload folder: {exc}")
|
|
196
|
+
except prismax.PrismaxAuthError as exc:
|
|
197
|
+
print(f"API key or permission error: {exc}")
|
|
198
|
+
except prismax.PrismaxApiError as exc:
|
|
199
|
+
print(f"PrismaX API error: {exc}")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
If raw file upload fails after the session is created, the SDK error includes
|
|
203
|
+
the upload ID and a `prismax resume <upload_id> <folder>` command.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
prismax/__init__.py,sha256=iVLWIeMPcOAjNm1wHgPFUPWsflZRK2g1VDByDWDQ6I0,639
|
|
2
|
+
prismax/cli.py,sha256=81xB8w-Q7XIAZmWRZ4oOB6OXin0xqU9TE8QWRRWnSqA,3936
|
|
3
|
+
prismax/client.py,sha256=nZG321roCN_93WMoavRhlpRJPN7Nn1dlmosFVfVFvpU,5760
|
|
4
|
+
prismax/errors.py,sha256=3ZsglvM2i3YCm6dhbG3yITtOZ6kE8kNDoohzOtEQB8A,348
|
|
5
|
+
prismax/manifest.py,sha256=APNuXtUzBKAT9z9wZTb7VWVCELO7bALI1CQa_l7VNBg,939
|
|
6
|
+
prismax/scanner.py,sha256=KKNF25EtFGSf0a0ZvdG1NO48v868SvC6-Awlac0KSDI,6463
|
|
7
|
+
prismax/upload.py,sha256=n7hJL4-RTbRCFIhcYlhn-Yr72FeLrsVRDaAHWD6rJ0s,7195
|
|
8
|
+
prismax-0.1.0.dist-info/licenses/LICENSE,sha256=FFp83etv6SWxufS_dkHzTCVx7LHtJjUfUjMEkLIjrxE,4589
|
|
9
|
+
prismax-0.1.0.dist-info/METADATA,sha256=xr9Yd9YcZ_Fneb_GbPNRsIUt-Gqw-_3vBMww60-PFn4,5473
|
|
10
|
+
prismax-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
11
|
+
prismax-0.1.0.dist-info/entry_points.txt,sha256=nhoZLNfrZJGwEnmdOFY2lIWtBEGizlaP5R2fLgZUKXw,45
|
|
12
|
+
prismax-0.1.0.dist-info/top_level.txt,sha256=Ydwy8p_-tArcn3AaCyEOEEAMQBh-2p9VJNZScG3H3Iw,8
|
|
13
|
+
prismax-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Required Notice: Copyright 2026 PrismaX
|
|
2
|
+
|
|
3
|
+
# PolyForm Noncommercial License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree
|
|
10
|
+
to them as both strict obligations and conditions to all your
|
|
11
|
+
licenses.
|
|
12
|
+
|
|
13
|
+
## Copyright License
|
|
14
|
+
|
|
15
|
+
The licensor grants you a copyright license for the software
|
|
16
|
+
to do everything you might do with the software that would
|
|
17
|
+
otherwise infringe the licensor's copyright in it for any
|
|
18
|
+
permitted purpose. However, you may only distribute the software
|
|
19
|
+
according to [Distribution License](#distribution-license) and
|
|
20
|
+
make changes or new works based on the software according to
|
|
21
|
+
[Changes and New Works License](#changes-and-new-works-license).
|
|
22
|
+
|
|
23
|
+
## Distribution License
|
|
24
|
+
|
|
25
|
+
The licensor grants you an additional copyright license to
|
|
26
|
+
distribute copies of the software. Your license to distribute
|
|
27
|
+
covers distributing the software with changes and new works
|
|
28
|
+
permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of the
|
|
33
|
+
software from you also gets a copy of these terms or the URL for
|
|
34
|
+
them above, as well as copies of any plain-text lines beginning
|
|
35
|
+
with `Required Notice:` that the licensor provided with the
|
|
36
|
+
software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to make
|
|
43
|
+
changes and new works based on the software for any permitted
|
|
44
|
+
purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncommercial Purposes
|
|
53
|
+
|
|
54
|
+
Any noncommercial purpose is a permitted purpose.
|
|
55
|
+
|
|
56
|
+
## Personal Uses
|
|
57
|
+
|
|
58
|
+
Personal use for research, experiment, and testing for the
|
|
59
|
+
benefit of public knowledge, personal study, private
|
|
60
|
+
entertainment, hobby projects, amateur pursuits, or religious
|
|
61
|
+
observance, without any anticipated commercial application, is
|
|
62
|
+
use for a permitted purpose.
|
|
63
|
+
|
|
64
|
+
## Noncommercial Organizations
|
|
65
|
+
|
|
66
|
+
Use by any charitable organization, educational institution,
|
|
67
|
+
public research organization, public safety or health
|
|
68
|
+
organization, environmental protection organization, or
|
|
69
|
+
government institution is use for a permitted purpose regardless
|
|
70
|
+
of the source of funding or obligations resulting from the
|
|
71
|
+
funding.
|
|
72
|
+
|
|
73
|
+
## Fair Use
|
|
74
|
+
|
|
75
|
+
You may have "fair use" rights for the software under the law.
|
|
76
|
+
These terms do not limit them.
|
|
77
|
+
|
|
78
|
+
## No Other Rights
|
|
79
|
+
|
|
80
|
+
These terms do not allow you to sublicense or transfer any of
|
|
81
|
+
your licenses to anyone else, or prevent the licensor from
|
|
82
|
+
granting licenses to anyone else. These terms do not imply any
|
|
83
|
+
other licenses.
|
|
84
|
+
|
|
85
|
+
## Patent Defense
|
|
86
|
+
|
|
87
|
+
If you make any written claim that the software infringes or
|
|
88
|
+
contributes to infringement of any patent, your patent license
|
|
89
|
+
for the software granted under these terms ends immediately. If
|
|
90
|
+
your company makes such a claim, your patent license ends
|
|
91
|
+
immediately for work on behalf of your company.
|
|
92
|
+
|
|
93
|
+
## Violations
|
|
94
|
+
|
|
95
|
+
The first time you are notified in writing that you have
|
|
96
|
+
violated any of these terms, or done anything with the software
|
|
97
|
+
not covered by your licenses, your licenses can nonetheless
|
|
98
|
+
continue if you come into full compliance with these terms, and
|
|
99
|
+
take practical steps to correct past violations, within 32 days
|
|
100
|
+
of receiving notice. Otherwise, all your licenses end
|
|
101
|
+
immediately.
|
|
102
|
+
|
|
103
|
+
## No Liability
|
|
104
|
+
|
|
105
|
+
As far as the law allows, the software comes as is, without any
|
|
106
|
+
warranty or condition, and the licensor will not be liable to
|
|
107
|
+
you for any damages arising out of these terms or the use or
|
|
108
|
+
nature of the software, under any kind of legal claim.
|
|
109
|
+
|
|
110
|
+
## Definitions
|
|
111
|
+
|
|
112
|
+
The licensor is the individual or entity offering these terms,
|
|
113
|
+
and the software is the software the licensor makes available
|
|
114
|
+
under these terms.
|
|
115
|
+
|
|
116
|
+
You refers to the individual or entity agreeing to these terms.
|
|
117
|
+
|
|
118
|
+
Your company is any legal entity, sole proprietorship, or other
|
|
119
|
+
kind of organization that you work for, plus all organizations
|
|
120
|
+
that have control over, are under the control of, or are under
|
|
121
|
+
common control with that organization. Control means ownership
|
|
122
|
+
of substantially all the assets of an entity, or the power to
|
|
123
|
+
direct its management and policies by vote, contract, or
|
|
124
|
+
otherwise. Control can be direct or indirect.
|
|
125
|
+
|
|
126
|
+
Your licenses are all the licenses granted to you for the
|
|
127
|
+
software under these terms.
|
|
128
|
+
|
|
129
|
+
Use means anything you do with the software requiring one of
|
|
130
|
+
your licenses.
|
|
131
|
+
|
|
132
|
+
© PolyForm Project Inc.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prismax
|