# cyclonedx.output

Set of classes and methods for outputting our libraries internal Bom model to CycloneDX documents in varying formats and according to different versions of the CycloneDX schema standard.

## Submodules

- cyclonedx.output.json
- cyclonedx.output.xml

## Classes

`BaseOutput` | Helper class that provides a standard way to create an ABC using
`BomRefDiscriminator` | Deprecated — Alias of `cyclonedx.contrib.bom.utils.BomRefDiscriminator`.

## Functions

`make_outputter`(…) | Helper method to quickly get the correct output class/formatter.

## Package Contents

class cyclonedx.output.BaseOutput(bom: cyclonedx.model.bom.Bom, **kwargs: int)

  Bases: `abc.ABC`

  Helper class that provides a standard way to create an ABC using inheritance.

  property schema_version: cyclonedx.schema.SchemaVersion
    Abstractmethod:

  property output_format: cyclonedx.schema.OutputFormat
    Abstractmethod:

  property generated: bool
  get_bom() → cyclonedx.model.bom.Bom
  set_bom(bom: cyclonedx.model.bom.Bom) → None
  abstractmethod generate(force_regeneration: bool = False) → None
  abstractmethod output_as_string(*, indent: int | str | None = None, **kwargs: Any) → str
  output_to_file(filename: str, allow_overwrite: bool = False, *, indent: int | str | None = None, **kwargs: Any) → None

cyclonedx.output.make_outputter(bom: cyclonedx.model.bom.Bom, output_format: Literal[cyclonedx.schema.OutputFormat.JSON], schema_version: cyclonedx.schema.SchemaVersion) → json.Json
cyclonedx.output.make_outputter(bom: cyclonedx.model.bom.Bom, output_format: Literal[cyclonedx.schema.OutputFormat.XML], schema_version: cyclonedx.schema.SchemaVersion) → xml.Xml
cyclonedx.output.make_outputter(bom: cyclonedx.model.bom.Bom, output_format: cyclonedx.schema.OutputFormat, schema_version: cyclonedx.schema.SchemaVersion) → xml.Xml | json.Json

  Helper method to quickly get the correct output class/formatter.

  Pass in your BOM and optionally an output format and schema version (defaults to XML and latest schema version).

  Raises error when no instance could be made.

  Parameters:

    - bom – Bom

    - output_format – OutputFormat

    - schema_version – SchemaVersion

  Returns:

    BaseOutput

class cyclonedx.output.BomRefDiscriminator(bomrefs: collections.abc.Iterable[cyclonedx.model.bom_ref.BomRef], prefix: str = 'BomRef')

  Bases: `cyclonedx.contrib.bom.utils.BomRefDiscriminator`

  Deprecated — Alias of `cyclonedx.contrib.bom.utils.BomRefDiscriminator`.

  Deprecated since version next: This re-export location is deprecated. Use `from cyclonedx.contrib.bom.utils import BomRefDiscriminator` instead. The exported symbol itself is NOT deprecated — only this import path.

  discriminate() → None

    Enforce uniqueness across all :attr:`cyclonedx.model.bom_ref.BomRef.value`s.

    Any BomRef whose `value` is `None` or duplicates a previously encountered value is assigned a newly generated unique identifier.

  reset() → None

    Restore all :attr:`cyclonedx.model.bom_ref.BomRef.value`s to their original state.

  classmethod from_bom(bom: cyclonedx.model.bom.Bom, prefix: str = 'BomRef') → BomRefDiscriminator

    Create a discriminator for all `cyclonedx.model.bom_ref.BomRefs` contained within a Bom.

    This includes BomRefs from

      - `cyclonedx.model.bom.Bom.components`

      - `cyclonedx.model.bom.Bom.services`

      - `cyclonedx.model.bom.Bom.vulnerabilities`