invenio-rest

raw JSON →
3.0.1 verified Mon Apr 27 auth: no python

REST API module for Invenio, providing content negotiation, REST endpoints registration, and error handling. Current version 3.0.1, compatible with Python >=3.7. Development is ongoing but release cadence is irregular.

pip install invenio-rest
error AttributeError: module 'invenio_rest' has no attribute 'InvenioREST'
cause The extension class may not be imported if using an older version (<1.0) or incorrect spelling.
fix
Ensure you have version >=1.0.0 and use: from invenio_rest import InvenioREST
error ImportError: cannot import name 'create_api_blueprint' from 'invenio_rest.views'
cause The function was renamed in version 2.0.0.
fix
Check your version. If >=2.0.0, use: from invenio_rest.views import create_api_blueprint
breaking Version 2.0.0 removed the deprecated 'invenio-rest' endpoint registration functions. Use 'invenio_rest.views.create_api_blueprint' instead.
fix Update imports and replace old registration calls with create_api_blueprint.
gotcha Content negotiation is case-sensitive. Ensure Accept headers match registered formats exactly (e.g., 'application/json' not 'Application/JSON').
fix Use lowercase and correct format strings in Accept headers.
deprecated The 'invenio_rest.errors' module is deprecated since 3.0.0. Use Flask's built-in error handling or 'invenio_rest.error_handlers'.
fix Replace from invenio_rest.errors import ... with from invenio_rest.error_handlers import ...

Initialize InvenioREST with a Flask app the usual way.

from flask import Flask
from invenio_rest import InvenioREST

app = Flask(__name__)
ext = InvenioREST(app)

@app.route('/api/hello')
def hello():
    return {'message': 'Hello, World!'}

if __name__ == '__main__':
    app.run()