Utilities¶
TSVGenerator¶
TSVGenerator
¶
Config-driven TSV generator for Alma data processing.
This utility creates TSV files based on JSON configuration files, allowing for flexible column definitions and data sources.
Initialize TSV Generator with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str
|
Path to JSON configuration file |
required |
Source code in src/almaapitk/utils/tsv_generator.py
generate_tsv
¶
Generate TSV file based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_id_override
|
str
|
Optional override for the Alma set ID |
None
|
environment_override
|
str
|
Optional override for the environment |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the created TSV file |
Source code in src/almaapitk/utils/tsv_generator.py
preview_config
¶
Print a preview of the current configuration.
Source code in src/almaapitk/utils/tsv_generator.py
Citation metadata¶
Helpers used by ResourceSharing.create_lending_request_from_citation to
enrich requests from PubMed (PMID) or Crossref (DOI).
enrich_citation_metadata
¶
enrich_citation_metadata(
pmid: Optional[str] = None,
doi: Optional[str] = None,
source_type: Optional[str] = None,
) -> Dict[str, Any]
Fetch citation metadata from PubMed or Crossref.
Convenience function that fetches metadata from specified source or auto-detects.
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: If both PMID and DOI are provided, tries PubMed first, then Crossref as fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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). If None, uses auto-detect with fallback. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Metadata dictionary with 'source' field indicating which API was used |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither PMID nor DOI provided, or invalid source_type |
CitationMetadataError
|
If metadata fetch fails |
Examples:
>>> # Explicit source - recommended for form inputs
>>> metadata = enrich_citation_metadata(
... pmid="33219451",
... source_type='pmid'
... )
>>> # Explicit DOI source
>>> metadata = enrich_citation_metadata(
... doi="10.1038/s41591-020-1124-9",
... source_type='doi'
... )
>>> # Auto-detect mode (backward compatible)
>>> metadata = enrich_citation_metadata(pmid="33219451")
>>> # Auto-detect with fallback
>>> metadata = enrich_citation_metadata(
... pmid="33219451",
... doi="10.1038/s41591-020-1124-9"
... )
Source code in src/almaapitk/utils/citation_metadata.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 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 | |
CitationMetadataError
¶
Bases: Exception
Base exception for citation metadata errors.