API Docs

Application and CLI factory

Invenio application factory.

invenio_base.app.app_loader(app, entry_points=None, modules=None)[source]

Run default application loader.

Parameters:
  • entry_points – List of entry points providing to Flask extensions.
  • modules – List of Flask extensions.
invenio_base.app.base_app(import_name, instance_path=None, static_folder=None, static_url_path='/static', template_folder='templates', instance_relative_config=True, app_class=<class 'flask.app.Flask'>)[source]

Invenio base application factory.

If the instance folder does not exists, it will be created.

Parameters:
  • import_name – The name of the application package.
  • env_prefix – Environment variable prefix.
  • instance_path – Instance path for Flask application.
  • static_folder – Static folder path.
  • app_class – Flask application class.
Returns:

Flask application instance.

invenio_base.app.blueprint_loader(app, entry_points=None, modules=None)[source]

Run default blueprint loader.

The value of any entry_point or module passed can be either an instance of flask.Blueprint or a callable accepting a flask.Flask application instance as a single argument and returning an instance of flask.Blueprint.

Parameters:
  • entry_points – List of entry points providing to Blueprints.
  • modules – List of Blueprints.
invenio_base.app.configure_warnings()[source]

Configure warnings by routing warnings to the logging system.

It also unhides DeprecationWarning.

invenio_base.app.converter_loader(app, entry_points=None, modules=None)[source]

Run default converter loader.

Parameters:
  • entry_points – List of entry points providing to Blue.
  • modules – Map of coverters.
invenio_base.app.create_app_factory(app_name, config_loader=None, extension_entry_points=None, extensions=None, blueprint_entry_points=None, blueprints=None, converter_entry_points=None, converters=None, wsgi_factory=None, **app_kwargs)[source]

Create a Flask application factory.

The application factory will load Flask extensions and blueprints specified using both entry points and directly in the arguments. Loading order of entry points are not guaranteed and can happen in any order.

Parameters:
  • app_name – Flask application name.
  • config_loader – Callable which will be invoked on application creation in order to load the Flask configuration. See example below.
  • extension_entry_points – List of entry points, which specifies Flask extensions that will be initialized only by passing in the Flask application object
  • extensions – List of Flask extensions that can be initialized only by passing in the Flask application object.
  • blueprint_entry_points – List of entry points, which specifies Blueprints that will be registered on the Flask application.
  • blueprints – List of Blueprints that will be registered on the Flask application.
  • converter_entry_points – List of entry points, which specifies Werkzeug URL map converters that will be added to app.url_map.converters.
  • converters – Map of Werkzeug URL map converter classes that will be added to app.url_map.converters.
  • wsgi_factory – A callable that will be passed the Flask application object in order to overwrite the default WSGI application (e.g. to install DispatcherMiddleware).
  • app_kwargs – Keyword arguments passed to base_app().
Returns:

Flask application factory.

Example of a configuration loader:

def my_config_loader(app, **kwargs):
    app.config.from_module('mysite.config')
    app.config.update(**kwargs)

Note

Invenio-Config provides a factory creating default configuration loader (see invenio_config.utils.create_config_loader()) which is sufficient for most cases.

Example of a WSGI factory:

def my_wsgi_factory(app):
    return DispatcherMiddleware(app.wsgi_app, {'/api': api_app})
invenio_base.app.create_cli(create_app=None)[source]

Create CLI for inveniomanage command.

Parameters:create_app – Flask application factory.
Returns:Click command group.

WSGI factory

WSGI application factory for Invenio.

invenio_base.wsgi.create_wsgi_factory(mounts_factories)[source]

Create a WSGI application factory.

Usage example:

wsgi_factory = create_wsgi_factory({'/api': create_api})
Parameters:mounts_factories – Dictionary of mount points per application factory.

New in version 1.0.0.

invenio_base.wsgi.wsgi_proxyfix(factory=None)[source]

Fix REMOTE_ADDR based on X-Forwarded-For headers.

Note

You must set WSGI_PROXIES to the correct number of proxies, otherwise you application is susceptible to malicious attacks.

New in version 1.0.0.

Signals

Signals for application creation.

invenio_base.signals.app_created = <blinker.base.NamedSignal object at 0x7f5742c65750; 'app-created'>

Signal sent when the base Flask application have been created.

Parameters: - sender - the application factory function. - app - the Flask application instance.

Example receiver:

def receiver(sender, app=None, **kwargs):
    # ...
invenio_base.signals.app_loaded = <blinker.base.NamedSignal object at 0x7f5742c65790; 'app-loaded'>

Signal sent when the Flask application have been fully loaded.

Parameters: - sender - the application factory function. - app - the Flask application instance.

Example receiver:

def receiver(sender, app=None, **kwargs):
    # ...