Resource Sharing¶
ResourceSharing
¶
ResourceSharing(client: AlmaAPIClient)
Domain class for handling Alma Resource Sharing API operations.
Focuses on lending requests created "for a partner" using Alma's Resource Sharing Partners API.
This class uses the AlmaAPIClient as its foundation for all HTTP operations.
Attributes:
| Name | Type | Description |
|---|---|---|
client |
AlmaAPIClient instance for making HTTP requests |
|
environment |
Current environment (SANDBOX/PRODUCTION) |
|
logger |
Logger instance for this domain |
Initialize the ResourceSharing domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AlmaAPIClient
|
The AlmaAPIClient instance for making HTTP requests |
required |
Source code in src/almaapitk/domains/resource_sharing.py
create_lending_request
¶
create_lending_request(
partner_code: str,
external_id: str,
owner: str,
format_type: str,
title: str,
citation_type: Optional[str] = None,
mms_id: Optional[str] = None,
**optional_fields
) -> Dict[str, Any]
Create a new lending request for a partner.
Creates a lending request through the Alma Partners API. This represents a request from a partner institution to borrow material from your library.
API Endpoint
POST /almaws/v1/partners/{partner_code}/lending-requests
Mandatory Parameters
partner_code: Partner institution code (URL path parameter) external_id: External identifier for the request owner: Resource sharing library code (e.g., 'MAIN') format_type: Request format - 'PHYSICAL' or 'DIGITAL' title: Resource title (required unless mms_id is provided)
Optional Parameters
citation_type: Resource type (e.g., 'BOOK', 'JOURNAL') - required if no mms_id mms_id: Alma MMS ID if resource exists in your catalog **optional_fields: Additional fields from the schema: - author: str - isbn: str - issn: str - publisher: str - year: str (publication year, e.g., "2024") - edition: str - volume: str - issue: str - pages: str - doi: str - pmid: str - call_number: str - oclc_number: str - status: Dict[str, str] (e.g., {'value': 'REQUEST_CREATED_LEN'}) - requested_media: Dict[str, str] - preferred_send_method: Dict[str, str] - pickup_location: Dict[str, str] - last_interest_date: str (ISO format date) - level_of_service: Dict[str, str] - copyright_status: Dict[str, str] - rs_note: List[Dict] (notes array - note: singular field name!) - And other fields per schema
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partner_code
|
str
|
Partner institution code |
required |
external_id
|
str
|
External identifier for this request |
required |
owner
|
str
|
Resource sharing library code |
required |
format_type
|
str
|
Request format (PHYSICAL/DIGITAL) |
required |
title
|
str
|
Resource title |
required |
citation_type
|
Optional[str]
|
Resource type (BOOK/JOURNAL/etc.), required if no mms_id |
None
|
mms_id
|
Optional[str]
|
Alma MMS ID if resource is in catalog |
None
|
**optional_fields
|
Additional optional fields |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Created lending request as dictionary with request_id and all fields |
Raises:
| Type | Description |
|---|---|
ValueError
|
If mandatory fields are missing or invalid |
AlmaAPIError
|
If API request fails |
Examples:
>>> # Create basic lending request
>>> rs = ResourceSharing(client)
>>> request = rs.create_lending_request(
... partner_code="PARTNER_01",
... external_id="EXT-2025-001",
... owner="MAIN",
... format_type="PHYSICAL",
... title="Introduction to Library Science",
... citation_type="BOOK",
... author="Smith, John",
... isbn="978-0-123456-78-9",
... publisher="Academic Press",
... year="2024"
... )
>>> print(request['request_id'])
>>> # Create request for known catalog item
>>> request = rs.create_lending_request(
... partner_code="PARTNER_02",
... external_id="EXT-2025-002",
... owner="MAIN",
... format_type="DIGITAL",
... title="Advanced Cataloging",
... mms_id="991234567890123456",
... level_of_service={"value": "Rush"}
... )
Source code in src/almaapitk/domains/resource_sharing.py
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 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
get_lending_request
¶
Retrieve a lending request by ID.
Fetches complete details of an existing lending request from the Alma Partners API.
API Endpoint
GET /almaws/v1/partners/{partner_code}/lending-requests/{request_id}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partner_code
|
str
|
Partner institution code |
required |
request_id
|
str
|
Lending request identifier |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Lending request data as dictionary |
Raises:
| Type | Description |
|---|---|
AlmaAPIError
|
If API request fails or request not found |
Examples:
>>> rs = ResourceSharing(client)
>>> request = rs.get_lending_request(
... partner_code="PARTNER_01",
... request_id="12345678"
... )
>>> print(f"Title: {request['title']}")
>>> print(f"Status: {request['status']['value']}")
>>> print(f"Format: {request['format']['value']}")
Source code in src/almaapitk/domains/resource_sharing.py
get_request_summary
¶
Extract key information from a lending request for display.
Creates a simplified summary dictionary with the most important fields from a lending request response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_data
|
Dict[str, Any]
|
Complete lending request data dictionary |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary with summary information: - request_id: Request identifier - external_id: External identifier - title: Resource title - author: Resource author (if present) - citation_type: Resource type - format: Request format - status: Current status - partner: Partner code - owner: Owning library |
Examples:
>>> request = rs.get_lending_request("PARTNER_01", "12345678")
>>> summary = rs.get_request_summary(request)
>>> print(f"{summary['title']} - {summary['status']}")
Source code in src/almaapitk/domains/resource_sharing.py
create_lending_request_from_citation
¶
create_lending_request_from_citation(
partner_code: str,
external_id: str,
owner: str,
format_type: str,
pmid: Optional[str] = None,
doi: Optional[str] = None,
source_type: Optional[str] = None,
**override_fields
) -> Dict[str, Any]
Create a lending request with metadata auto-populated from PubMed or Crossref.
Fetches article metadata from PubMed (using PMID) or Crossref (using DOI) and creates a lending request with automatically populated citation fields.
When source_type is specified, ONLY that source is used (no fallback). This is recommended when you know the identifier type upfront (e.g., from a form).
When source_type is None, uses auto-detect mode with fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partner_code
|
str
|
Partner institution code |
required |
external_id
|
str
|
External identifier for this request |
required |
owner
|
str
|
Resource sharing library code |
required |
format_type
|
str
|
Request format (PHYSICAL/DIGITAL) |
required |
pmid
|
Optional[str]
|
PubMed ID (optional) |
None
|
doi
|
Optional[str]
|
Digital Object Identifier (optional) |
None
|
source_type
|
Optional[str]
|
Explicit source type - 'pmid' or 'doi' (optional). If specified, only that source is tried (no fallback). Recommended for form inputs where type is known. |
None
|
**override_fields
|
Additional fields to override auto-populated values |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Created lending request as dictionary |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither pmid nor doi provided, or validation fails |
CitationMetadataError
|
If metadata fetch fails |
AlmaAPIError
|
If API request fails |
Examples:
>>> # Explicit PMID source (recommended for form inputs)
>>> request = rs.create_lending_request_from_citation(
... partner_code="RELAIS",
... external_id="ILL-2025-001",
... owner="MAIN",
... format_type="DIGITAL",
... pmid="33219451",
... source_type='pmid'
... )
>>> # Explicit DOI source (recommended for form inputs)
>>> request = rs.create_lending_request_from_citation(
... partner_code="RELAIS",
... external_id="ILL-2025-002",
... owner="MAIN",
... format_type="DIGITAL",
... doi="10.1038/s41591-020-1124-9",
... source_type='doi'
... )
>>> # Auto-detect mode (backward compatible)
>>> request = rs.create_lending_request_from_citation(
... partner_code="RELAIS",
... external_id="ILL-2025-003",
... owner="MAIN",
... format_type="DIGITAL",
... pmid="33219451"
... )
>>> # Override specific fields
>>> request = rs.create_lending_request_from_citation(
... partner_code="RELAIS",
... external_id="ILL-2025-004",
... owner="MAIN",
... format_type="PHYSICAL",
... doi="10.1038/s41591-020-1124-9",
... source_type='doi',
... title="Custom Title Override" # Override auto-fetched title
... )
Source code in src/almaapitk/domains/resource_sharing.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 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 | |