# Check Attachments

Checks can provide additional results in the form of attachments. These can e.g. be data or screenshots.

To create attachments in your checks, create files in the $CHECKSON_DIR/attachments directory.

CHECKSON_DIR is an environment variable that is set by the Checkson cloud executor when it runs your Docker image. You will have to create the attachments subfolder before you create files in there.

Let's look at an example:

import sys
import os
import datetime

checkson_dir = os.environ.get('CHECKSON_DIR', '/tmp')
attachments_dir = f"{checkson_dir}/attachments"
attachment_file = f"{attachments_dir}/example-attachment.txt"


def write_attachment(data):
    if not os.path.exists(attachments_dir):
        print(f"Creating {attachments_dir}")
        os.makedirs(attachments_dir)

    print(f"Creating artifact: {attachment_file}")
    with open(attachment_file, "w") as f:
        f.write(str(data))


def main():
    write_attachment(f"Check was executed at {datetime.datetime.now()}")

    # This check always succeeds
    sys.exit(0)


if __name__ == "__main__":
    main()

This script creates a simple helper function (write_attachment) that creates an attachment called $CHECKSON_DIR/attachments/example-attachment.txt. The helper function is used to write some information related to the check.

Since the file is in the $CHECKSON_DIR/attachments directory, it will be picked up by Checkson as an attachment to the check run.

All attachments of a check can be downloaded from the details page of a check run in the Checkson web UI.