Code to transform Axiell Collections records into av-efi-schema compliant records.
For installation, you need
- Python >=3.11 and
- Poetry
installed. Run
git clone https://github.com/your-org/av-efi-generator.git
cd av-efi-generatorto clone the repository and
poetry installto install all dependencies.
Two key files define translation logic:
src/collections2efi/record_definitions.tomlmaps av-efi-schema class values to python translation functions.src/collections2efi/mappings/mappings.tomldefines the vocabulary mapping from collections to AV-EFI enums.
The system supports simple mappings (direct XPath to Enum) and complex mappings (delegated to functions in src/collections2efi/record_type/).
The library relies on three main components to orchestrate the translation:
- Records: Wrappers around raw XML data that provide helper methods for traversing relationships.
CollectRecord: The primary record (Work, Manifestation, Item).PeopleRecord&ThesauRecord: Auxiliary context for persons and thesaurus terms.
- Repositories: In-memory stores (
PeopleRepo,ThesauRepo) for the auxiliary records, working as a cache. - Translator: The core logic that applies the configured mappings. It combines a
CollectRecordwith data from the repositories to produce an AV-EFI object.
This script demonstrates a fetch-translate-purge cycle.
Ensure the SDK_AXIELL_COLLECTIONS_URL environment variable is set.
Ensure the SDK_AXIELL_COLLECTIONS_CACHED environment variable is set. See Caching.
export SDK_AXIELL_COLLECTIONS_URL=http://...
export SDK_AXIELL_COLLECTIONS_CACHED=1
poetry run python main.pyProcess Flow:
- Fetch: Retrieves records
- via pointer files
- via direct input
- via subgraph exploration on direct input
- Contextualize: Fetches and "caches" related people and thesaurus records.
- Translate: Converts records using the
Translator. - Purge: Removes orphan records (records without valid parents).
- Output: Writes the final JSON to the
tmpdirectory.
This temporary script provides an outline on how PIDs could be written back into collections.
During development, it was very helpful to have the requests to the axiell collections database cached.
This was done very rudimentarily by using the package requests-cache.
For caching set SDK_AXIELL_COLLECTIONS_CACHED = 1.
Note: There is no cache invalidation implemented, to invalidate delete the generated axiell_collections_cache.sqlite database.
Regression tests in ./tests/test_complete_records.py verify output against known states stored in ./tests/test_complete_records.
Unit tests for the specific mappings functions are located in the folders work, manifestation, and item. At this point they are very incomplete.
Update and run populate_test_records.py with required records before running tests.
poetry run pytestNote: Sensitive data (like names) is redacted from stored files for privacy.
Code quality is enforced via ruff.
- Lint with
poetry run ruff check --fix
- Format with
poetry run ruff format
To upgrade the schema, update the git commit hash in pyproject.toml and run:
poetry update avefi-schema
poetry installStructured logging is configured in logging_config.toml and writes to logs/. Use these logs to monitor:
- Mapping errors and data inconsistencies.
- API connectivity issues.
- Processing statistics (counts, purges).