#!/usr/bin/env python # coding: utf-8 # ## Running XULE in Arelle # This interactive environment copies the [free, open-source XULE plugin](https://github.com/xbrlus/xule/) to a working Python environment with [Arelle](https://pypi.org/project/arelle-release/) plus [additional packages](https://raw.githubusercontent.com/xbrlus/xule/jupyter/environment.yml). Click the code cell below (gray background) to bring it in focus, then click the run button above to add and confirm XULE is ready. **The asterisk to the left of the cell indicates the cell is queued/processing**. # In[ ]: import os, shutil, sys, site, platform print('Please wait while Arelle, XULE and some helper packages are installed. \nA XULE version message appears below when the environment is ready.') # In this example, Arelle and aniso are required to use XULE - get Arelle release details from GitHub (https://github.com/Arelle/arelle/releases). # Use %pip -q install git+https://git@github.com/Arelle/arelle.git@master to use Arelle's development release get_ipython().run_line_magic('pip', '-q install Arelle-release==2.23.1') get_ipython().run_line_magic('pip', '-q install aniso8601==9.0.1') # 1) locate Arelle's plugin directory (do not modify this location) plugindir = site.getsitepackages()[0] + '/arelle/plugin/' tempxule = site.getsitepackages()[0] + '/arelle/plugin/temp/plugin/xule/' xuledir = site.getsitepackages()[0] + '/arelle/plugin/xule/' os.chdir(plugindir) # 2) copy a XULE release from GitHub (https://github.com/xbrlus/xule/releases) to plugin directory and cleanup temp get_ipython().system('git clone --quiet --depth=1 --branch 23694 --single-branch https://github.com/xbrlus/xule.git temp') shutil.move(tempxule, xuledir) shutil.rmtree('temp') # 3) confirm XULE (change -v to -h and re-run to see help contents for Arelle and XULE) get_ipython().system("arelleCmdLine --plugins 'xule' -v") # ### 1. Define a XULE Expression # The cell below is the contents of a XULE 'file' called sample.xule **which starts on the line below %%writefile** - *a Jupyter-specific command* that saves the cell's contents as a file when the cell is run. # # Click the code cell below then **use 'Run All Below' from Jupyter's Cell menu** to save and run XULE with a single click (NB: after the cell is run once, toggling **%%writefile** to **%load** will display the contents of the sample.xule file in the cell). # In[ ]: get_ipython().run_cell_magic('writefile', "'sample.xule'", '/** add constants and namespaces below **/\n\n/** modify rule below **/\noutput example\n{@}\n') # ### 2. Run XULE against an XBRL report # The cell below compiles the sample.xule file above (the `{@}` XULE expression returns all facts for an XBRL report) and runs the .zip against the instance document listed in the command (NB: run the first code cell in this notebook with the -h switch instead of -v to get configuration paramters for the command). # In[ ]: get_ipython().system('arelleCmdLine -f "https://www.sec.gov/Archives/edgar/data/1753673/000121390022027184/f20f2021_scienjoyhold.htm" --plugins "xule | transforms/SEC" --xule-compile "sample.xule" --xule-run --xule-rule-set "sample.zip" --httpUserAgent "XULE-Arelle (xbrl.us; support@xbrl.us)" --logFormat="[%(messageCode)s] %(message)s"') # # Any **[example]** details listed above were found in the report ('example' is the default name of the output in the sample.xule file above). Modify and re-run the _1. Define_ and _2. Run_ cells, or change and re-run the report in the _2. Run_ cell to get different results. # #