Bibliographic Records¶
build_alma_bib_xml
¶
Build Alma's non-namespaced <bib><record> MARCXML from a spec.
Pure, network-free helper (the XML-assembly shape mirrors
BibliographicRecords._build_updated_marc_xml but is spec-driven and
escapes exactly once). The spec is plain JSON-serialisable data so it
is usable from non-Python callers (e.g. Power Automate)::
spec = {
"leader": " nam a22 3i 4500", # optional; default if omitted
"fields": [
{"tag": "008", "data": "..."}, # control field
{"tag": "245", "ind1": "1", "ind2": "0",
"subfields": [["a", "Data Reduction Methods"]]}, # data field
{"tag": "650", "ind1": " ", "ind2": "0",
"subfields": [["a", "Data reduction"]]},
{"tag": "650", "ind1": " ", "ind2": "0",
"subfields": [["a", "Data science"]]},
],
}
Beyond spec shape, the builder enforces MARC content designation
(issue #187) so it is not more permissive than the editing/reading paths:
tags must be three digits, control vs data is decided by the tag (00X
is a control field carrying data; 010-999 is a data field
carrying subfields — a data-range tag with data is rejected),
subfield codes are a single lowercase letter or digit, and indicators are a
blank / digit / lowercase letter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Dict[str, Any]
|
Mapping with an optional |
required |
require_245
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A |
str
|
meth: |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If the spec is malformed (not a dict, missing or
empty |
Source code in src/almaapitk/domains/bibs.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 | |
BibliographicRecords
¶
BibliographicRecords(client: AlmaAPIClient)
Domain class for handling Alma Bibliographic Records API operations. Builds upon and improves the existing bib record functionality.
Source code in src/almaapitk/domains/bibs.py
get_record
¶
get_record(
mms_id: str, view: str = "full", expand: str = None
) -> AlmaResponse
Retrieve a bibliographic record by MMS ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
view
|
str
|
Level of detail (brief, full) |
'full'
|
expand
|
str
|
Additional data to include (p_avail, e_avail, d_avail) |
None
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the bibliographic record |
Source code in src/almaapitk/domains/bibs.py
create_record
¶
create_record(
marc_xml: str,
validate: bool = True,
override_warning: bool = False,
) -> AlmaResponse
Create a new bibliographic record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
marc_xml
|
str
|
MARC XML data for the record |
required |
validate
|
bool
|
Whether to validate the record |
True
|
override_warning
|
bool
|
Whether to override validation warnings |
False
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the created record |
Source code in src/almaapitk/domains/bibs.py
create_record_from_fields
¶
create_record_from_fields(
spec: Dict[str, Any],
validate: bool = True,
override_warning: bool = False,
require_245: bool = True,
) -> AlmaResponse
Create a new bibliographic record from a native, structure-driven spec.
Builds Alma's non-namespaced <bib><record> XML from spec via
:func:build_alma_bib_xml and funnels it into :meth:create_record,
so callers never hand-assemble MARCXML. Pattern source: thin
builder-then-create_record wrapper (issue #179).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Dict[str, Any]
|
JSON-serialisable field structure (see
:func: |
required |
validate
|
bool
|
Whether Alma should validate the record. |
True
|
override_warning
|
bool
|
Whether to override validation warnings. |
False
|
require_245
|
bool
|
Assert client-side that the record has exactly one
|
True
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the created record. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
Source code in src/almaapitk/domains/bibs.py
create_record_from_pymarc
¶
create_record_from_pymarc(
record: Any,
validate: bool = True,
override_warning: bool = False,
require_245: bool = True,
) -> AlmaResponse
Create a new bibliographic record from a pymarc.Record.
Converts the record to a native spec and delegates to
:meth:create_record_from_fields. pymarc is an optional extra
(pip install almaapitk[pymarc]) imported lazily here so the core
install stays dependency-light (issue #179).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
Any
|
A |
required |
validate
|
bool
|
Whether Alma should validate the record. |
True
|
override_warning
|
bool
|
Whether to override validation warnings. |
False
|
require_245
|
bool
|
Assert client-side that the record has exactly one
|
True
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the created record. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
Source code in src/almaapitk/domains/bibs.py
update_record
¶
update_record(
mms_id: str,
marc_xml: str,
validate: bool = True,
override_warning: bool = True,
override_lock: bool = True,
stale_version_check: bool = False,
) -> AlmaResponse
Update an existing bibliographic record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the record to update |
required |
marc_xml
|
str
|
Updated MARC XML data |
required |
validate
|
bool
|
Whether to validate the record |
True
|
override_warning
|
bool
|
Whether to override validation warnings |
True
|
override_lock
|
bool
|
Whether to override record locks |
True
|
stale_version_check
|
bool
|
Whether to check for stale versions |
False
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the updated record |
Source code in src/almaapitk/domains/bibs.py
delete_record
¶
delete_record(
mms_id: str, override_attached_items: bool = False
) -> AlmaResponse
Delete a bibliographic record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the record to delete |
required |
override_attached_items
|
bool
|
Whether to delete even if items are attached (overrides Alma's deletion warnings). |
False
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse confirming deletion |
Source code in src/almaapitk/domains/bibs.py
update_marc_field
¶
update_marc_field(
mms_id: str,
field: str,
subfields: SubfieldsArg,
ind1: str = " ",
ind2: str = " ",
mode: str = "replace_first",
) -> AlmaResponse
Update, replace, or append a MARC field in a bibliographic record.
Many MARC tags (6XX/5XX/7XX/020/490/856, etc.) are repeatable, so a
record routinely carries several occurrences of the same tag (e.g. three
650 subject headings). This method only touches the occurrence(s)
selected by mode and preserves every other occurrence untouched, so
an update to one instance never silently drops the rest (issue #184).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the record. |
required |
field
|
str
|
MARC field number (e.g. |
required |
subfields
|
SubfieldsArg
|
Subfields for the new/updated field, in one of two
shapes (see :data:
|
required |
ind1
|
str
|
First indicator for the new/updated field. |
' '
|
ind2
|
str
|
Second indicator for the new/updated field. |
' '
|
mode
|
str
|
How to apply the change to the target tag:
|
'replace_first'
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the updated record. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
AlmaAPIError
|
If the record cannot be retrieved or has no MARC XML. |
Source code in src/almaapitk/domains/bibs.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 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 | |
get_holdings
¶
get_holdings(
mms_id: str, holding_id: str = None
) -> AlmaResponse
Get holdings for a bibliographic record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
holding_id
|
str
|
Specific holding ID, or None for all holdings |
None
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing holdings data |
Source code in src/almaapitk/domains/bibs.py
create_holding
¶
create_holding(
mms_id: str, holding_data: Dict[str, Any]
) -> AlmaResponse
Create a new holding record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
holding_data
|
Dict[str, Any]
|
Holding record data |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the created holding |
Source code in src/almaapitk/domains/bibs.py
get_items
¶
get_items(
mms_id: str,
holding_id: str = "ALL",
item_id: str = None,
) -> AlmaResponse
Get items for a bibliographic record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
holding_id
|
str
|
Holding ID or "ALL" for all holdings |
'ALL'
|
item_id
|
str
|
Specific item ID, or None for all items |
None
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing items data |
Source code in src/almaapitk/domains/bibs.py
create_item
¶
create_item(
mms_id: str, holding_id: str, item_data: Dict[str, Any]
) -> AlmaResponse
Create a new item record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
holding_id
|
str
|
The holding ID |
required |
item_data
|
Dict[str, Any]
|
Item record data |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the created item |
Source code in src/almaapitk/domains/bibs.py
scan_in_item
¶
scan_in_item(
mms_id: str,
holding_id: str,
item_pid: str,
library: str,
department: Optional[str] = None,
circ_desk: Optional[str] = None,
work_order_type: Optional[str] = None,
status: Optional[str] = None,
done: bool = False,
confirm: bool = True,
) -> AlmaResponse
Scan in an item to a department with optional work order.
This operation simulates the UI "Scan In Items" function, which allows placing items in a work order within a department. When used after receiving an item, it prevents the item from going into Transit status and keeps it in the specified department.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
holding_id
|
str
|
The holding ID |
required |
item_pid
|
str
|
The item PID (item identifier) |
required |
library
|
str
|
Library code where item should be scanned in |
required |
department
|
Optional[str]
|
Department code (provide either department or circ_desk) |
None
|
circ_desk
|
Optional[str]
|
Circulation desk code (alternative to department) |
None
|
work_order_type
|
Optional[str]
|
Work order type code (e.g., 'AcqWorkOrder') |
None
|
status
|
Optional[str]
|
Work order status (e.g., 'CopyCataloging', 'Labeling') |
None
|
done
|
bool
|
If True, completes the work order; if False, keeps item in department |
False
|
confirm
|
bool
|
Whether to bypass confirmation prompts (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the updated item data |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If required parameters are missing or invalid |
Example
Scan in item to acquisitions department with work order¶
bibs.scan_in_item( ... mms_id="99123456789", ... holding_id="22123456789", ... item_pid="23123456789", ... library="ACQ_LIB", ... department="ACQ_DEPT", ... work_order_type="AcqWorkOrder", ... status="CopyCataloging", ... done=False # Keep in department ... )
Notes
- Either department or circ_desk must be provided
- When done=False, item stays in department with work order
- When done=True, work order is completed and item may move to next step
- Work order configuration must exist in Alma (Configuration > Fulfillment > Physical Fulfillment > Work Order Types)
Source code in src/almaapitk/domains/bibs.py
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | |
get_representations
¶
get_representations(
mms_id: str, representation_id: str = None
) -> AlmaResponse
Get digital representations for a bibliographic record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
representation_id
|
str
|
Specific representation ID, or None for all |
None
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing representation data |
Source code in src/almaapitk/domains/bibs.py
create_representation
¶
create_representation(
mms_id: str,
access_rights_value: str,
access_rights_desc: str,
lib_code: str,
usage_type: str = "PRESERVATION_MASTER",
) -> AlmaResponse
Create a new digital representation. Enhanced version of your existing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
access_rights_value
|
str
|
Access rights policy value |
required |
access_rights_desc
|
str
|
Access rights description |
required |
lib_code
|
str
|
Library code |
required |
usage_type
|
str
|
Usage type for the representation |
'PRESERVATION_MASTER'
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the created representation |
Source code in src/almaapitk/domains/bibs.py
get_representation_files
¶
get_representation_files(
mms_id: str, representation_id: str, file_id: str = None
) -> AlmaResponse
Get files for a digital representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
representation_id
|
str
|
The representation ID |
required |
file_id
|
str
|
Specific file ID, or None for all files |
None
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing file data |
Source code in src/almaapitk/domains/bibs.py
link_file_to_representation
¶
link_file_to_representation(
mms_id: str, representation_id: str, file_path: str
) -> AlmaResponse
Link a file to a digital representation. Enhanced version of your existing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
representation_id
|
str
|
The representation ID |
required |
file_path
|
str
|
Path to the file in storage |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the linked file data |
Source code in src/almaapitk/domains/bibs.py
update_representation_file
¶
update_representation_file(
mms_id: str,
representation_id: str,
file_id: str,
file_data: Dict[str, Any],
) -> AlmaResponse
Update a file in a digital representation. Enhanced version of your existing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the bibliographic record |
required |
representation_id
|
str
|
The representation ID |
required |
file_id
|
str
|
The file ID |
required |
file_data
|
Dict[str, Any]
|
Updated file data |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the updated file data |
Source code in src/almaapitk/domains/bibs.py
get_collection_members
¶
get_collection_members(
collection_id: str, limit: int = 100, offset: int = 0
) -> AlmaResponse
Get bibliographic records that are members of a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_id
|
str
|
The collection ID |
required |
limit
|
int
|
Maximum number of records to return (default 100) |
100
|
offset
|
int
|
Starting position for pagination (default 0) |
0
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing list of bib records in the collection |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If collection_id is empty or None |
AlmaAPIError
|
If the API request fails (e.g., collection not found) |
Source code in src/almaapitk/domains/bibs.py
add_to_collection
¶
add_to_collection(
collection_id: str, mms_id: str
) -> AlmaResponse
Add a bibliographic record to a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_id
|
str
|
The collection ID |
required |
mms_id
|
str
|
The MMS ID of the bibliographic record to add |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the added bib record |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If collection_id or mms_id is empty or None |
AlmaAPIError
|
If the API request fails (e.g., collection/bib not found) |
Source code in src/almaapitk/domains/bibs.py
remove_from_collection
¶
remove_from_collection(
collection_id: str, mms_id: str
) -> AlmaResponse
Remove a bibliographic record from a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_id
|
str
|
The collection ID |
required |
mms_id
|
str
|
The MMS ID of the bibliographic record to remove |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse confirming removal |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If collection_id or mms_id is empty or None |
AlmaAPIError
|
If the API request fails (e.g., collection/bib not found) |
Source code in src/almaapitk/domains/bibs.py
get_marc_subfield
¶
Get specific MARC subfield values from a bibliographic record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mms_id
|
str
|
The MMS ID of the record |
required |
field
|
str
|
MARC data-field tag (e.g., "907"). Data fields (010-999) only — control fields (00X) have no subfields. |
required |
subfield
|
str
|
Subfield code (e.g., "e") |
required |
strict
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of subfield values; an empty list means the field/subfield |
List[str]
|
is genuinely absent from the record. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
for a missing |
AlmaAPIError / Exception
|
on fetch/parse failure only when
|
Source code in src/almaapitk/domains/bibs.py
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 | |