UsageΒΆ

Invenio-Records is a metadata storage module.

Invenio-Records is typically used as part of the Invenio digital repository ecosystem. Please see Invenio documentation for more.

If you’d like to use Invenio-Records in a standalone manner, here is a simple minimal example that is useful among others for Invenio-Records developments.



"""Minimal Invenio-Records application example for development.

Create database and tables::

   $ cd examples
   $ export FLASK_APP=app.py
   $ export FLASK_DEBUG=1
   $ mkdir -p instance
   $ flask db init
   $ flask db create

Create test record::

   $ echo '{"title": "Test title"}' | flask records create \
      -i deadbeef-9fe4-43d3-a08f-38c2b309afba

Run the development server::

   $ flask run

Retrieve record via web::

   $ curl http://127.0.0.1:5000/deadbeef-9fe4-43d3-a08f-38c2b309afba

Retrieve record via shell::

   $ flask shell
   >>> from invenio_records.api import Record
   >>> Record.get_record('deadbeef-9fe4-43d3-a08f-38c2b309afba')
"""

from __future__ import absolute_import, print_function

import os

import pkg_resources
from flask import Flask, jsonify, render_template
from flask_celeryext import create_celery_app
from invenio_db import InvenioDB

from invenio_records import InvenioRecords

try:
    pkg_resources.get_distribution('invenio_pidstore')
except pkg_resources.DistributionNotFound:
    HAS_PIDSTORE = False
else:
    HAS_PIDSTORE = True
    from invenio_pidstore import InvenioPIDStore

# Create Flask application
app = Flask(__name__)
app.config.update(
    CELERY_ALWAYS_EAGER=True,
    CELERY_CACHE_BACKEND="memory",
    CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
    CELERY_RESULT_BACKEND="cache",
    SECRET_KEY="CHANGE_ME",
    SECURITY_PASSWORD_SALT="CHANGE_ME_ALSO",
)

db_uri = os.environ.get('SQLALCHEMY_DATABASE_URI')
if db_uri is not None:
    app.config['SQLALCHEMY_DATABASE_URI'] = db_uri

InvenioDB(app)
InvenioRecords(app)

if HAS_PIDSTORE:
    InvenioPIDStore(app)

celery = create_celery_app(app)


@app.route("/<uuid>")
def index(uuid):
    """Retrieve record."""
    from invenio_records.api import Record
    return jsonify(Record.get_record(uuid))