Python wrapper for Solrmarc – converts MARC records to Solr documents via the Solrmarc Java tool
Project description
pysolrmarc
A Python wrapper for Solrmarc that converts binary MARC records into Solr documents by communicating with the Solrmarc Java process via stdin/stdout (NDJSON).
Installation
pip install pysolrmarc
Prerequisites
- Java 8+ must be installed and available on
PATH. - A Solrmarc installation directory (default:
/opt/solrmarc) containing:solrmarc/solrmarc_core_ant.jarsolrmarc/lib/(Java dependencies)solrmarc/lib_solrj/andsolrmarc/lib_local/solrmarc/log4j.properties- A mapping properties file (e.g.
index.kxp.tit.properties) - A reader options file (e.g.
marcreader.properties)
Quick Start
import pysolrmarc
with pysolrmarc.Solrmarc(
mapping="/opt/solrmarc/mappings/ahn/index.kxp.tit.properties",
reader_opts="/opt/solrmarc/mappings/ahn/marcreader.properties",
) as sm:
solr_doc = sm.convert(binary_marc_record)
print(solr_doc)
The context manager ensures the Java process is terminated gracefully when done. You can also use it without with and call close() manually:
sm = pysolrmarc.Solrmarc(
mapping="/opt/solrmarc/mappings/ahn/index.kxp.tit.properties",
reader_opts="/opt/solrmarc/mappings/ahn/marcreader.properties",
path="/opt/solrmarc",
)
try:
solr_doc = sm.convert(binary_marc_record)
finally:
sm.close()
API Reference
Solrmarc(mapping, reader_opts, path="/opt/solrmarc")
Creates a new Solrmarc instance and starts the Java process.
| Parameter | Type | Description |
|---|---|---|
mapping |
str |
Full path to the Solrmarc mapping properties file. |
reader_opts |
str |
Full path to the reader options configuration file. |
path |
str |
Root path of the Solrmarc installation (default: /opt/solrmarc). |
Supports the context manager protocol (with statement).
convert(marc, retries=2) -> dict | None
Converts a single binary MARC record to a Solr document dict.
| Parameter | Type | Description |
|---|---|---|
marc |
bytes |
Binary MARC record data. |
retries |
int |
Number of retry attempts on timeout (default: 2). |
Returns a dict representing the Solr document, or None if Solrmarc returned an empty response.
Raises an Exception if JSON decoding fails or all retries are exhausted.
start() -> None
Starts the Solrmarc Java process. Called automatically on __init__. Use to restart after calling stop().
stop() -> None
Kills the Solrmarc process forcefully (sends SIGKILL).
restart() -> None
Stops and restarts the Solrmarc instance.
close() -> None
Terminates the Solrmarc process gracefully (sends SIGTERM). Called automatically when exiting a with block.
Build and Publish
pip install hatch
hatch build
uv publish dist/*
To publish to a private registry:
uv publish --publish-url https://git.slub-dresden.de/api/v4/projects/2300/packages/pypi dist/*
License
MIT – see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysolrmarc-0.5.0.tar.gz.
File metadata
- Download URL: pysolrmarc-0.5.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e656f649a9dd2300da5fa0282d4d7099d6ebd6a59672c55a0acf07bd12aeaa1d
|
|
| MD5 |
babfdf510217c8205b6d7c08cd9d1c8d
|
|
| BLAKE2b-256 |
595ff8d176012d001e41d8be32088ae29a457c162ddac32f9263c31742d1f44a
|
File details
Details for the file pysolrmarc-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pysolrmarc-0.5.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bdc3366339b4e09ba46e2732296280b6fd2a6247c6deb1304d7cbd2a81959f7
|
|
| MD5 |
71dba4173b1bab1c3e96063900ce7139
|
|
| BLAKE2b-256 |
3235643f66d9547e00df3d8207261e60122dc3b3ccbc2918f52ed8295b7adda9
|