json_tree.JSONTree

class xbrl_filings_api.json_tree.JSONTree

Bases: object

Object for traversing and parsing API response.

When the required keys have been read, method close() must be called in the init methods of APIObject subclasses. This ensures the keys which were never accessed (novel API features) are available via the two class methods.

The class methods get_unaccessed_key_paths() and get_key_path_availability_counts() are preferred to be called via the identically named functions of the debug module.

Methods

close()

Close JSON tree for reading.

get(key_path[, parse_type])

Read JSON data from dict and parse values to Python literals.

get_key_path_availability_counts()

Get counts of dot access paths not resolving to None.

get_unaccessed_key_paths()

Get unaccessed dot access paths of JSON objects.

__hash__()

Return hash(self).

__repr__()

Return repr(self).

__str__()

Return str(self).

Attributes

unexpected_resource_types

Set of unexpected API resource types.

class_name

The __qualname__ of the owner APIObject subclass.

tree

JSON fragment as Python dict from API page response.

request_url

Base URL for ParseType.URL.

do_not_track

When True, does not track successful and total get() method calls for debug module.

unexpected_resource_types: ClassVar[set[tuple[str, str]]] = {}

Set of unexpected API resource types.

Read by calling function debug.get_unexpected_resource_types.

Content:

unexpected_resource_types.pop() = (type_str, origin)
classmethod get_key_path_availability_counts()

Get counts of dot access paths not resolving to None.

See documentation of debug.get_key_path_availability_counts().

Return type:

set[KeyPathRetrieveCounts]

classmethod get_unaccessed_key_paths()

Get unaccessed dot access paths of JSON objects.

See documentation of debug.get_unaccessed_key_paths().

Return type:

set[tuple[str, str]]

class_name: str

The __qualname__ of the owner APIObject subclass.

tree: dict[str, Any] | None

JSON fragment as Python dict from API page response.

An APIPage subclass contains the whole JSON document.

request_url: str

Base URL for ParseType.URL.

do_not_track: bool

When True, does not track successful and total get() method calls for debug module.

close()

Close JSON tree for reading.

Remember all unaccessed and never existing dot access paths in the nested dictionary structure but skip lists.

Return type:

None

get(key_path, parse_type=None)

Read JSON data from dict and parse values to Python literals.

Value ParseType.DATETIME of parameter parse_type parses ISO style UTC strings such as '2023-05-09 10:51:50.382633'. The return value is locale-aware and if the string does not specify timezone, it will be on UTC.

Value ParseType.DATE parses naive dates and ParseType.URL resolves relative URLs based on request_url.

Parameters:
  • key_path (str) – A dot access path for nested access in a serialized JSON fragment. E.g. ‘relationships.validation_messages.links.related’.

  • parse_type (ParseType member, optional) – One of the ParseType Enum members.

Return type:

Any