Admin (Sets)¶
Admin
¶
Admin(client: AlmaAPIClient)
Enhanced Admin domain class for handling Alma Admin/Configuration API operations.
Now supports:
- BIB_MMS sets (original functionality)
- USER sets (new for email update project)
- Flexible set processing with type validation
- Enhanced error handling and logging
Initialize the Admin domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AlmaAPIClient
|
The AlmaAPIClient instance for making HTTP requests |
required |
Source code in src/almaapitk/domains/admin.py
get_set_members
¶
Extract all member IDs from an Alma set using pagination.
This method now supports both BIB_MMS and USER sets automatically, or can validate against a specific expected type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The ID of the Alma set (e.g., "25793308630004146") |
required |
expected_type
|
Optional[str]
|
Optional validation - "BIB_MMS", "USER", or None for auto-detect |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of member IDs from the set (MMS IDs for BIB sets, User IDs for USER sets) |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If set_id is empty or set type doesn't match expected |
AlmaAPIError
|
If the API request fails |
Source code in src/almaapitk/domains/admin.py
get_user_set_members
¶
Extract all user IDs from a USER set (convenience method).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The ID of the Alma USER set |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List of user IDs from the set |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If set is not a USER set |
AlmaAPIError
|
If the API request fails |
Source code in src/almaapitk/domains/admin.py
get_bib_set_members
¶
Extract all MMS IDs from a BIB_MMS set (convenience method).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The ID of the Alma BIB_MMS set |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List of MMS IDs from the set |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If set is not a BIB_MMS set |
AlmaAPIError
|
If the API request fails |
Source code in src/almaapitk/domains/admin.py
validate_user_set
¶
Validate that a set exists and is a USER type set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The set ID to validate |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing set information if valid |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If set doesn't exist or is not USER type |
AlmaAPIError
|
If API request fails |
Source code in src/almaapitk/domains/admin.py
get_set_info
¶
Get detailed information about a set (public method).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The set ID |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing set information including name, description, type, etc. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If set_id is empty |
AlmaAPIError
|
If API request fails |
Source code in src/almaapitk/domains/admin.py
get_set_metadata_and_member_count
¶
Get set metadata and member count for user sets (enhanced method).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The set ID |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with metadata and member count information |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If set_id is empty |
AlmaAPIError
|
If API request fails |
Source code in src/almaapitk/domains/admin.py
list_sets
¶
list_sets(
limit: int = 25,
offset: int = 0,
content_type: str = None,
include_member_counts: bool = False,
) -> AlmaResponse
List sets with optional filtering.
Note: The Alma API list endpoint does NOT include member counts in the response. Member counts are only available via individual set API calls. Set include_member_counts=True to fetch member counts (slower but complete).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of results to return (max 100) |
25
|
offset
|
int
|
Starting point for results |
0
|
content_type
|
str
|
Optional filter by content type (BIB_MMS, USER, etc.) |
None
|
include_member_counts
|
bool
|
If True, fetch member counts via individual API calls (slower) |
False
|
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse containing the list of sets |
Raises:
| Type | Description |
|---|---|
AlmaAPIError
|
If API request fails |
Source code in src/almaapitk/domains/admin.py
get_environment
¶
test_connection
¶
Test if the admin/configuration endpoints are accessible.
Returns:
| Type | Description |
|---|---|
bool
|
True if connection successful, False otherwise |
Source code in src/almaapitk/domains/admin.py
create_set
¶
create_set(set_data: Dict[str, Any]) -> AlmaResponse
Create a new itemized or logical set.
Wraps POST /almaws/v1/conf/sets. set_data must include at
minimum the name and type fields Alma requires; the rest
of the payload (description, content type, status, query, etc.)
is passed through verbatim so callers can build any set Alma
accepts without having to wait for explicit kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_data
|
Dict[str, Any]
|
Set object payload. Required keys:
Almost every real call also wants |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse wrapping the create response. The created set's |
AlmaResponse
|
|
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
AlmaAPIError
|
On API failure (typed subclass when the Alma
error code or HTTP status maps to one — see
|
Example
response = admin.create_set({ ... "name": "My BIB set", ... "type": {"value": "ITEMIZED"}, ... "content": {"value": "BIB_MMS"}, ... }) set_id = response.data["id"]
Source code in src/almaapitk/domains/admin.py
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 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 | |
update_set
¶
update_set(
set_id: str, set_data: Dict[str, Any]
) -> AlmaResponse
Update an existing set's metadata.
Wraps PUT /almaws/v1/conf/sets/{set_id}. Alma expects a
complete set object (see get_set_info for the shape Alma
returns); callers typically read the current set, mutate the
fields they want to change, and pass the whole dict here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The Alma set identifier to update. |
required |
set_data
|
Dict[str, Any]
|
Full set object payload. Must be a non-empty dict. |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse wrapping the updated set object. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
AlmaAPIError
|
On API failure. |
Example
info = admin.get_set_info(set_id) info["description"] = "Updated description" response = admin.update_set(set_id, info)
Source code in src/almaapitk/domains/admin.py
delete_set
¶
delete_set(set_id: str) -> AlmaResponse
Delete a set.
Wraps DELETE /almaws/v1/conf/sets/{set_id}. Removes the set
record from Alma; the underlying member records (bibs, users,
etc.) are untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The Alma set identifier to delete. |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse wrapping the delete response. Alma typically |
AlmaResponse
|
returns an empty body on a successful delete. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
AlmaAPIError
|
On API failure. |
Source code in src/almaapitk/domains/admin.py
add_members_to_set
¶
add_members_to_set(
set_id: str, member_ids: List[str]
) -> AlmaResponse
Add members to an existing set.
Wraps POST /almaws/v1/conf/sets/{set_id}?op=add_members. The
body shape Alma expects is {"members": {"member": [{"id":
"<member_id>"}, ...]}}.
Member-content validation: a BIB_MMS set takes MMS IDs and
a USER set takes user primary IDs. Caller-side ID-shape
validation is intentionally NOT performed here — Alma owns that
rule and will reject mismatched IDs server-side with a typed
error code (60116 / 60120).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The Alma set identifier to extend. |
required |
member_ids
|
List[str]
|
Non-empty list of member IDs to add. Each entry must be a non-empty string. |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse wrapping the updated set object. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
AlmaAPIError
|
On API failure. |
Source code in src/almaapitk/domains/admin.py
remove_members_from_set
¶
remove_members_from_set(
set_id: str, member_ids: List[str]
) -> AlmaResponse
Remove members from an existing set.
Wraps POST /almaws/v1/conf/sets/{set_id}?op=delete_members.
Body shape matches add_members_to_set: {"members":
{"member": [{"id": "<member_id>"}, ...]}}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id
|
str
|
The Alma set identifier to shrink. |
required |
member_ids
|
List[str]
|
Non-empty list of member IDs to remove. Each entry must be a non-empty string. |
required |
Returns:
| Type | Description |
|---|---|
AlmaResponse
|
AlmaResponse wrapping the updated set object. |
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
AlmaAPIError
|
On API failure. |