chuk-artifacts 0.2.2__py3-none-any.whl → 0.3__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.
- chuk_artifacts/core.py +73 -0
- chuk_artifacts/metadata.py +4 -4
- chuk_artifacts/store.py +29 -2
- {chuk_artifacts-0.2.2.dist-info → chuk_artifacts-0.3.dist-info}/METADATA +4 -4
- {chuk_artifacts-0.2.2.dist-info → chuk_artifacts-0.3.dist-info}/RECORD +7 -8
- chuk_artifacts-0.2.2.dist-info/licenses/LICENSE +0 -21
- {chuk_artifacts-0.2.2.dist-info → chuk_artifacts-0.3.dist-info}/WHEEL +0 -0
- {chuk_artifacts-0.2.2.dist-info → chuk_artifacts-0.3.dist-info}/top_level.txt +0 -0
chuk_artifacts/core.py
CHANGED
@@ -101,6 +101,79 @@ class CoreStorageOperations:
|
|
101
101
|
else:
|
102
102
|
raise ProviderError(f"Storage failed: {e}") from e
|
103
103
|
|
104
|
+
async def update_file(
|
105
|
+
self,
|
106
|
+
artifact_id: str,
|
107
|
+
new_data: bytes,
|
108
|
+
*,
|
109
|
+
mime: Optional[str] = None,
|
110
|
+
summary: Optional[str] = None,
|
111
|
+
meta: Optional[Dict[str, Any]] = None,
|
112
|
+
filename: Optional[str] = None,
|
113
|
+
ttl: Optional[int] = None,
|
114
|
+
) -> None:
|
115
|
+
"""
|
116
|
+
Update the contents of an existing artifact.
|
117
|
+
|
118
|
+
Parameters
|
119
|
+
----------
|
120
|
+
artifact_id : str
|
121
|
+
ID of the artifact to update.
|
122
|
+
new_data : bytes
|
123
|
+
New data to overwrite the existing artifact.
|
124
|
+
mime : Optional[str]
|
125
|
+
Optional new MIME type.
|
126
|
+
summary : Optional[str]
|
127
|
+
Optional new summary.
|
128
|
+
meta : Optional[Dict[str, Any]]
|
129
|
+
Optional updated metadata.
|
130
|
+
filename : Optional[str]
|
131
|
+
Optional new filename.
|
132
|
+
ttl : Optional[int]
|
133
|
+
Optional TTL to reset (if provided).
|
134
|
+
"""
|
135
|
+
if self.artifact_store._closed:
|
136
|
+
raise ArtifactStoreError("Store is closed")
|
137
|
+
|
138
|
+
try:
|
139
|
+
record = await self._get_record(artifact_id)
|
140
|
+
key = record["key"]
|
141
|
+
session_id = record["session_id"]
|
142
|
+
|
143
|
+
# Overwrite in object storage
|
144
|
+
await self._store_with_retry(
|
145
|
+
new_data,
|
146
|
+
key,
|
147
|
+
mime or record["mime"],
|
148
|
+
filename or record.get("filename"),
|
149
|
+
session_id,
|
150
|
+
)
|
151
|
+
|
152
|
+
# Update metadata
|
153
|
+
record.update({
|
154
|
+
"mime": mime or record["mime"],
|
155
|
+
"summary": summary or record["summary"],
|
156
|
+
"meta": meta or record["meta"],
|
157
|
+
"filename": filename or record.get("filename"),
|
158
|
+
"bytes": len(new_data),
|
159
|
+
"sha256": hashlib.sha256(new_data).hexdigest(),
|
160
|
+
"updated_at": datetime.utcnow().isoformat() + "Z",
|
161
|
+
"ttl": ttl or record["ttl"],
|
162
|
+
})
|
163
|
+
|
164
|
+
if ttl is not None:
|
165
|
+
record["ttl"] = ttl
|
166
|
+
|
167
|
+
session_ctx_mgr = self.artifact_store._session_factory()
|
168
|
+
async with session_ctx_mgr as session:
|
169
|
+
await session.setex(artifact_id, record["ttl"], json.dumps(record))
|
170
|
+
|
171
|
+
logger.info("Artifact updated successfully", extra={"artifact_id": artifact_id})
|
172
|
+
|
173
|
+
except Exception as e:
|
174
|
+
logger.error(f"Update failed for artifact {artifact_id}: {e}")
|
175
|
+
raise ProviderError(f"Artifact update failed: {e}") from e
|
176
|
+
|
104
177
|
async def retrieve(self, artifact_id: str) -> bytes:
|
105
178
|
"""Retrieve artifact data."""
|
106
179
|
if self.artifact_store._closed:
|
chuk_artifacts/metadata.py
CHANGED
@@ -9,7 +9,7 @@ from __future__ import annotations
|
|
9
9
|
|
10
10
|
import json
|
11
11
|
import logging
|
12
|
-
from typing import Any, Dict, List,
|
12
|
+
from typing import Any, Dict, List, TYPE_CHECKING
|
13
13
|
|
14
14
|
if TYPE_CHECKING:
|
15
15
|
from .store import ArtifactStore
|
@@ -68,7 +68,7 @@ class MetadataOperations:
|
|
68
68
|
try:
|
69
69
|
artifacts = []
|
70
70
|
# Use the session manager's canonical prefix instead of building our own
|
71
|
-
prefix = self.artifact_store.
|
71
|
+
prefix = self.artifact_store.get_canonical_prefix(session_id)
|
72
72
|
|
73
73
|
storage_ctx_mgr = self.artifact_store._s3_factory()
|
74
74
|
async with storage_ctx_mgr as s3:
|
@@ -82,7 +82,7 @@ class MetadataOperations:
|
|
82
82
|
for obj in response.get('Contents', []):
|
83
83
|
key = obj['Key']
|
84
84
|
# Parse the grid key using chuk_sessions
|
85
|
-
parsed = self.artifact_store.
|
85
|
+
parsed = self.artifact_store.parse_grid_key(key)
|
86
86
|
if parsed and parsed.get('artifact_id'):
|
87
87
|
artifact_id = parsed['artifact_id']
|
88
88
|
try:
|
@@ -93,7 +93,7 @@ class MetadataOperations:
|
|
93
93
|
|
94
94
|
return artifacts[:limit]
|
95
95
|
|
96
|
-
logger.warning(
|
96
|
+
logger.warning("Storage provider doesn't support listing")
|
97
97
|
return []
|
98
98
|
|
99
99
|
except Exception as e:
|
chuk_artifacts/store.py
CHANGED
@@ -12,7 +12,9 @@ Grid Architecture:
|
|
12
12
|
|
13
13
|
from __future__ import annotations
|
14
14
|
|
15
|
-
import os
|
15
|
+
import os
|
16
|
+
import logging
|
17
|
+
import uuid
|
16
18
|
from datetime import datetime
|
17
19
|
from typing import Any, Dict, List, Callable, AsyncContextManager, Optional, Union
|
18
20
|
from chuk_sessions.session_manager import SessionManager
|
@@ -37,7 +39,6 @@ except ImportError:
|
|
37
39
|
from .exceptions import ArtifactStoreError, ProviderError
|
38
40
|
|
39
41
|
# Import chuk_sessions instead of local session manager
|
40
|
-
from chuk_sessions.session_manager import SessionManager
|
41
42
|
|
42
43
|
# Configure structured logging
|
43
44
|
logger = logging.getLogger(__name__)
|
@@ -161,6 +162,32 @@ class ArtifactStore:
|
|
161
162
|
session_id=session_id,
|
162
163
|
ttl=ttl,
|
163
164
|
)
|
165
|
+
|
166
|
+
async def update_file(
|
167
|
+
self,
|
168
|
+
artifact_id: str,
|
169
|
+
*,
|
170
|
+
data: Optional[bytes] = None,
|
171
|
+
meta: Optional[Dict[str, Any]] = None,
|
172
|
+
filename: Optional[str] = None,
|
173
|
+
summary: Optional[str] = None,
|
174
|
+
mime: Optional[str] = None,
|
175
|
+
) -> bool:
|
176
|
+
"""
|
177
|
+
Update an artifact's content, metadata, filename, summary, or mime type.
|
178
|
+
All parameters are optional. At least one must be provided.
|
179
|
+
"""
|
180
|
+
if not any([data, meta, filename, summary, mime]):
|
181
|
+
raise ValueError("At least one update parameter must be provided.")
|
182
|
+
|
183
|
+
return await self._core.update_file(
|
184
|
+
artifact_id=artifact_id,
|
185
|
+
new_data=data,
|
186
|
+
meta=meta,
|
187
|
+
filename=filename,
|
188
|
+
summary=summary,
|
189
|
+
mime=mime,
|
190
|
+
)
|
164
191
|
|
165
192
|
async def retrieve(self, artifact_id: str) -> bytes:
|
166
193
|
"""Retrieve artifact data."""
|
@@ -1,11 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: chuk-artifacts
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3
|
4
4
|
Summary: Chuk Artifacts provides a production-ready, modular artifact storage system that works seamlessly across multiple storage backends (memory, filesystem, AWS S3, IBM Cloud Object Storage) with Redis or memory-based metadata caching and strict session-based security.
|
5
|
-
License: MIT
|
6
5
|
Requires-Python: >=3.11
|
7
6
|
Description-Content-Type: text/markdown
|
8
|
-
License-File: LICENSE
|
9
7
|
Requires-Dist: chuk-tool-processor>=0.4
|
10
8
|
Requires-Dist: pydantic>=2.10.6
|
11
9
|
Requires-Dist: pyyaml>=6.0.2
|
@@ -19,7 +17,6 @@ Provides-Extra: dev
|
|
19
17
|
Requires-Dist: pytest>=8.3.5; extra == "dev"
|
20
18
|
Requires-Dist: pytest-asyncio>=0.26.0; extra == "dev"
|
21
19
|
Requires-Dist: ruff>=0.4.6; extra == "dev"
|
22
|
-
Dynamic: license-file
|
23
20
|
|
24
21
|
# Chuk Artifacts
|
25
22
|
|
@@ -593,6 +590,9 @@ Move/rename file within same session only (cross-session blocked).
|
|
593
590
|
#### `list_files(session_id, prefix="", limit=100)`
|
594
591
|
List files with optional prefix filtering.
|
595
592
|
|
593
|
+
#### `update_file(artifact_id, *, data=None, meta=None, filename=None, summary=None, mime=None)`
|
594
|
+
Update artifact content, metadata, filename, summary, or MIME type. At least one field must be specified for update.
|
595
|
+
|
596
596
|
### Metadata Operations
|
597
597
|
|
598
598
|
#### `update_metadata(artifact_id, *, summary=None, meta=None, merge=True, **kwargs)`
|
@@ -3,22 +3,21 @@ chuk_artifacts/admin.py,sha256=lUgmKBPxJh-0FYrGWjkACXQOl8lbVEDPJaeGVsWZmC4,6071
|
|
3
3
|
chuk_artifacts/base.py,sha256=BtuVnC9M8QI1znyTdBxjZ6knIKP_k0yUfLfh7inGJUc,2559
|
4
4
|
chuk_artifacts/batch.py,sha256=x8ARrWJ24I9fAXXodzvh31uMxYrvwZCGGJhUCM4vMJ4,5099
|
5
5
|
chuk_artifacts/config.py,sha256=MaUzHzKPoBUyERviEpv8JVvPybMzSksgLyj0b7AO3Sc,7664
|
6
|
-
chuk_artifacts/core.py,sha256=
|
6
|
+
chuk_artifacts/core.py,sha256=u1w0A-DZUoTvnnTrtYNMNxqLdKqvRHJZBaXHsjIHQ8E,9465
|
7
7
|
chuk_artifacts/exceptions.py,sha256=f-s7Mg7c8vMXsbgqO2B6lMHdXcJQNvsESAY4GhJaV4g,814
|
8
8
|
chuk_artifacts/grid.py,sha256=IkvAgTLaN-ahRGVC6sysMkP7ALUUleJHaYfr5TRH7ZY,796
|
9
|
-
chuk_artifacts/metadata.py,sha256=
|
9
|
+
chuk_artifacts/metadata.py,sha256=Dr2IFgYn4ISHYzoSdnOToVO3CmskDqkV_ejnJFAsZos,7785
|
10
10
|
chuk_artifacts/models.py,sha256=_foXlkr0DprqgztDw5WtlDc-s1OouLgYNp4XM1Ghp-g,837
|
11
11
|
chuk_artifacts/presigned.py,sha256=-GE8r0CfUZuPNA_jnSGTfX7kuws6kYCPe7C4y6FItdo,11491
|
12
12
|
chuk_artifacts/provider_factory.py,sha256=T0IXx1C8gygJzp417oB44_DxEaZoZR7jcdwQy8FghRE,3398
|
13
|
-
chuk_artifacts/store.py,sha256=
|
13
|
+
chuk_artifacts/store.py,sha256=zotx7jJosFLKBdqfRtLRRUIsRWu7eDOB2TpoldEjYck,25605
|
14
14
|
chuk_artifacts/providers/__init__.py,sha256=3lN1lAy1ETT1mQslJo1f22PPR1W4CyxmsqJBclzH4NE,317
|
15
15
|
chuk_artifacts/providers/filesystem.py,sha256=F4EjE-_ItPg0RWe7CqameVpOMjU-b7AigEBkm_ZoNrc,15280
|
16
16
|
chuk_artifacts/providers/ibm_cos.py,sha256=K1-VAX4UVV9tA161MOeDXOKloQ0hB77jdw1-p46FwmU,4445
|
17
17
|
chuk_artifacts/providers/ibm_cos_iam.py,sha256=VtwvCi9rMMcZx6i9l21ob6wM8jXseqvjzgCnAA82RkY,3186
|
18
18
|
chuk_artifacts/providers/memory.py,sha256=9sA8xDKh_IMjuHtqR5gTtpzpanZfdBeQLcTk-4-G9Dk,10582
|
19
19
|
chuk_artifacts/providers/s3.py,sha256=QSSiYjNENQfwxJ2-Yw-CJrO8lNZcIrsfdn2Vo_DD-b4,2931
|
20
|
-
chuk_artifacts-0.
|
21
|
-
chuk_artifacts-0.
|
22
|
-
chuk_artifacts-0.
|
23
|
-
chuk_artifacts-0.
|
24
|
-
chuk_artifacts-0.2.2.dist-info/RECORD,,
|
20
|
+
chuk_artifacts-0.3.dist-info/METADATA,sha256=rWEYiBcR92SduU9VzxnQMU1gqmGArE_XiSdWavdav4c,21340
|
21
|
+
chuk_artifacts-0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
22
|
+
chuk_artifacts-0.3.dist-info/top_level.txt,sha256=1_PVMtWXR0A-ZmeH6apF9mPaMtU0i23JE6wmN4GBRDI,15
|
23
|
+
chuk_artifacts-0.3.dist-info/RECORD,,
|
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2025 Chris Hay
|
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.
|
File without changes
|
File without changes
|