omni.flux.service.factory

  • SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Licensed under the Apache License, Version 2.0 (the “License”);

  • you may not use this file except in compliance with the License.

  • You may obtain a copy of the License at

  • https://www.apache.org/licenses/LICENSE-2.0

  • Unless required by applicable law or agreed to in writing, software

  • distributed under the License is distributed on an “AS IS” BASIS,

  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  • See the License for the specific language governing permissions and

  • limitations under the License.

class omni.flux.service.factory.ServiceBase(*args, **kwargs)

Bases: abc.ABC

A base class used to define a Service.

All endpoints must be defined within the implementation of the register_endpoints function.

static describe_query_param(default_value: Any, description: str)

Get a query parameter field with a description.

Returns

a FastAPI query parameter field

static inject_hidden_fields(base_model: Type[omni.flux.service.shared.base_model.BaseServiceModel], **kwargs) Type[omni.flux.service.shared.base_model.BaseServiceModel]

Inject hidden fields (non-visible in OpenAPI) in the given model

Parameters
  • base_model – The base model to inject the fields in

  • kwargs – Keyword arguments in the format field_name=value that will be injected as hidden fields

Returns

The model with all the injected fields

class property name: str

Returns: The Service Name must be unique. It is used in the Service Factory to fetch specific services

abstract class property prefix: str

Returns: The Service Prefix is prepended to all routes defined in the service. It must start with a “/” character

static raise_error(status_code: int, details: Union[Exception, str])

Raise an HTTP error with given status code and detail message or based on an exception

Parameters
  • status_code – The desired HTTP status code

  • details – The detail message or exception to build the error from

Raises

exceptions.KitServicesBaseException – The HTTP error

abstract register_endpoints()

Endpoints should be registered in this function as to not include self as a required query parameter.

This also allows the endpoints to have access to any of the class instance’s properties.

property router: omni.flux.service.factory.services.base.APIRouter

The router inherits from VersionedAPIRouter from fast_version and from ServiceAPIRouter from omni.services.core.routers.

The VersionedAPIRouter base class will have priority over the ServiceAPIRouter class when the same attribute is defined in both base classes.

Both of these routers are based on the FastAPI Router.

Returns

The router

static validate_path_param(base_model: Type[omni.flux.service.shared.base_model.BaseServiceModel], description: Optional[str] = None, validate_list: bool = False, **kwargs)

Get a path parameter validation dependency that will check the validity of a value using a Pydantic model.

Parameters
  • base_model – The Pydantic model to use to validate the given value

  • description – A description for the path parameter to display in the OpenAPI docs

  • validate_list – Whether to validate the value as a comma-separated list of as a single item

  • kwargs – Key-word arguments to be passed down to the Pydantic model for validation

Returns

The FastAPI path parameter dependency

class omni.flux.service.factory.TrexServiceFactoryExtension

Bases: omni.ext._extensions.IExt

Create Final Configuration

on_shutdown()
on_startup(_)
omni.flux.service.factory.get_instance() omni.flux.service.factory.core.TrexServiceFactoryCore
Returns

The Service Factory instance