Skip to main content

Tooling Library for Notebooks

Build Status PyPI Package Docs

Introduction

A modular Python toolkit designed to support notebook-based workflows. It provides reusable tools for data ingestion, transformations, visualisation, notifications, and microgrid metadata managers. These tools make the repository ideal for streamlining analytics workflows with minimal setup and building data pipelines, reporting workflows, and alert systems seamlessly in Jupyter or cloud notebooks.

Supported Platforms

The following platforms are officially supported (tested):

  • Python: 3.11
  • Operating System: Ubuntu Linux 20.04
  • Architectures: amd64, arm64

Contributing

If you want to know how to build this project and contribute to it, please check out the Contributing Guide.

Quick Start

Install the package, open the example notebooks, and explore the available modules.

Installation

# Choose the version you want to install or use the latest
pip install frequenz‑lib‑notebooks

Then open the prebuilt example notebooks using your preferred interface:

  • Classic Notebook: jupyter examples/
  • JupyterLab: jupyter-lab examples/

⚠️ Note: This project does not install jupyter or jupyterlab by default. You will need to install it separately if you want to run notebooks:

pip install jupyterlab

Code Examples

📧 Example 1: Generate an Alert Email (HTML Body Only)

This example shows how to:

  • Transform a pandas DataFrame of alert records into a structured HTML email using generate_alert_email.
  • Use AlertEmailConfig to control layout (e.g., table row limits, sorting by severity).
  • Integrate microgrid-component alerts cleanly into operational workflows (e.g., for notifications or reporting tools).
import pandas as pd
from IPython.display import HTML

from frequenz.lib.notebooks.alerts.alert_email import (
    AlertEmailConfig,
    generate_alert_email,
)
from frequenz.lib.notebooks.notification_utils import format_email_preview

# Example alert records dataframe
alert_records = pd.DataFrame(
    [
        {
            "microgrid_id": 1,
            "component_id": 1,
            "state_type": "error",
            "state_value": "UNDERVOLTAGE",
            "start_time": "2025-03-14 15:06:30",
            "end_time": "2025-03-14 17:00:00",
        },
        {
            "microgrid_id": 2,
            "component_id": 1,
            "state_type": "state",
            "state_value": "DISCHARGING",
            "start_time": "2025-03-14 15:06:30",
            "end_time": None,
        },
    ]
)

# Configuration for email generation
alert_email_config = AlertEmailConfig(
    displayed_rows=10,
    sort_by_severity=True,
)

# Generate the HTML body of the alert email
html_email = generate_alert_email(
    alert_records=alert_records, config=alert_email_config
)

# Output the HTML # or send it via email as shown in the next example
print(html_email)

# or preview it in a nicer format
HTML(format_email_preview(subject="Alert Notification", body_html=html_email))

📨 Example 2: Compose and Send Alert Email with Attachments

Continuing from Example 1, this snippet builds on the generated HTML email and demonstrates:

  • Configuring SMTP credentials and recipients.
  • Attaching both a CSV export of the alert data and optional visual plots.
  • Sending the email once or scheduling it periodically. Note that the periodic scheduling would make sense when the data also refreshes so as to not send the same email over and over again!
import time
from datetime import datetime

from frequenz.lib.notebooks.alerts.alert_email import ExportOptions, plot_alerts
from frequenz.lib.notebooks.notification_service import (
    EmailConfig,
    EmailNotification,
    SchedulerConfig,
)

# Configuration for email notification
email_config = EmailConfig(
    subject="Critical Alert",
    message=html_email,  # Assuming that html_email already exists. See the code example above on how to generate this.
    recipients=["recipient@example.com"],
    smtp_server="smtp.example.com",
    smtp_port=587,
    smtp_user="user@example.com",
    smtp_password="password",
    from_email="alert@example.com",
    scheduler=SchedulerConfig(
        send_immediately=True,
        interval=60,  # send every minute
        duration=3600,  # for one hour total
    ),
)
# The SMTP details and sender/recipient details need to be adjusted accordingly
# note that the library provides a convenient way to validate the settings via frequenz.lib.notebooks.notification_utils.validate_email_config

# Create a notification object
email_notification = EmailNotification(config=email_config)

# optionally add attachments (a list of files)
email_config.attachments = None
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
alert_file_name = f"alert_details_{timestamp}.csv"
alert_records.to_csv(alert_file_name, index=False)
email_config.attachments = [alert_file_name]

# Optionally create a visualisation of the alert records
img_path = plot_alerts(
    records=alert_records,
    plot_type="all",
    export_options=ExportOptions(
        format="png",
        show=True,
    ),
)
email_config.attachments += img_path if img_path else []

# Send one-off notification
email_notification.send()

# Or start a periodic scheduler:
email_notification.start_scheduler()
time.sleep(300)  # let it run for 5 minutes
email_notification.stop_scheduler()

Module Overview

  • Solar Maintenance App: Interactive forecasting and visualisation tools tailored to solar installations.
  • Notification Service: Flexible and configurable email dispatching.
  • Alert Email Generation: Embed rich Plotly charts into alert emails, complete with context and summaries.
  • Microgrid Configuration: Manage structured microgrid metadata—location, devices, etc. — consistently across notebooks.

For more details about each module/project, please refer to the overview Wiki page which has links to dedicated project pages.

The full code documentation can be accessed here.

Metadata

Release files for frequenz-lib-notebooks 0.16.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for frequenz-lib-notebooks 0.16.7
File Size Uploaded
frequenz_lib_notebooks-0.16.7.tar.gz 3.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for frequenz-lib-notebooks 0.16.7
File Interpreter ABI Platform
frequenz_lib_notebooks-0.16.7-py3-none-any.whl Python 3 none any Details

Total release size: 3.4 MB

Release files / frequenz_lib_notebooks-0.16.7.tar.gz

Download URL frequenz_lib_notebooks-0.16.7.tar.gz
Size 3.3 MB
Tags Source
SHA-256 checksum
How to use checksums
013fdc94ca268308baaa420c310c3538bc0848815d5ea61e434c572630390f0d
BLAKE2b-256 checksum
How to use checksums
77f865f02c742cb0e5a057223bab7f883fa16ce5c1dc2266547903dc1ae2a4e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / frequenz_lib_notebooks-0.16.7-py3-none-any.whl

Download URL frequenz_lib_notebooks-0.16.7-py3-none-any.whl
Size 172.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9c9114a797159fcbe8e8708271ead4ae93549ef1a3d17fb7a935b31b2a2570c
BLAKE2b-256 checksum
How to use checksums
8dc511988cfad212efffeb5dbb03d4a194eaaed9155aa155df09dd64fc2d4884
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.16.7 This release

2 release files

0.16.5

2 release files

0.16.4

2 release files

0.16.3

2 release files

0.16.2

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.7

2 release files

0.14.6

2 release files

0.14.5

2 release files

0.14.4

2 release files

0.14.3

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.2

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page