cobra.io.web.load
=================

.. py:module:: cobra.io.web.load

.. autoapi-nested-parse::

   Provide a function ``load_model`` to access remote model repositories.



Attributes
----------

.. autoapisummary::

   cobra.io.web.load.logger
   cobra.io.web.load.configuration
   cobra.io.web.load.DEFAULT_REPOSITORIES


Functions
---------

.. autoapisummary::

   cobra.io.web.load.load_model
   cobra.io.web.load._fetch_model
   cobra.io.web.load.get_model_from_gzip_sbml


Module Contents
---------------

.. py:data:: logger

.. py:data:: configuration

.. py:data:: DEFAULT_REPOSITORIES

.. py:function:: load_model(model_id: str, repositories: Iterable[cobra.io.web.abstract_model_repository.AbstractModelRepository] = DEFAULT_REPOSITORIES, cache: bool = True) -> cobra.core.Model

   Download an SBML model from a remote repository.

   Downloaded SBML documents are by default stored in a cache on disk such that future
   access is much faster. By default, models can be loaded from the following
   repositories:

   * BiGG Models
   * BioModels

   You can use the ``AbstractModelRepository`` class as a parent to implement your own
   repository accessor which you pass to the ``load_model`` function. In case you
   implement a new interface, please consider submitting a pull request to COBRApy.

   :param model_id: The identifier of the desired metabolic model. This is typically repository
                    specific.
   :type model_id: str
   :param repositories: An iterable of repository accessor instances. The model_id is searched in order.
   :type repositories: iterable, optional

   :returns: A model instance generated from the SBML document.
   :rtype: Model

   :raises RuntimeError: As with any internet connection, there are multiple errors that can occur.

   .. rubric:: Examples

   # Most of the time calling `load_model` with an identifier should be enough.
   >>> print(load_model("e_coli_core"))
   e_coli_core
   >>> print(load_model("MODEL1510010000"))
   MODEL1510010000

   .. seealso:: :py:obj:`BiGGModels`, :py:obj:`BioModels`


.. py:function:: _fetch_model(model_id: str, repositories: Iterable[cobra.io.web.abstract_model_repository.AbstractModelRepository]) -> bytes

   Attempt to load a gzip-compressed SBML document from the given repositories.

   :param model_id: The identifier of the desired metabolic model. This is typically repository
                    specific.
   :type model_id: str
   :param repositories: An iterable of repository accessor instances. The model_id is searched in order.
   :type repositories: iterable

   :returns: A gzip-compressed, UTF-8 encoded SBML document.
   :rtype: bytes


.. py:function:: get_model_from_gzip_sbml(stream: bytes) -> cobra.core.Model

   Generate a model instance from a gzip-compressed, UTF-8 encoded SBML document.

   :param stream: A gzip-compressed, UTF-8 encoded SBML document.
   :type stream: bytes

   :returns: A model instance generated from the SBML document.
   :rtype: Model


