Collection¶
A Collection is a named, described grouping of IVCAP entity URNs (most commonly
artifacts) backed entirely by DataFabric aspects — there is no separate REST endpoint.
Quick Reference¶
from ivcap_client import IVCAP
ivcap = IVCAP()
# Create (or update) a collection
coll = ivcap.create_collection(
"urn:ivcap:collection:my-survey",
name="Ocean CTD Survey",
description="CTD casts from voyage V2025-03",
)
# Add an item (deduplication is automatic)
item = coll.add_item("urn:ivcap:artifact:<uuid>")
# List items
for ci in coll.items(limit=50):
print(ci.item)
# Remove a single item
coll.remove_item("urn:ivcap:artifact:<uuid>")
# Retract the entire collection
total = coll.retract()
print(f"Retracted {total} aspect records")
Class Documentation¶
Collection
dataclass
¶
A named, described grouping of entities stored in the IVCAP DataFabric.
A collection is identified by its entity URN and backed by a
urn:ivcap:schema:collection.1 aspect. Items are tracked as individual
urn:ivcap:schema:collection-item.1 aspects attached to the same entity
URN.
Attributes:
| Name | Type | Description |
|---|---|---|
urn |
str
|
The collection entity URN (also accessible as :attr: |
name |
str
|
Human-readable name. |
description |
str | None
|
Optional description. |
asserter |
URN | None
|
URN of the account that created/updated the definition. |
valid_from |
datetime | None
|
Timestamp from which the current definition is valid. |
valid_to |
datetime | None
|
Timestamp until which the current definition is valid
( |
Source code in ivcap_client/collection.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
id
property
¶
Alias for :attr:urn.
add_item(item_urn, *, policy=None)
¶
Add an item to this collection with automatic deduplication.
Checks whether item_urn is already a member before creating the
membership aspect. If it is, returns None (skip silently).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_urn
|
str
|
URN of the entity to add. |
required |
policy
|
URN | None
|
Optional access policy URN for the membership aspect
( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CollectionItem | None
|
class: |
Source code in ivcap_client/collection.py
remove_item(item_urn)
¶
Remove an item from this collection by retracting its membership aspect.
Items that are not currently members of the collection are silently skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_urn
|
str
|
URN of the entity to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in ivcap_client/collection.py
items(*, limit=10, at_time=None)
¶
Return an iterator over all items in this collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Maximum number of items to yield. Defaults to 10. |
10
|
at_time
|
datetime | None
|
Return membership records that were valid at this point in time (ISO 8601). Defaults to now. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[CollectionItem]
|
An iterator over :class: |
Source code in ivcap_client/collection.py
retract()
¶
Fully retract this collection and all its item memberships.
All membership aspects are retracted first (paginated), then the collection definition aspect is retracted. This operation cannot be undone.
Returns:
| Type | Description |
|---|---|
int
|
Total number of aspect records retracted (items + 1 definition). |
Source code in ivcap_client/collection.py
refresh()
¶
Reload the collection definition from IVCAP.
Returns:
| Type | Description |
|---|---|
Collection
|
|
Source code in ivcap_client/collection.py
CollectionItem¶
CollectionItem
dataclass
¶
A single membership record linking one item to a collection.
This corresponds to a urn:ivcap:schema:collection-item.1 aspect stored
in the DataFabric.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Aspect record URN. |
collection |
str
|
Collection entity URN. |
item |
str
|
Member entity URN. |
valid_from |
datetime | None
|
Timestamp from which this membership is valid. |
valid_to |
datetime | None
|
Timestamp until which this membership is valid ( |
Source code in ivcap_client/collection.py
urn
property
¶
Alias for :attr:item — the member entity URN.
Module-Level Functions¶
create_collection(ivcap, urn, name, *, description=None, policy=None)
¶
Create or update a collection definition (idempotent).
Checks whether a collection.1 aspect already exists for urn:
- If not found — issues a
POST(create) to add the definition. - If found — issues a
PUT(update) to replace the definition.
This avoids the server-side "not authorised for method 'add'" error that occurs when a plain PUT is sent for a collection that does not yet exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ivcap
|
IVCAP
|
The IVCAP client instance. |
required |
urn
|
str
|
The collection entity URN (must be a valid IVCAP URN,
e.g. |
required |
name
|
str
|
Human-readable collection name. |
required |
description
|
str | None
|
Optional description. |
None
|
policy
|
URN | None
|
Optional access policy URN
( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Collection
|
class: |
Raises:
| Type | Description |
|---|---|
|
exc: |
Source code in ivcap_client/collection.py
get_collection(ivcap, urn, *, at_time=None)
¶
Fetch a collection definition from IVCAP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ivcap
|
IVCAP
|
The IVCAP client instance. |
required |
urn
|
str
|
The collection entity URN. |
required |
at_time
|
datetime | None
|
Retrieve the definition as it was at this point in time. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Collection
|
class: |
Raises:
| Type | Description |
|---|---|
|
exc: |
Source code in ivcap_client/collection.py
list_collections(ivcap, *, name_filter=None, limit=10, at_time=None)
¶
Return an iterator over collection definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ivcap
|
IVCAP
|
The IVCAP client instance. |
required |
name_filter
|
str | None
|
Optional JSONPath comparison expression applied to the
collection |
None
|
limit
|
int | None
|
Maximum number of collections to return. Defaults to 10. |
10
|
at_time
|
datetime | None
|
Return collections that were valid at this point in time. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Collection]
|
An iterator over :class: |
Source code in ivcap_client/collection.py
add_item_to_collection(ivcap, collection_urn, item_urn, *, policy=None)
¶
Add an item to a collection with a prior deduplication check.
Before creating the membership aspect the server is queried to confirm
that no active collection-item.1 aspect already records this
(collection, item) pair. If found the call returns None (skip
silently). Otherwise a new aspect record is created with POST.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ivcap
|
IVCAP
|
The IVCAP client instance. |
required |
collection_urn
|
str
|
The collection entity URN. |
required |
item_urn
|
str
|
URN of the entity to add as a member. |
required |
policy
|
URN | None
|
Optional access policy URN for the membership aspect
( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CollectionItem | None
|
class: |
Raises:
| Type | Description |
|---|---|
|
exc: |
Source code in ivcap_client/collection.py
remove_item_from_collection(ivcap, collection_urn, item_urn)
¶
Remove an item from a collection by retracting its membership aspect.
Looks up the active collection-item.1 aspect for the
(collection_urn, item_urn) pair using a JSONPath filter, then
retracts it via DELETE /1/aspects/<id>. Items that are not
currently members of the collection are silently skipped.
This operation leaves a retracted (inactive) aspect record in the
DataFabric — the store is append-only by design. The item can be
re-added later by calling :func:add_item_to_collection again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ivcap
|
IVCAP
|
The IVCAP client instance. |
required |
collection_urn
|
str
|
The collection entity URN. |
required |
item_urn
|
str
|
URN of the entity to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
|
exc: |
Source code in ivcap_client/collection.py
retract_collection(ivcap, collection_urn)
¶
Fully retract a collection and all its item memberships.
All active collection-item.1 aspects for collection_urn are
retracted first (one DELETE per membership record, paginated), then
the collection.1 definition aspect is retracted.
The DataFabric is append-only — this leaves retracted (inactive) records behind but makes the collection invisible to normal queries. The operation cannot be undone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ivcap
|
IVCAP
|
The IVCAP client instance. |
required |
collection_urn
|
str
|
URN of the collection to retract. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Total number of aspect records retracted (items + 1 definition). |
Raises:
| Type | Description |
|---|---|
|
exc: |
|
|
exc: |
Source code in ivcap_client/collection.py
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |
Schema Constants¶
| Constant | Value |
|---|---|
COLLECTION_SCHEMA |
urn:ivcap:schema:collection.1 |
COLLECTION_ITEM_SCHEMA |
urn:ivcap:schema:collection-item.1 |
See Also¶
- Guide: Collections — Usage patterns and examples
- API Reference: IVCAP Client —
create_collection(),get_collection(),list_collections(),add_to_collection(),remove_from_collection(),retract_collection() - API Reference: Aspect — The underlying aspect primitives