belso package — belso 0.0.1 documentation

# belso package

## Subpackages

- belso.schemas package
  - Submodules
  - belso.schemas.base module
    - `Field`
    - `Schema`
      - `Schema.fields`
      - `Schema.get_field_by_name()`
      - `Schema.get_required_fields()`
      - `Schema.name`
  - belso.schemas.nested module
    - `ArrayField`
      - `ArrayField.__init__()`
    - `NestedField`
      - `NestedField.__init__()`
  - Module contents
    - `Field`
    - `Schema`
      - `Schema.fields`
      - `Schema.get_field_by_name()`
      - `Schema.get_required_fields()`
      - `Schema.name`
- belso.translator package
  - Subpackages
    - belso.translator.providers package
      - Submodules
      - belso.translator.providers.anthropic module
      - belso.translator.providers.google module
      - belso.translator.providers.huggingface module
      - belso.translator.providers.langchain module
      - belso.translator.providers.mistral module
      - belso.translator.providers.ollama module
      - belso.translator.providers.openai module
      - Module contents
    - belso.translator.serialization package
      - Submodules
      - belso.translator.serialization.json_format module
      - belso.translator.serialization.xml_format module
      - Module contents
    - belso.translator.utils package
      - Submodules
      - belso.translator.utils.detecting module
      - Module contents
  - Submodules
  - belso.translator.translator module
    - `SchemaTranslator`
      - `SchemaTranslator.detect_format()`
      - `SchemaTranslator.from_json()`
      - `SchemaTranslator.from_xml()`
      - `SchemaTranslator.standardize()`
      - `SchemaTranslator.to_json()`
      - `SchemaTranslator.to_xml()`
      - `SchemaTranslator.translate()`
  - Module contents
    - `SchemaTranslator`
      - `SchemaTranslator.detect_format()`
      - `SchemaTranslator.from_json()`
      - `SchemaTranslator.from_xml()`
      - `SchemaTranslator.standardize()`
      - `SchemaTranslator.to_json()`
      - `SchemaTranslator.to_xml()`
      - `SchemaTranslator.translate()`
- belso.validator package
  - Submodules
  - belso.validator.validator module
    - `SchemaValidator`
      - `SchemaValidator.validate()`
  - Module contents
    - `SchemaValidator`
      - `SchemaValidator.validate()`
- belso.utils package
  - Submodules
  - belso.utils.classes module
    - `PROVIDERS`
      - `PROVIDERS.ANTHROPIC`
      - `PROVIDERS.AZURE_OPENAI`
      - `PROVIDERS.BELSO`
      - `PROVIDERS.GOOGLE`
      - `PROVIDERS.HUGGINGFACE`
      - `PROVIDERS.JSON`
      - `PROVIDERS.LANGCHAIN`
      - `PROVIDERS.MISTRAL`
      - `PROVIDERS.OLLAMA`
      - `PROVIDERS.OPENAI`
      - `PROVIDERS.XML`
      - `PROVIDERS.get_all_providers()`
  - belso.utils.logging module
    - `configure_logger()`
    - `disable_logging()`
    - `get_logger()`
    - `log_exception()`
    - `restore_logging()`
  - belso.utils.schema_helpers module
    - `build_properties_dict()`
    - `create_fallback_schema()`
    - `is_schema_supported()`
    - `map_json_to_python_type()`
    - `map_python_to_json_type()`
  - Module contents
    - `PROVIDERS`
      - `PROVIDERS.ANTHROPIC`
      - `PROVIDERS.AZURE_OPENAI`
      - `PROVIDERS.BELSO`
      - `PROVIDERS.GOOGLE`
      - `PROVIDERS.HUGGINGFACE`
      - `PROVIDERS.JSON`
      - `PROVIDERS.LANGCHAIN`
      - `PROVIDERS.MISTRAL`
      - `PROVIDERS.OLLAMA`
      - `PROVIDERS.OPENAI`
      - `PROVIDERS.XML`
      - `PROVIDERS.get_all_providers()`

## Module contents

class belso.SchemaTranslator

  Bases: `object`

  static detect_format(schema)

    Detect the format of a schema.

    Return type:

      `str`

    ### Args

    - schema: the schema to detect.

    ### Returns

    - str: the detected format as a string.

  static from_json(json_input)

    Convert JSON data or a JSON file to a belso schema.

    Return type:

      `Type`

    ### Args

    param json_input:

      either a JSON dictionary or a file path to a JSON file.

    type json_input:

      Union[Dict[str, Any], str]

    ### Returns

    - Type: the converted schema as a belso Schema subclass.

  static from_xml(xml_input)

    Convert XML data or an XML file to a belso schema.

    Return type:

      `Type`

    ### Args

    param xml_input:

      either an XML string, Element, or a file path to an XML file.

    type xml_input:

      Union[str, Any]

    ### Returns

    - Type: the converted schema as a belso Schema subclass.

  static standardize(schema, from_format)

    Convert a schema from a specific format to our internal belso format.

    Return type:

      `Type`

    ### Args

    - schema: the schema to convert.

    - from_format: the format of the input schema (“google”, “ollama”, “openai”, “anthropic”, “json”, “xml”).

    ### Returns

    - Type: the converted schema as a belso Schema subclass.

  static to_json(schema, file_path=None)

    Convert a schema to standardized JSON format and optionally save to a file.

    Return type:

      `Dict`[`str`, `Any`]

    ### Args

    param schema:

      the schema to convert.

    type schema:

      Type

    param file_path:

      optional path to save the JSON to a file.

    type file_path:

      Optional[str]

    ### Returns

    - Dict[str, Any]: the schema in JSON format.

  static to_xml(schema, file_path=None)

    Convert a schema to XML format and optionally save to a file.

    Return type:

      `str`

    ### Args

    param schema:

      the schema to convert.

    type schema:

      Type

    param file_path:

      optional path to save the XML to a file.

    type file_path:

      Optional[str]

    ### Returns

    - str: the schema in XML format.

  static translate(schema, to, from_format=None)

    Translate a schema to a specific format. This method can automatically detect the input schema format and convert it to our internal format before translating to the target format.

    Return type:

      `Union`[`Dict`[`str`, `Any`], `Type`, `str`]

    ### Args

    param schema:

      the schema to translate.

    type schema:

      Any

    param to:

      the target format. Can be a string or a belso.utils.PROVIDERS attribute.

    type to:

      str

    param from_format:

      optional format hint for the input schema, if None, the format will be auto-detected.

    type from_format:

      Optional[str]

    ### Returns

    - Union[Dict[str, Any], Type, str]: the translated schema in the target format.