/ mlflow / tracking / request_header / abstract_request_header_provider.py
abstract_request_header_provider.py
 1  from abc import ABCMeta, abstractmethod
 2  
 3  from mlflow.utils.annotations import developer_stable
 4  
 5  
 6  @developer_stable
 7  class RequestHeaderProvider:
 8      """
 9      Abstract base class for specifying custom request headers to add to outgoing requests
10      (e.g. request headers specifying the environment from which mlflow is running).
11  
12      When a request is sent, MLflow will iterate through all registered RequestHeaderProviders.
13      For each provider where ``in_context`` returns ``True``, MLflow calls the ``request_headers``
14      method on the provider to compute request headers.
15  
16      All resulting request headers will then be merged together and sent with the request.
17      """
18  
19      __metaclass__ = ABCMeta
20  
21      @abstractmethod
22      def in_context(self):
23          """Determine if MLflow is running in this context.
24  
25          Returns:
26              bool indicating if in this context.
27  
28          """
29  
30      @abstractmethod
31      def request_headers(self):
32          """Generate context-specific request headers.
33  
34          Returns:
35              dict of request headers.
36          """