API Docs

Invenio module for metadata storage.

class invenio_records.ext.InvenioRecords(app=None, **kwargs)[source]

Invenio-Records extension.

Extension initialization.

init_app(app, entry_point_group='invenio_records.jsonresolver', **kwargs)[source]

Flask application initialization.

Parameters:
  • app – The Flask application.
  • entry_point_group – The entrypoint for jsonresolver extensions. (Default: 'invenio_records.jsonresolver')
init_config(app)[source]

Initialize configuration.

Parameters:app – The Flask application.

Record API

Record API.

class invenio_records.api.Record(data, model=None)[source]

Define API for metadata creation and manipulation.

Initialize instance with dictionary data and SQLAlchemy model.

Parameters:
  • data – Dict with record metadata.
  • modelRecordMetadata instance.
commit(**kwargs)[source]

Store changes of the current record instance in the database.

  1. Send a signal invenio_records.signals.before_record_update with the current record to be committed as parameter.
  2. Validate the current record data.
  3. Commit the current record in the database.
  4. Send a signal invenio_records.signals.after_record_update
    with the committed record as parameter.
Keyword Arguments:
 
Returns:

The Record instance.

classmethod create(data, id_=None, **kwargs)[source]

Create a new record instance and store it in the database.

  1. Send a signal invenio_records.signals.before_record_insert with the new record as parameter.
  2. Validate the new record data.
  3. Add the new record in the database.
  4. Send a signal invenio_records.signals.after_record_insert with the new created record as parameter.
Keyword Arguments:
 
Parameters:
  • data – Dict with the record metadata.
  • id – Specify a UUID to use for the new record, instead of automatically generated.
Returns:

A new Record instance.

delete(force=False)[source]

Delete a record.

If force is False, the record is soft-deleted: record data will be deleted but the record identifier and the history of the record will be kept. This ensures that the same record identifier cannot be used twice, and that you can still retrieve its history. If force is True, then the record is completely deleted from the database.

  1. Send a signal invenio_records.signals.before_record_delete with the current record as parameter.
  2. Delete or soft-delete the current record.
  3. Send a signal invenio_records.signals.after_record_delete with the current deleted record as parameter.
Parameters:force – if True, completely deletes the current record from the database, otherwise soft-deletes it.
Returns:The deleted Record instance.
classmethod get_record(id_, with_deleted=False)[source]

Retrieve the record by id.

Raise a database exception if the record does not exist.

Parameters:
  • id – record ID.
  • with_deleted – If True then it includes deleted records.
Returns:

The Record instance.

classmethod get_records(ids, with_deleted=False)[source]

Retrieve multiple records by id.

Parameters:
  • ids – List of record IDs.
  • with_deleted – If True then it includes deleted records.
Returns:

A list of Record instances.

model_cls

alias of invenio_records.models.RecordMetadata

patch(patch)[source]

Patch record metadata.

Params patch:Dictionary of record metadata.
Returns:A new Record instance.
revert(revision_id)[source]

Revert the record to a specific revision.

  1. Send a signal invenio_records.signals.before_record_revert with the current record as parameter.
  2. Revert the record to the revision id passed as parameter.
  3. Send a signal invenio_records.signals.after_record_revert with the reverted record as parameter.
Parameters:revision_id – Specify the record revision id
Returns:The Record instance corresponding to the revision id
revisions

Get revisions iterator.

class invenio_records.api.RecordBase(data, model=None)[source]

Base class for Record and RecordBase.

Initialize instance with dictionary data and SQLAlchemy model.

Parameters:
  • data – Dict with record metadata.
  • modelRecordMetadata instance.
created

Get creation timestamp.

dumps(**kwargs)[source]

Return pure Python dictionary with record metadata.

id

Get model identifier.

replace_refs()[source]

Replace the $ref keys within the JSON.

revision_id

Get revision identifier.

updated

Get last updated timestamp.

validate(**kwargs)[source]

Validate record according to schema defined in $schema key.

Keyword Arguments:
 
  • format_checker – A format_checker is an instance of class jsonschema.FormatChecker containing business logic to validate arbitrary formats. For example:

    >>> from jsonschema import FormatChecker
    >>> from jsonschema.validators import validate
    >>> checker = FormatChecker()
    >>> checker.checks('foo')(lambda el: el.startswith('foo'))
    <function <lambda> at ...>
    >>> validate('foo', {'format': 'foo'}, format_checker=checker)
    

    returns None, which means that the validation was successful, while

    >>> validate('bar', {'format': 'foo'},
    ...    format_checker=checker)  # doctest: +IGNORE_EXCEPTION_DETAIL
    Traceback (most recent call last):
      ...
    ValidationError: 'bar' is not a 'foo'
      ...
    

    raises a jsonschema.exceptions.ValidationError.

  • validator – A jsonschema.IValidator class used for record validation. It will be used as cls argument when calling jsonschema.validate(). For example

    >>> from jsonschema.validators import extend, Draft4Validator
    >>> NoRequiredValidator = extend(
    ...     Draft4Validator,
    ...     validators={'required': lambda v, r, i, s: None}
    ... )
    >>> schema = {
    ...     'type': 'object',
    ...     'properties': {
    ...         'name': { 'type': 'string' },
    ...         'email': { 'type': 'string' },
    ...         'address': {'type': 'string' },
    ...         'telephone': { 'type': 'string' }
    ...     },
    ...     'required': ['name', 'email']
    ... }
    >>> from jsonschema.validators import validate
    >>> validate({}, schema, NoRequiredValidator)
    

    returns None, which means that the validation was successful, while

    >>> validate({}, schema)  # doctest: +IGNORE_EXCEPTION_DETAIL
    Traceback (most recent call last):
    ...
    ValidationError: 'name' is a required property
    ...
    

    raises a jsonschema.exceptions.ValidationError.

class invenio_records.api.RecordRevision(model)[source]

API for record revisions.

Initialize instance with the SQLAlchemy model.

class invenio_records.api.RevisionsIterator(model)[source]

Iterator for record revisions.

Initialize instance with the SQLAlchemy model.

next()[source]

Python 2.7 compatibility.

CLI

Click command-line interface for record management.

invenio_records.cli.option_pid_minter(_)[source]

Empty option.

invenio_records.cli.records_deprecation_warning()[source]

Add deprecation warning for records cli.

invenio_records.cli.records = <click.core.Group object>

Record management.

invenio_records.cli.create = <click.core.Command object>

Create new bibliographic record(s).

invenio_records.cli.patch = <click.core.Command object>

Patch existing bibliographic record.

invenio_records.cli.delete = <click.core.Command object>

Delete bibliographic record(s).

Configuration

Default values for records configuration.

invenio_records.config.RECORDS_VALIDATION_TYPES = {}

Pass additional types when validating a record against a schema. For more details, see: https://python-jsonschema.readthedocs.io/en/latest/validate/#validating-types.

Errors

Errors for Invenio-Records module.

exception invenio_records.errors.MissingModelError[source]

Error raised when a record has no model.

exception invenio_records.errors.RecordsError[source]

Base class for errors in Invenio-Records module.

Models

Record models.

class invenio_records.models.RecordMetadata(**kwargs)[source]

Represent a record metadata.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

Signals

Record module signals.

invenio_records.signals.after_record_delete = <blinker.base.NamedSignal object at 0x7fc80982ad50; 'after-record-delete'>

Signal sent after a record is deleted.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’].

Note

Do not perform any modification to the record here: they will be not persisted.

invenio_records.signals.after_record_insert = <blinker.base.NamedSignal object at 0x7fc80982a6d0; 'after-record-insert'>

Signal sent after a record is inserted.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’].

Note

Do not perform any modification to the record here: they will be not persisted.

invenio_records.signals.after_record_revert = <blinker.base.NamedSignal object at 0x7fc80982add0; 'after-record-revert'>

Signal sent after a record is reverted.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’].

Note

Do not perform any modification to the record here: they will be not persisted.

invenio_records.signals.after_record_update = <blinker.base.NamedSignal object at 0x7fc80982acd0; 'after-record-update'>

Signal sent after a record is updated.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’].

Note

Do not perform any modification to the record here: they will be not persisted.

invenio_records.signals.before_record_delete = <blinker.base.NamedSignal object at 0x7fc80982ad10; 'before-record-delete'>

Signal is sent before a record is deleted.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’].

invenio_records.signals.before_record_insert = <blinker.base.NamedSignal object at 0x7fc81118ae10; 'before-record-insert'>

Signal is sent before a record is inserted.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’]. Example event listener (subscriber) implementation:

def listener(sender, *args, **kwargs):
    record = kwargs['record']
    # do something with the record

from invenio_records.signals import before_record_insert
before_record_insert.connect(listener)
invenio_records.signals.before_record_revert = <blinker.base.NamedSignal object at 0x7fc80982ad90; 'before-record-revert'>

Signal is sent before a record is reverted.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’].

invenio_records.signals.before_record_update = <blinker.base.NamedSignal object at 0x7fc80982aad0; 'before-record-update'>

Signal is sent before a record is updated.

When implementing the event listener, the record data can be retrieved from kwarg[‘record’].