This interactive environment copies the free, open-source XULE plugin to a working Python environment with Arelle plus additional packages. 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.
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
%pip -q install Arelle-release==2.23.1
%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
!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)
!arelleCmdLine --plugins 'xule' -v
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).
%%writefile 'sample.xule'
/** add constants and namespaces below **/
/** modify rule below **/
output example
{@}
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).
!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.