jina.serve.runtimes.gateway.http package#

Submodules#

Module contents#

class jina.serve.runtimes.gateway.http.HTTPGateway(title=None, description=None, no_debug_endpoints=False, no_crud_endpoints=False, expose_endpoints=None, expose_graphql_endpoint=False, cors=False, ssl_keyfile=None, ssl_certfile=None, uvicorn_kwargs=None, proxy=None, **kwargs)[source]#

Bases: BaseGateway

HTTP Gateway implementation

Initialize the gateway

Get the app from FastAPI as the REST interface.

Parameters:
  • title (Optional[str]) – The title of this HTTP server. It will be used in automatics docs such as Swagger UI.

  • description (Optional[str]) – The description of this HTTP server. It will be used in automatics docs such as Swagger UI.

  • no_debug_endpoints (Optional[bool]) – If set, /status /post endpoints are removed from HTTP interface.

  • no_crud_endpoints (Optional[bool]) –

    If set, /index, /search, /update, /delete endpoints are removed from HTTP interface.

    Any executor that has @requests(on=…) bound with those values will receive data requests.

  • expose_endpoints (Optional[str]) – A JSON string that represents a map from executor endpoints (@requests(on=…)) to HTTP endpoints.

  • expose_graphql_endpoint (Optional[bool]) – If set, /graphql endpoint is added to HTTP interface.

  • cors (Optional[bool]) – If set, a CORS middleware is added to FastAPI frontend to allow cross-origin access.

  • ssl_keyfile (Optional[str]) – the path to the key file

  • ssl_certfile (Optional[str]) – the path to the certificate file

  • uvicorn_kwargs (Optional[dict]) – Dictionary of kwargs arguments that will be passed to Uvicorn server when starting the server

  • proxy (Optional[bool]) – If set, respect the http_proxy and https_proxy environment variables, otherwise, it will unset these proxy variables before start. gRPC seems to prefer no proxy

  • kwargs – keyword args

async setup_server()[source]#

Initialize and return GRPC server

async shutdown()[source]#

Free resources allocated when setting up HTTP server

async run_server()[source]#

Run HTTP server forever

property host#

Gets the host from the runtime_args :return: The host where to bind the gateway

static is_valid_jaml(obj)#

Verifies the yaml syntax of a given object by first serializing it and attempting to deserialize and catch parser errors :type obj: Dict :param obj: yaml object :rtype: bool :return: whether the syntax is valid or not

classmethod load_config(source, *, allow_py_modules=True, substitute=True, context=None, uses_with=None, uses_metas=None, uses_requests=None, extra_search_paths=None, py_modules=None, runtime_args=None, **kwargs)#

A high-level interface for loading configuration with features of loading extra py_modules, substitute env & context variables. Any class that implements JAMLCompatible mixin can enjoy this feature, e.g. BaseFlow, BaseExecutor, BaseGateway and all their subclasses.

Support substitutions in YAML:
  • Environment variables: ${{ ENV.VAR }} (recommended), $VAR (deprecated).

  • Context dict (context): ${{ CONTEXT.VAR }}``(recommended), ``${{ VAR }}.

  • Internal reference via this and root: ${{this.same_level_key}}, ${{root.root_level_key}}

Substitutions are carried in the order and multiple passes to resolve variables with best effort.

!BaseEncoder
metas:
    name: ${{VAR_A}}  # env or context variables
    workspace: my-${{this.name}}  # internal reference
# load Executor from yaml file
BaseExecutor.load_config('a.yml')

# load Executor from yaml file and substitute environment variables
os.environ['VAR_A'] = 'hello-world'
b = BaseExecutor.load_config('a.yml')
assert b.name == 'hello-world'

# load Executor from yaml file and substitute variables from a dict
b = BaseExecutor.load_config('a.yml', context={'VAR_A': 'hello-world'})
assert b.name == 'hello-world'

# disable substitute
b = BaseExecutor.load_config('a.yml', substitute=False)
Parameters:
  • source (Union[str, TextIO, Dict]) – the multi-kind source of the configs.

  • allow_py_modules (bool) – allow importing plugins specified by py_modules in YAML at any levels

  • substitute (bool) – substitute environment, internal reference and context variables.

  • context (Optional[Dict[str, Any]]) – context replacement variables in a dict, the value of the dict is the replacement.

  • uses_with (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s with field

  • uses_metas (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s metas field

  • uses_requests (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s requests field

  • extra_search_paths (Optional[List[str]]) – extra paths used when looking for executor yaml files

  • py_modules (Optional[str]) – Optional py_module from which the object need to be loaded

  • runtime_args (Optional[Dict[str, Any]]) – Optional dictionary of parameters runtime_args to be directly passed without being parsed into a yaml config

:param : runtime_args that need to be passed to the yaml

Parameters:

kwargs – kwargs for parse_config_source

Return type:

JAMLCompatible

Returns:

JAMLCompatible object

property port#

Gets the first port of the port list argument. To be used in the regular case where a Gateway exposes a single port :return: The first port to be exposed

property ports#

Gets all the list of ports from the runtime_args as a list. :return: The lists of ports to be exposed

property protocols#

Gets all the list of protocols from the runtime_args as a list. :return: The lists of protocols to be exposed

save_config(filename=None)#

Save the object’s config into a YAML file.

Parameters:

filename (Optional[str]) – file path of the yaml file, if not given then config_abspath is used