Modules

Module class

class xbridge.modules.Module(code=None, url=None, taxonomy_code=None, date=None, tables=None)

Bases: object

Class representing an XBRL Module.

It has attributes like code, url, taxonomy_code, date, tables and input_path, whose main function is to operate with the module and return properties like a specific table from the JSON file used as input, an object, a dictionary using the attributes as keys, a module object from a part of preprocessed JSON file and the variables that are present in it.

It is used when taxonomies are loaded to collect the information associated to the tables belonging to the module.

Parameters:
  • code – The code of the XBRL module.

  • url – The module reference within the taxonomy.

  • taxonomy_code – The code of the module within to the taxonomy.

  • date – Dates contained in the module.

  • tables – The tables that form the module.

extract_tables(zip_file: ZipFile)

Extracts the tables in the JSON files for the modules in the taxonomy

classmethod from_serialized(input_path: str | Path)

Returns a module object from a JSON file

classmethod from_taxonomy(zip_file: ZipFile, json_file_path: str)

Returns a module object from a part of the JSON file

get_table(table_code: str)

Returns a table object with the given code

property repeated_variables

Returns a dictionary with the variables and the tables where they are present, if they are repeated

property tables

Returns the tables defined in the JSON file for the module

to_dict()

Returns a dictionary

property variables_location

Returns a dictionary with the variables and the tables where they are present

Table class

class xbridge.modules.Table(code=None, url=None, open_keys=None, variables=None, attributes=None, input_zip_path=None)

Bases: object

Class representing an XBRL table as defined in the JSON file.

Its properties allow to return open keys, variables and attributes from the table. It can also generate a variable dataframe or work with one already created. Finally, it can return a dictionary using its attributes or a Table object from the preprocessed JSON file.

It is used when module is loaded to collect the information associated to the variables and open keys belonging to the table.

Parameters:
  • code – The code of the table.

  • url – The table reference within the module.

  • open_keys – Open key contained in the table.

  • variables – the variables that belongs to the table.

  • attributes – attributes related to the variables that can be extracted from the table.

  • input_zip_path – Path to the file used as table.

property attributes

Returns the attributes for the table

extract_open_keys(zip_file: ZipFile)

Extracts the open keys for the table

extract_variables(zip_file: ZipFile)

Extract the variable for the table

classmethod from_dict(table_dict)

Returns a table object from a dictionary

classmethod from_taxonomy(zip_file: ZipFile, table_path: str, code: str, url: str)

Returns a table object from a part of the preprocessed JSON file

generate_variable_df()

Returns a dataframe with the variable and extensional context

property open_keys

Returns the open keys for the table

to_dict()

Returns a dictionary for the table

property variable_columns

Returns the columns for the variable dataframe

property variable_df

Returns a dataframe with the variable and extensional context

property variables

Returns the variable for the table

Variable class

class xbridge.modules.Variable(code=None, dimensions=None, attributes=None)

Bases: object

Class representing a variable as represented in the JSON files. Can return or extract the dimension of the variable, create a dictionary using its attributes as keys or return a variable object from the preprocessed JSON file.

Parameters:
  • code – The code of the variable.

  • dimensions – the dimensions of the variable.

  • attributes – The attributes related to the variable.

property dimensions

Returns the dimensions of a variable

extract_dimensions(datapoint_dict)

Extracts the dimensions for the variable

classmethod from_dict(variable_dict)

Returns a variable object from a dictionary

classmethod from_taxonomy(variable_id, variable_dict)

Returns a variable object from a part of the preprocessed JSON file

to_dict()

Returns a dictionary with the attributes