API reference - JQpy 1.0.0 documentation

Skip to content

# API reference

jqpy.EmptyInput = `<jqpy._TEmptyInput object>`

  Constant that represents no data input.

  None can not be used because it is valid JSON value.

exception jqpy.JQError

  Bases: `Exception`

  Base jqpy exception.

exception jqpy.JQMissingError

  Bases: `JQError`

  Jq binary executable (typically jq.exe in Windows and /usr/bin/jq in Unix) ws not found.

  Jq binary can be installed via system package manager or from https://jqlang.github.io/jq/download official website.

exception jqpy.JQProcessingError

  Bases: `JQError`

  Processing was not finished successfully.

exception jqpy.JQResultError

  Bases: `JQRuntimeError`

  Result of processing was corrupted.

exception jqpy.JQRuntimeError

  Bases: `JQProcessingError`

  Processing was failed.

exception jqpy.JQTimeoutError

  Bases: `JQProcessingError`

  Processing took too much time.

  By default, processing longer then 5 minutes will rise this error.

exception jqpy.JQUsageError

  Bases: `JQRuntimeError`

  Processing was aborted of finished with errors.

jqpy.JSON

  JSON serializable type.

  alias of `Union`[`None`, `bool`, `int`, `float`, `str`, `Dict`, `List`]

class jqpy.RawOutput(stdout: str, stderr: str, code: int, filter: str)

  Bases: `object`

  Raw jq binary evaluation results.

  code : int

    Return code of jq evaluation.

  filter : str

    Processed jq filtration program.

  property json_output : list[None | bool | int | float | str | dict | list]

    List of JSON parsed results from jq evaluation one per each line.

    Raises:

      JQResultError – jq evaluation resulted in bad output.

  stderr : str

    Standard error text of jq evaluation.

  stdout : str

    Standard output text of jq evaluation.

  property text : str

    Combined stdout then stderr texts.

    Result is joined with new line and stripped.

jqpy.jq(filter: str = '', data: None | bool | int | float | str | ~typing.Dict | ~typing.List | ~jqpy._TEmptyInput = <jqpy._TEmptyInput object>, *, timeout: float | None = 300, raw_output: bool = False) → list[None | bool | int | float | str | dict | list] | RawOutput

  Evaluate jq with provided input JSON data and filtration program.

  Parameters:
    filter

      jq filtration program. By default, is empty.

    data

      JSON compatible input data to be passed to jq. By default, is empty.

    timeout

      jq evaluation maximum time. By default, processing longer then 5 minutes will rise JQTimeoutError error.

    raw_output

      whether to return raw results of jq evaluation. In the most cases integrated JSON data results parser should be used instead.

  Returns:

    List of JSON parsed results from jq evaluation one per each line.

  Raises:

    - ValueError – invalid input data was provided.

    - JQMissingError – jq binary dependency not found.

    - JQUsageError – jq evaluation failed.

    - JQTimeoutError – jq evaluation took too much time.

    - JQResultError – jq evaluation resulted in bad output.

Back to top