Bibliography¶
Bibliography facade exposed through the TeXSmith public API.
- Architecture
-
BibliographyCollectioncentralises reference merging, deduplication, and- portable export so higher layers can treat bibliographies as immutable
- dictionaries. The collection records provenance internally so API consumers
- can report issues with source context.
-
DoiBibliographyFetcherencapsulates remote lookups so IO code remains outside- the pure transformation layers. Callers provide a DOI and receive parsed
- BibTeX data ready to inject into the collection.
bibliography_data_from_stringaccepts inline BibTeX payloads and converts them intoBibliographyDataobjects, enabling templating systems to embed references alongside content.
- Implementation Rationale
-
- The public API needs a stable, documented entry point that is decoupled from
- the evolving internal package layout. Re-exporting the curated primitives keeps
- backward compatibility guarantees manageable.
- Aggregation logic lives in
collection.pyso both the CLI and the programmatic API can reuse it. By funnelling access through this module we expose documentation and doctest examples close to the import surface users reach for first.
Usage Example
>>> from texsmith.core.bibliography import BibliographyCollection, bibliography_data_from_string
>>> collection = BibliographyCollection()
>>> payload = """@article{doe2023,
... author = {Doe, Jane},
... title = {A Minimal Example},
... year = {2023},
... }"""
>>> inline = bibliography_data_from_string(payload, "doe2023")
>>> collection.load_data(inline, source="inline.bib")
>>> reference = collection.find("doe2023")
>>> reference["fields"]["title"]
'A Minimal Example'
BibliographyCollection ¶
BibliographyCollection()
Aggregate references from one or more BibTeX sources.
Source code in src/texsmith/core/bibliography/collection.py
22 23 24 25 26 27 | |
file_stats
property
¶
file_stats: Sequence[tuple[Path, int]]
Return (file, entry_count) pairs in the order files were processed.
issues
property
¶
issues: Sequence[BibliographyIssue]
Return the list of issues discovered while loading references.
clone ¶
clone() -> BibliographyCollection
Return a deep copy of the collection without reparsing sources.
Source code in src/texsmith/core/bibliography/collection.py
203 204 205 206 207 208 209 210 211 | |
find ¶
find(reference_key: str) -> dict[str, Any] | None
Return the portable representation of a specific reference.
Source code in src/texsmith/core/bibliography/collection.py
149 150 151 152 153 154 155 | |
list_references ¶
list_references() -> list[dict[str, Any]]
Return all references as portable dictionaries sorted by key.
Source code in src/texsmith/core/bibliography/collection.py
157 158 159 160 161 162 | |
load_data ¶
load_data(
data: BibliographyData,
*,
source: Path | str | None = None,
) -> None
Merge pre-parsed bibliography data into the collection.
Source code in src/texsmith/core/bibliography/collection.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
load_files ¶
load_files(files: Iterable[Path | str]) -> None
Load BibTeX entries from one or more files.
Source code in src/texsmith/core/bibliography/collection.py
39 40 41 42 | |
to_bibliography_data ¶
to_bibliography_data(
*, keys: Iterable[str] | None = None
) -> BibliographyData
Return a BibliographyData object scoped to the selected keys.
Source code in src/texsmith/core/bibliography/collection.py
171 172 173 174 175 176 177 178 | |
to_dict ¶
to_dict() -> dict[str, dict[str, Any]]
Return a dictionary keyed by reference identifiers.
Source code in src/texsmith/core/bibliography/collection.py
164 165 166 167 168 169 | |
write_bibtex ¶
write_bibtex(
target: Path | str, *, keys: Iterable[str] | None = None
) -> None
Persist the bibliography to a BibTeX file.
Source code in src/texsmith/core/bibliography/collection.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
BibliographyIssue
dataclass
¶
BibliographyIssue(
message: str,
key: str | None = None,
source: Path | None = None,
)
Represents a problem encountered while loading bibliography entries.
DoiBibliographyFetcher ¶
DoiBibliographyFetcher(
*,
session: Session | None = None,
timeout: float = 10.0,
user_agent: str | None = None,
cache: MutableMapping[str, str] | None = None,
cache_dir: Path | None = None,
enable_cache: bool = True,
)
Retrieve BibTeX entries for DOIs using content negotiation fallbacks.
Source code in src/texsmith/core/bibliography/doi.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
fetch ¶
fetch(value: str) -> str
Return the BibTeX payload for a DOI, trying multiple providers.
Source code in src/texsmith/core/bibliography/doi.py
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 | |
DoiLookupError ¶
Bases: Exception
Raised when resolving a DOI to a BibTeX payload fails.
bibliography_data_from_inline_entry ¶
bibliography_data_from_inline_entry(
key: str, entry: InlineBibliographyEntry
) -> BibliographyData
Create a BibliographyData instance from a manual inline entry.
Source code in src/texsmith/core/bibliography/parsing.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
bibliography_data_from_string ¶
bibliography_data_from_string(
payload: str, key: str
) -> BibliographyData
Parse a BibTeX payload and scope it to a specific reference key.
Source code in src/texsmith/core/bibliography/parsing.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Aggregation utilities for BibTeX references.
BibliographyCollection ¶
BibliographyCollection()
Aggregate references from one or more BibTeX sources.
Source code in src/texsmith/core/bibliography/collection.py
22 23 24 25 26 27 | |
file_stats
property
¶
file_stats: Sequence[tuple[Path, int]]
Return (file, entry_count) pairs in the order files were processed.
issues
property
¶
issues: Sequence[BibliographyIssue]
Return the list of issues discovered while loading references.
clone ¶
clone() -> BibliographyCollection
Return a deep copy of the collection without reparsing sources.
Source code in src/texsmith/core/bibliography/collection.py
203 204 205 206 207 208 209 210 211 | |
find ¶
find(reference_key: str) -> dict[str, Any] | None
Return the portable representation of a specific reference.
Source code in src/texsmith/core/bibliography/collection.py
149 150 151 152 153 154 155 | |
list_references ¶
list_references() -> list[dict[str, Any]]
Return all references as portable dictionaries sorted by key.
Source code in src/texsmith/core/bibliography/collection.py
157 158 159 160 161 162 | |
load_data ¶
load_data(
data: BibliographyData,
*,
source: Path | str | None = None,
) -> None
Merge pre-parsed bibliography data into the collection.
Source code in src/texsmith/core/bibliography/collection.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
load_files ¶
load_files(files: Iterable[Path | str]) -> None
Load BibTeX entries from one or more files.
Source code in src/texsmith/core/bibliography/collection.py
39 40 41 42 | |
to_bibliography_data ¶
to_bibliography_data(
*, keys: Iterable[str] | None = None
) -> BibliographyData
Return a BibliographyData object scoped to the selected keys.
Source code in src/texsmith/core/bibliography/collection.py
171 172 173 174 175 176 177 178 | |
to_dict ¶
to_dict() -> dict[str, dict[str, Any]]
Return a dictionary keyed by reference identifiers.
Source code in src/texsmith/core/bibliography/collection.py
164 165 166 167 168 169 | |
write_bibtex ¶
write_bibtex(
target: Path | str, *, keys: Iterable[str] | None = None
) -> None
Persist the bibliography to a BibTeX file.
Source code in src/texsmith/core/bibliography/collection.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
Helpers for resolving DOIs to BibTeX payloads.
DoiBibliographyFetcher ¶
DoiBibliographyFetcher(
*,
session: Session | None = None,
timeout: float = 10.0,
user_agent: str | None = None,
cache: MutableMapping[str, str] | None = None,
cache_dir: Path | None = None,
enable_cache: bool = True,
)
Retrieve BibTeX entries for DOIs using content negotiation fallbacks.
Source code in src/texsmith/core/bibliography/doi.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
fetch ¶
fetch(value: str) -> str
Return the BibTeX payload for a DOI, trying multiple providers.
Source code in src/texsmith/core/bibliography/doi.py
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 | |
DoiLookupError ¶
Bases: Exception
Raised when resolving a DOI to a BibTeX payload fails.
normalise_doi ¶
normalise_doi(value: str) -> str
Return a canonical representation for DOI strings.
Source code in src/texsmith/core/bibliography/doi.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
Shared data structures for bibliography processing.
BibliographyIssue
dataclass
¶
BibliographyIssue(
message: str,
key: str | None = None,
source: Path | None = None,
)
Represents a problem encountered while loading bibliography entries.
Parsing helpers for bibliography payloads.
bibliography_data_from_inline_entry ¶
bibliography_data_from_inline_entry(
key: str, entry: InlineBibliographyEntry
) -> BibliographyData
Create a BibliographyData instance from a manual inline entry.
Source code in src/texsmith/core/bibliography/parsing.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
bibliography_data_from_string ¶
bibliography_data_from_string(
payload: str, key: str
) -> BibliographyData
Parse a BibTeX payload and scope it to a specific reference key.
Source code in src/texsmith/core/bibliography/parsing.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |