Models
models
In-memory bundle containers.
Classes
BundleCollection
Bases: Mapping[str, Any]
A named, keyed collection within a :class:Bundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Collection name from the bundle. |
required |
values
|
Mapping[str, Any]
|
Objects keyed by their identifiers. |
required |
Initialize a bundle collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Collection name from the bundle. |
required |
values
|
Mapping[str, Any]
|
Objects keyed by their identifiers. |
required |
Methods:
__getitem__
Return an object by identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Object identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The stored object. |
Raises:
| Type | Description |
|---|---|
BundleObjectNotFoundError
|
If |
__iter__
Iterate over object identifiers.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator over identifiers. |
__len__
Return the number of objects in the collection.
Returns:
| Type | Description |
|---|---|
int
|
Collection size. |
keys
Return the object identifiers in the collection.
Returns:
| Type | Description |
|---|---|
KeysView[str]
|
A view of the collection's object identifiers. |
Bundle
Bundle(collections: Mapping[str, BundleCollection], *, metadata: Mapping[str, Any] | None = None, extras: Mapping[str, Any] | None = None, name: str | None = None)
Bases: Mapping[str, BundleCollection]
Represent a GKM Bundle in memory.
Producer-defined collection names are preserved and can be accessed through
mapping syntax, attribute access, or :meth:collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collections
|
Mapping[str, BundleCollection]
|
Named object collections in the bundle. |
required |
metadata
|
Mapping[str, Any] | None
|
Bundle and provenance metadata. |
None
|
extras
|
Mapping[str, Any] | None
|
Top-level values that are not object collections. |
None
|
name
|
str | None
|
Registered or inferred bundle name. |
None
|
Initialize a bundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collections
|
Mapping[str, BundleCollection]
|
Named object collections in the bundle. |
required |
metadata
|
Mapping[str, Any] | None
|
Bundle and provenance metadata. |
None
|
extras
|
Mapping[str, Any] | None
|
Top-level values that are not object collections. |
None
|
name
|
str | None
|
Registered or inferred bundle name. |
None
|
Methods:
__getitem__
__getitem__(name: str) -> BundleCollection
Return a collection by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Collection name. |
required |
Returns:
| Type | Description |
|---|---|
BundleCollection
|
The matching collection. |
Raises:
| Type | Description |
|---|---|
BundleCollectionNotFoundError
|
If |
__iter__
Iterate over collection names.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator over collection names. |
__len__
Return the number of collections.
Returns:
| Type | Description |
|---|---|
int
|
Collection count. |
collection_names
Return the collection names in document order.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Names of the collections exposed by this bundle. |
__getattr__
__getattr__(name: str) -> BundleCollection
Provide attribute access to named collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Collection name. |
required |
Returns:
| Type | Description |
|---|---|
BundleCollection
|
The matching collection. |
Raises:
| Type | Description |
|---|---|
BundleCollectionNotFoundError
|
If |
collection
collection(name: str) -> BundleCollection
Return a collection by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Collection name. |
required |
Returns:
| Type | Description |
|---|---|
BundleCollection
|
The matching collection. |
Raises:
| Type | Description |
|---|---|
BundleCollectionNotFoundError
|
If |
resolve
Resolve an RFC 6901 JSON Pointer into this bundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pointer
|
str
|
Bundle-local pointer beginning with |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The referenced value. |
Raises:
| Type | Description |
|---|---|
BundleReferenceError
|
If the pointer is invalid or cannot be resolved. |
dereference
Return a value with all reachable local references replaced inline.
The complete bundle is used when value is omitted. The bundle itself remains
referenced.
Cycle-closing pointers remain referenced because JSON cannot represent a cyclic inline value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any | None
|
Value from this bundle to dereference, or |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A JSON-compatible, inline representation of the value. |
to_dict
Serialize the bundle to JSON-compatible Python values.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The complete serialized bundle. |
write
Write the bundle to a file.
Writing preserves collection names, identifiers, local references, metadata, and producer-specific values, but the result may not be byte-for-byte identical to the input. Output is not validated against the producer's schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination
|
str | Path
|
Output file path. |
required |
serialization
|
str
|
Output serialization. Only |
'json'
|
indent
|
int | None
|
Number of spaces used to indent JSON, or |
2
|
Raises:
| Type | Description |
|---|---|
BundleSerializationError
|
If |