--- title: "Export Documentation Handler" description: "How to define a custom handler that exports an object's documentation to a 3rd party application." --- The export documentation handler needs to be defined if we want to export the documentation for the object (DataElement/Feature/Model/Policy) for custom processing. See also the [Export Artifact Handler](/technology/customization/export/export-artifact-handler/) for exporting an object's artifact bundle the same way. ## Utility By default, the user has an option to download the documentation to local computer. There could be scenarios when that's not enough. The user might want to export the documentation to some other application, give the link to the users on Corridor Platform, which the user could go to. Export documentation handler can be used to send the artifact as bytes buffer (io.BytesIO), using API calls. ## Handler class The user would need to define a `CustomExportDocumentationHandler` which would inherit Corridor's base export documentation handler class: `corridor_api.config.handlers.ExportDocumentationHandler` The logic for artifact export would be defined the following method(s) inside `CustomExportDocumentationHandler`. - `export_documentation(obj, username, job)` ### Example ```python import datetime import requests from corridor import DataElement, Feature, Model, Policy from corridor_api.config.handlers import ExportDocumentationHandler class CustomExportDocumentationHandler(ExportDocumentationHandler): name = 'document_export' @classmethod def export_documentation(self, object, username, job=None): if isinstance(object, DataElement): object_type = 'DataElement' elif isinstance(object, Feature): object_type = 'Feature' elif isinstance(object, Model): object_type = 'Model' elif isinstance(object, Policy): object_type = 'Policy' else: raise NotImplementedError(f'{type(object)} not handled !!!') current_time = datetime.datetime.now() object_name = object.name object_version = object.version export_type = 'document' json_info = { 'export_type': export_type, 'username': username, 'object_type': object_type, 'object_name': object_name, 'object_version': object_version, 'current_time': current_time.isoformat(), 'document': None, # we can create any type of documentation, using info from the object, and pass it here } headers = {} # any headers can be configured (optional) # assuming /export is the endpoint for the POST api in the 3rd party application running on port: 7006 url = 'http://externaltool.example.com/export' res = requests.post(url, json=json_info, headers=headers) # assuming /export also serves as GET api, with appropriate query_params link = f'http://externaltool.example.com/export?export_type={export_type}&user={username}&object_type={object_type}&object_name={object_name}&object_version={object_version}¤t_time={current_time}' type_ = 'info' if res.status_code == 200 else 'error' message = 'success' if res.status_code == 200 else 'failure' return {'link': link, 'message': message, 'type': type_} ``` ## Configurations Export documentation handler related configurations need to be set in `api_config.py` along with other configurations (assuming the `CustomExportDocumentationHandler` class is defined in the file `custom_export_documentation_handler.py`). ```python EXPORT_DOCUMENTATION = { 'External Export Documentation': { 'handler': 'custom_export_documentation_handler.CustomExportDocumentationHandler', 'return': 'message', }, } ```