<jupyter_start><jupyter_text>Getting Compliance Documentation**Author**: <NAME>**Label**: Model Management ScopeThe scope of this notebook is to provide instructions on how to get Compliance Documentation documents using the Python API. BackgroundCompliance documentation is a premium add-on product to DataRobot. It allows users to automatically generate and download documentation to assist with deploying models in highly regulated industries. Requirements- Python version 3.7.3-  DataRobot API version 2.19.0. Small adjustments might be needed depending on the Python version and DataRobot API version you are using.Full documentation of the Python package can be found here: https://datarobot-public-api-client.readthedocs-hosted.comIt is assumed you already have a DataRobot Project object and a DataRobot Model object.  Import Libraries<jupyter_code>import datarobot as dr<jupyter_output><empty_output><jupyter_text>Downloading Compliance DocumentationTo download compliance documentation for a particular model, call ComplianceDocumentation on a particular project and model.  Next generate the documenation and save it to the path of your preference. Note that it downloads in DOCX format.<jupyter_code># Using the default template
doc = dr.ComplianceDocumentation(project.id, model.id)

# Start a job to generate documentation
job = doc.generate()

# Once the job is complete, download as a DOCX
job.wait_for_completion()
doc.download('/path/to/save')<jupyter_output><empty_output><jupyter_text>Creating a Custom TemplateYou can also use your own custom compliance documentation templates. The Default TemplateFirst, let’s get the default template. This can be done just by using ComplianceDocTemplate. It downloads as a JSON file.<jupyter_code>GetComplianceDocTemplate("path/to/filename.json")
default_template = dr.ComplianceDocTemplate.get_default()<jupyter_output><empty_output><jupyter_text>Updating the Default TemplateA common workflow for building your own template is downloading the default template and modifying it.<jupyter_code># Download the template and edit sections on your local machine
default_template.sections_to_json_file('path/to/save')

# Create a new template from your local file
my_template = dr.ComplianceDocTemplate.create_from_json_file(name='my_template', path='path/of/file')<jupyter_output><empty_output><jupyter_text>Alternatively, custom templates can also be created from scratch.<jupyter_code>sections = [{
            'title': 'Missing Values Report',
            'highlightedText': 'NOTICE',
            'regularText': 'This dataset had a lot of Missing Values. See the chart below: {{missing_values}}',
            'type': 'user'
            },
            {
            'title': 'Blueprints',
            'highlightedText': '',
            'regularText': '{{blueprint_diagram}} /n Blueprint for this model'
            'type': 'user'
            }]
template = dr.ComplianceDocTemplate.create(name='Example', sections=sections)<jupyter_output><empty_output><jupyter_text>You can then get and download your template:<jupyter_code># Specify the template_id to generate documentation using a custom template
doc = dr.ComplianceDocumentation(project.id, model.id, template.id)
job = doc.generate().wait_for_completion()
doc.download('/path/to/save')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07789473684210527, 'fraction_numerical': 0.002105263157894737, 'mean_word_length': 5.228464419475656, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '141452', 'license': 'Apache-2.0', 'n_tokens_mistral': 905, 'n_tokens_neox': 866, 'n_words': 315, 'path': 'Compliance Docs/Python/Getting Compliance Documentation.ipynb', 'repo_name': 'ahjota/examples-for-data-scientists', 'size': '3339'}