API Docs¶
Invenio module for metadata storage.
-
class
invenio_records.ext.
InvenioRecords
(app=None, **kwargs)[source]¶ Invenio-Records extension.
Extension initialization.
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.
- model –
RecordMetadata
instance.
-
commit
(**kwargs)[source]¶ Store changes of the current record instance in the database.
- Send a signal
invenio_records.signals.before_record_update
with the current record to be committed as parameter. - Validate the current record data.
- Commit the current record in the database.
- Send a signal
invenio_records.signals.after_record_update
- with the committed record as parameter.
- Send a signal
Keyword Arguments: - format_checker –
An instance of the class
jsonschema.FormatChecker
, which contains validation rules for formats. Seevalidate()
for more details. - validator –
A
jsonschema.IValidator
class that will be used to validate the record. Seevalidate()
for more details.
Returns: The
Record
instance.- Send a signal
-
classmethod
create
(data, id_=None, **kwargs)[source]¶ Create a new record instance and store it in the database.
- Send a signal
invenio_records.signals.before_record_insert
with the new record as parameter. - Validate the new record data.
- Add the new record in the database.
- Send a signal
invenio_records.signals.after_record_insert
with the new created record as parameter.
Keyword Arguments: - format_checker –
An instance of the class
jsonschema.FormatChecker
, which contains validation rules for formats. Seevalidate()
for more details. - validator –
A
jsonschema.IValidator
class that will be used to validate the record. Seevalidate()
for more details.
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.- Send a signal
-
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 isTrue
, then the record is completely deleted from the database.- Send a signal
invenio_records.signals.before_record_delete
with the current record as parameter. - Delete or soft-delete the current record.
- 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.- Send a signal
-
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
¶
-
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.
- Send a signal
invenio_records.signals.before_record_revert
with the current record as parameter. - Revert the record to the revision id passed as parameter.
- 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- Send a signal
-
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.
- model –
RecordMetadata
instance.
-
created
¶ Get creation timestamp.
-
id
¶ Get model identifier.
-
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 classjsonschema.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 callingjsonschema.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
.
CLI¶
Click command-line interface for record management.
-
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.
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’].