trying arelle python rest api but getting error

163 views
Skip to first unread message

depak

unread,
Jan 24, 2025, 12:32:29 AMJan 24
to Arelle-users
Hi,

I am working as Integration Developer for an insurance company and i am evaluating Arelle for XBRL validation. i am trying with below details and getting error, it would be rally great if someone can review the request and let me know what is missing.

Arelle Version - 2.36.5
Python - 3.12.5

followed the steps and arelle webserver running in 8080 port.

started the webserver: 
Python\Python312\site-packages\arelle\scripts-windows\startWebServer
Bottle v0.13-dev server starting up (using WSGIRefServer())...


Request: 
{
    "file":"C:\\aerelle-sw\\STIC.xbrl",
    "taxonomy":["C:\\aerelle-sw\\taxonomies\\sbr_au\\sbr_au_reports\\ato\\stic\\stic_0003\\stic.0003.lodge.request.02.00.report.xsd"],
   
    "options": {
        "validate": true,
        "formula": true
    }
}

setting Content-Type as "application/json", but getting error like

Error:

<?xml version="1.0" encoding="utf-8"?>

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">

<head>

<STYLE type="text/css">

body, table, p {font-family:Arial,sans-serif;font-size:10pt;}

table {vertical-align:top;white-space:normal;}

th {{background:#eee;}}

td {vertical-align:top;}

.tableHdr{border-top:.5pt solid windowtext;border-right:none;border-bottom:none;border-left:.5pt solid windowtext;}

.cell{border-top:1.0pt solid windowtext;border-right:.5pt solid windowtext;border-bottom:.5pt solid windowtext;border-left:.5pt solid windowtext;}

.blockedCell{border-top:1.0pt solid windowtext;border-right:.5pt solid windowtext;border-bottom:.5pt solid windowtext;border-left:.5pt solid windowtext;background:#eee;}

</STYLE>

</head>

<body>

<table cellspacing="0" cellpadding="4"><tr><th>Messages</th></tr><tr><td>URL: (no file)</td></tr>

<tr><td>POST must provide a zip file, Content-Type 'application/json' not recognized as a zip file.</td></tr>

</table>

</body>


depak

unread,
Jan 28, 2025, 4:11:22 PMJan 28
to Arelle-users
hi All,

it would be great if i can get any help on this, not sure if i should try with latest version of arelle?

Thanks & Regards
Depak

Austin Matherne

unread,
Feb 6, 2025, 11:29:44 AMFeb 6
to Arelle-users
Hi Depak,

You'll need to upload the zip as part of the request:

For example:
curl --request POST \
  --url http://localhost:8080/rest/xbrl/validation \
  --header 'content-type: application/zip' \
  --data-binary @/path/to/report.zip

Or:
curl --request POST \
  --url http://localhost:8080/rest/xbrl/validation \
  --header 'content-type: multipart/form-data' \
  --form upload=@/path/to/report.zip

Best,
Austin Matherne

depak

unread,
Feb 6, 2025, 5:17:33 PMFeb 6
to Arelle-users
Hi Austin,

Thank you very much for response, I tried by compressing the file and it is working fine. I am now trying to call the modelmanager validate method or Validate class validate method using a simple python script but getting below error. The same xbrl file when I try using the command line and calling rest api I am getting success response. please review the script and let me know if I have missed anything and is it possible to call validate method like this from python script.

Sample Python Script:

import sys
import arelle.Cntlr

def validate_xbrl(xbrl_file):
    """
    Validate an XBRL instance file using Arelle.

    Args:
    xbrl_file (str): Path to the XBRL instance document to be validated.

    Returns:
    bool: True if the document is valid, False otherwise.
    """
    # Initialize Arelle controller
    controller = arelle.Cntlr.Cntlr(logFileName="logToBuffer")

    try:
       
        # Access the ModelManager
        modelManager = controller.modelManager
       
        #formula_options = modelManager.FormulaOptions
       
        # If needed, customize the formulaOptions, though the default settings might suffice
        #formula_options.validationMode = 'full'  # Possible values: 'full', 'quick'
        #formula_options.debug = False  # Set to True for debug information
        #formula_options.reportError = True  # Report errors during formula validation
       
        # Load the XBRL file using Arelle's modelManager
        model_xbrl = modelManager.load(xbrl_file)
       
       
       
        if not model_xbrl:
            print(f"Error loading XBRL file: {xbrl_file}")
            return False

        # Perform validation using the modelManager's validate function
        modelManager.validate()
       
        log = controller.logHandler.getText()  
        print(log)

        # Check if there are any validation errors
        if model_xbrl.errors:
            print(f"Validation failed with {len(model_xbrl.errors)} error(s):")
            for error in model_xbrl.errors:
                print(error)
            return False
        else:
            print("XBRL document is valid!")
            return True

    except Exception as e:
        print(f"An error occurred: {e}")
        return False
    finally:
        controller.close()

# Main entry point for script execution
if __name__ == "__main__":
    # Replace this path with the actual XBRL file you want to validate
    xbrl_file_path = "C:\\irr3\\IRRQ3_XBRL.xbrl"

    if validate_xbrl(xbrl_file_path):
        print("XBRL file validation passed!")
    else:
        print("XBRL file validation failed!")

end of python script

Arelle Version: 2.36.9
Python Version: 3.12.5

Error: 

C:\Users\DEPGOP\AppData\Roaming\Python\Python312\Scripts>python arelle4.py
2025-02-07 08:50:01,419 [exception:AttributeError] Instance validation exception: 'ModelManager' object has no attribute 'formulaOptions', instance: IRRQ3_XBRL.xbrl - IRRQ3_XBRL.xbrl
Traceback (most recent call last):
  File "C:\Users\DEPGOP\AppData\Roaming\Python\Python312\site-packages\arelle\Validate.py", line 131, in validate
    self.instValidator.validate(self.modelXbrl, self.modelXbrl.modelManager.formulaOptions.typedParameters(self.modelXbrl.prefixedNamespaces))
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ModelManager' object has no attribute 'formulaOptions'
Validation failed with 1 error(s):
exception:AttributeError
XBRL file validation failed!


so, I uncommented the formula options and tried, but getting the below error.

Error:

C:\Users\DEPGOP\AppData\Roaming\Python\Python312\Scripts>python arelle4.py
An error occurred: 'ModelManager' object has no attribute 'formulaOptions'
XBRL file validation failed! 

same xbrl file when executed from command line:

C:\Users\DEPGOP\AppData\Roaming\Python\Python312\Scripts>arelleCmdLine.exe  --file C:\\irr3\\IRRQ3_XBRL.xbrl --validate
[info] loaded in 1.03 secs at 2025-02-07T08:57:09 - C:\\irr3\\IRRQ3_XBRL.xbrl
[info] validated in 0.07 secs - C:\\irr3\\IRRQ3_XBRL.xbrl


same xbrl file when compressed and invoked python rest api:

<?xml version="1.0" encoding="utf-8"?>
<log>
    <entry code="info" level="info">
        <message>2025-02-07 08:58:46,554 [info] loaded in 0.95 secs at 2025-02-07T08:58:45 - \POSTupload.zip\data
</message>
        <ref href="\POSTupload.zip\data"/>
    </entry>
    <entry code="info" level="info">
        <message>2025-02-07 08:58:46,634 [info] validated in 0.08 secs - \POSTupload.zip\data
</message>
        <ref href="\POSTupload.zip\data"/>
    </entry>
</log>

Thanks & Regards
Depak

Austin Matherne

unread,
Feb 6, 2025, 5:45:55 PMFeb 6
to Arelle-users
It's possible to make it work, but the Cntlr class is a base class and not intended to be used directly. Here's where the CLI controller subclass sets up formula options if you want to create your own sub class.

I'd suggest taking a look at the new Session Python API. It abstracts away all of this setup into a runtime options class.

Austin

depak

unread,
Mar 19, 2025, 1:37:03 AMMar 19
to Arelle-users
Hi,

we are trying to enable verbose logging by using the below command, but we cannot see any logs in console. it would be really great if we can know how to enable verbose logging. currently we are just getting only one line logger only when request is processed, and it takes almost 7 minutes to process the request.

sudo su utiluat bash -c ". /opt/python3_venv/arelle/bin/activate &&  arelleCmdLine --logLevel=debug --webserver <hostname>:8081 &> /opt/python3_venv/arelle/logs/output.log & disown"

Thanks & Regards
Depak

Austin Matherne

unread,
Mar 24, 2025, 10:53:46 AMMar 24
to Arelle-users
Hi Depak,

Do you get more details when you log to an XML file?

Austin

Reply all
Reply to author
Forward
0 new messages