API Docs

Record API

API for manipulating files associated to a record.

class invenio_records_files.api.FileObject(obj, data)[source]

Wrapper for files.

Bind to current bucket.


Create a dump of the metadata associated to the record.

get(key, default=None)[source]

Proxy to obj.

Parameters:key – Metadata key which holds the value.
Returns:Metadata value of the specified key or default.

Return specific version ObjectVersion instance or HEAD.

Parameters:version_id – Version ID of the object.
Returns:ObjectVersion instance or HEAD of the stored object.
class invenio_records_files.api.FilesIterator(record, bucket=None, file_cls=None)[source]

Iterator for files.

Initialize iterator.


Serialize files from a bucket.

Parameters:bucket – Instance of files invenio_files_rest.models.Bucket. (Default: self.bucket)
Returns:List of serialized files.

Flush changes to record.


Return file keys.


Python 2.7 compatibility.

rename(*args, **kwargs)[source]

Rename a file.

  • old_key – Old key that holds the object.
  • new_key – New key that will hold the object.

The object that has been renamed.


Update files order.

Parameters:ids – List of ids specifying the final status of the list.
class invenio_records_files.api.FilesMixin[source]

Implement files attribute for Record models.


Implement _create_bucket() in subclass to allow files property to automatically create a bucket in case no bucket is present.


File class used to generate the instance of files. Default to FileObject

alias of FileObject


Get files iterator.

Returns:Files iterator.

Files iterator class used to generate the files iterator. Default to FilesIterator

alias of FilesIterator

class invenio_records_files.api.Record(*args, **kwargs)[source]

Record class with associated bucket.

The record class implements a one-to-one relationship between a bucket and a record. A bucket is automatically created and associated with the record when the record is created with Record.create() (unless with_bucket is set to False).

The bucket id is stored in the record metadata (by default in the _bucket key). You can implement your dump/load behavior for storing the bucket id in the record (or possibly somewhere else). You do this by creating a subclass of this class, and overriding the two classmethods Record.dump_bucket() and Record.load_bucket().

Initialize the record.


Get bucket instance.


Get bucket id from record metadata.

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

Create a record and the associated bucket.

Parameters:with_bucket – Create a bucket automatically on record creation.
classmethod create_bucket(data)[source]

Create a bucket for this record.

Override this method to provide more advanced bucket creation capabilities. This method may return a new or existing bucket, or may return None, in case no bucket should be created.


Delete a record and also remove the RecordsBuckets if necessary.

Parameters:force – True to remove also the RecordsBuckets object.
Returns:Deleted record.
classmethod dump_bucket(data, bucket)[source]

Dump the bucket id into the record metadata.

Override this method to provide custom behavior for storing the bucket id in the record metadata. By default the bucket id is stored in the _bucket key. If you override this method, make sure you also override Record.load_bucket().

This method is called after the bucket is created, but before the record is created in the database.

  • data – A dictionary of the record metadata.
  • bucket – The created bucket for the record.
classmethod load_bucket(record)[source]

Load the bucket id from the record metadata.

Override this method to provide custom behavior for retrieving the bucket id from the record metadata. By default the bucket id is retrieved from the _bucket key. If you override this method, make sure you also override Record.dump_bucket().

Parameters:record – A record instance.


Implementation of various utility functions.

invenio_records_files.utils.file_download_ui(pid, record, _record_file_factory=None, **kwargs)[source]

File download view for a given record.

Plug this method into your RECORDS_UI_ENDPOINTS configuration:

        # ...

If download is passed as a querystring argument, the file is sent as an attachment.

invenio_records_files.utils.record_file_factory(pid, record, filename)[source]

Get file from a record.

  • pid – Not used. It keeps the function signature.
  • record – Record which contains the files.
  • filename – Name of the file to be returned.

File object or None if not found.

invenio_records_files.utils.sorted_files_from_bucket(bucket, keys=None)[source]

Return files from bucket sorted by given keys.

  • bucketBucket containing the files.
  • keys – Keys order to be used.

Sorted list of bucket items.


Define relation between records and buckets.

class invenio_records_files.models.RecordsBuckets(**kwargs)[source]

Relationship between Records and Buckets.

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.


Relationship to the bucket.


Bucket related with the record.

classmethod create(record, bucket)[source]

Create a new RecordsBuckets and adds it to the session.

  • record – Record used to relate with the Bucket.
  • bucket – Bucket used to relate with the Record.

The RecordsBuckets object created.


It is used by SQLAlchemy for optimistic concurrency control.


Record related with the bucket.