# oarepo\_oaipmh\_harvester.writers

## `oarepo_oaipmh_harvester.writers`

Writers for OAI-PMH harvested records.

This package ships the oai-service writer, which brings the local records to the harvested state through the model's service and keeps a harvest record for every harvested OAI identifier.

What the harvest record contains, how errors are stored and how to write additional writers is described in [Readers, transformers and writers](<https://oarepo.github.io/oarepo-oaipmh-harvester/readers-transformers-writers.html>).

Modules:

| Name | Description |
| --- | --- |
| `oai_service` | `oai-service` writer - synchronizes local records with harvested ones. |

### `OAIServiceWriter`

Bases: `BaseWriter`

Writer for OAI-PMH harvested records.

This writer uses a service to write records harvested via OAI-PMH. It also stores an OAIRecord model instance to keep track of the harvesting status.

#### `service: RecordService`

Get the service for the specified model.

#### `__init__(model: str, *args: Any, identity: Identity | None = None, update_all: bool = False, harvester_id: str | None = None, pid_field: str = 'id', publish: bool = True, direct_update: bool = False, community: str | None = None, **kwargs: Any)`

Initialize the OAI service writer.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `model` | `str` | Name of the target model (`current_runtime.models`). | *required* |
| `identity` | `Identity \| None` | Identity used for the service calls, defaults to the system identity. | `None` |
| `update_all` | `bool` | Write every record, even if it is up to date. | `False` |
| `harvester_id` | `str \| None` | Harvester the harvest records belong to (set by the harvest task). | `None` |
| `pid_field` | `str` | Path of the pid value in the service result. | `'id'` |
| `publish` | `bool` | Publish created / updated drafts. Required (`ValueError` otherwise) for rdm models; `False` only for models without drafts. | `True` |
| `direct_update` | `bool` | Update published records via `service.update` instead of edit - update draft - publish. Only for services that allow updating published records (drafts services do not by default). | `False` |
| `community` | `str \| None` | Slug (or id) of a community every written record is added to. Only for rdm models. | `None` |

#### `write(stream_entry: StreamEntry, *args: Any, **kwargs: Any) -> StreamEntry`

Write the input entry using a given service.

#### `write_many(stream_entries: list[StreamEntry], *args: Any, **kwargs: Any) -> list[StreamEntry]`

Write the input entries using a given service.
