PICTIFY
How to create real time snapshot of your reports using Python and Pictify
Programming

How to create real time snapshot of your reports using Python and Pictify

Pictify Engineering
19 Jul
3 min read

Introduction

In the fast pace world of data and analytics, having real-time snapshots of your data dashboards is crucial for timely reporting and alerts. Converting these dashboards into images can streamline sharing and archiving processes. In this post, we'll explore how to capture real-time snapshots of reports using Python and Pictify API.

Why convert reports to images?

Converting reports to images has several benefits:

  1. Shareability: Images are easy to share via email, chat, or social media, making it simple to distribute reports to stakeholders.
  2. Archiving: Images can be easily stored and archived for future reference, ensuring that historical data is preserved.
  3. Visual representation: Images provide a visual representation of data, making it easier for stakeholders to understand and interpret the information.

Prerequisites

  1. Python: Make sure you have Python installed on your machine. You can download Python from the official website.
  2. Pictify API key: Sign up for a free account on the Pictify website to get your API key.
  3. Requests library: Install the requests library by running the following command in your terminal:
bash

Step 1: Set up the code

First, import the necessary libraries and define the URL of the report you want to capture:

python

Step 2: Identify the report elements to capture

Next, inspect the report page to identify the elements you want to capture. You can use browser developer tools to find the CSS selectors or the id of the elements you want to capture. The elements could be charts, tables, or any other visualizations on the report.

python

Step 3: Capture the report elements

Now, use the Pictify API to capture the report elements as an image:

python

Replace YOUR_API_KEY with your actual API key.

Step 4: Download the image

Finally, download the image using the URL provided by the Pictify API if needed or else you can directly use the URL to share the image.

python

Step 5: Automate the process

To automate the process of capturing real-time snapshots of reports, you can schedule the script to run at specific intervals using tools like cron jobs or Windows Task Scheduler.

Step 6: Handle errors and retries

The steps above assume every request succeeds. In a scheduled job running every few minutes, that assumption breaks eventually: the target dashboard times out, Pictify has a transient 5xx, or your API key expires. None of that should crash a cron job silently or, worse, fail silently and leave you thinking snapshots are still being captured when they aren't.

Wrap the render call in a small retry helper that backs off on server errors and timeouts, but fails fast and loud on client errors (a 4xx almost always means something in the request itself is wrong, and retrying won't fix it):

python

Swap the bare requests.post(...) call from Step 3 for capture_snapshot(url, selector, api_key), and a scheduled job now degrades gracefully instead of dying on the first flaky request.

Step 7: Store snapshots in cloud storage instead of local disk

Writing to report_snapshot.png on local disk works for a one-off script, but it doesn't hold up once the capture runs on a schedule: the file gets overwritten every run, there's no history, and nothing outside that machine can see it. If the job runs on a server or in a container, "local disk" might not even persist between runs.

Upload the captured image straight to S3 (or any S3-compatible bucket; this works unchanged against R2, DigitalOcean Spaces, etc.) instead of writing it to disk, and key each object by timestamp so you get a running history for free:

python

Now a scheduled run looks like: capture with capture_snapshot(), upload with upload_snapshot(), and you're left with a timestamped archive in S3 instead of a single file that gets clobbered every run. If you need public sharing links without exposing the whole bucket, generate a presigned URL (s3.generate_presigned_url(...)) instead of relying on a public bucket policy.

Step 8: Send snapshots to Slack when something needs attention

The whole point of a real-time snapshot is usually to notice something before someone has to go looking for it. Pair the capture with a Slack webhook so a snapshot shows up in a channel the moment it's taken, instead of sitting in S3 waiting to be checked manually:

python

Slack's image block needs a URL it can fetch itself, so pass it the S3 URL from Step 7 (or the raw Pictify image_url from capture_snapshot() if you're not archiving to S3). A minimal alerting loop then looks like:

python

Three functions, each doing one job (capture, archive, notify), and you can run any subset depending on whether a given schedule needs Slack alerts or just a silent archive.

Example

Let's say you want to capture a real-time snapshot of Digital Ocean status dashboard. Here's how you can do it:

python

This script captures the status of Digital Ocean components and saves it as an image named digitalocean_status.png.

The output image will look like this:

Example screenshot of a Digital Ocean status report rendered as an image via the Pictify API

Conclusion

Capturing real-time snapshots of reports can be a valuable addition to your reporting and alerting workflows. By converting reports to images, you can easily share, archive, and visualize data for better decision-making. With the Pictify API and Python, you can automate the process of capturing snapshots and streamline your reporting processes.

If you have any questions or need help with implementing this solution, feel free to reach out to us. We're here to help!

Happy reporting!

Free Tier Available

Run Your First Batch In Under 5 Minutes

Sign up, pick a template, add your data. Get pixel-perfect documents rendered and delivered in minutes.

Read Docs
4:59
Time to first batch
API Ready
50 Free Credits

Instant Access

Get your API key immediately upon signup. Start integrating in seconds.

50 Free Credits

No credit card required. Test the API for free and see the pixel-perfect results.

Secure Infra

Enterprise-ready security and isolation. Your data is processed safely.