arelle.api.Session

See COPYRIGHT.md for copyright information.

The arelle.api module is the supported method for integrating Arelle into other Python applications.

Module Contents

Classes

Session

CRITICAL THREAD SAFETY WARNING:

API

class arelle.api.Session.Session

CRITICAL THREAD SAFETY WARNING:

Arelle uses shared global state (PackageManager, PluginManager) which is NOT thread-safe. Only ONE Session can run at a time across the entire process.

Safe usage:

  • Use one Session at a time per process

  • Use a process pool instead of thread pool for parallelism

Unsafe usage:

  • Running multiple Sessions concurrently in any threads

  • Threading.Thread with Session.run()

Initialization

clear_logs() → None

Clears the log buffer (if the current log handler supports buffering, e.g., LogToXmlHandler).

close() → None
get_log_messages() → list[dict[str, Any]]

Returns structured log messages from the session’s log handler if it supports structured messages (e.g., StructuredMessageLogHandler).

Returns:

Structured log messages from the session.

get_logs(log_format: Literal[json, text, xml], clear_logs: bool = False) → str

Retrieve logs as a string in the configured format. Raises a ValueError if the log format is not supported by the current log handler. Optionally clear the log buffer after retrieving.

Parameters:
  • log_format – The format to retrieve logs in. Supported formats are ‘json’, ‘text’, and ‘xml’.

  • clear_logs – If enabled, clears the log buffer after retrieving logs.

Returns:

get_models() → list[arelle.ModelXbrl.ModelXbrl]

Retrieve a list of loaded models.

run(options: arelle.RuntimeOptions.RuntimeOptions, sourceZipStream: BinaryIO | arelle.FileSource.FileNamedBytesIO | None = None, responseZipStream: BinaryIO | None = None, logHandler: logging.Handler | None = None, logFilters: list[logging.Filter] | None = None, logFileName: pathlib.Path | arelle.Cntlr.TypeLogFileName | None = None) → bool

Perform a run using the given options. When using a sourceZipStream, the name attribute on it will be checked and, if present, assumed to be the effective name of the zip file the stream represents. When validating ‘.xbri’ files, via a sourceZipStream, it is important to set this name attribute to avoid rpe:documentTypeFileExtensionMismatch errors.

Parameters:
  • options – Options to use for the run.

  • sourceZipStream – Optional stream to read source data from.

  • responseZipStream – Options stream to write response data to.

  • logHandler – Optional log handler to use for logging.

  • logFilters – Log filters to apply to logger.

  • logFileName – Log output filepath or keyword (see “Logging” in “Python API” documentation).

Returns:

True if the run was successful, False otherwise.