Skip to main content

A Python toolkit for ML experiment management based on SwanLab and Lark

Project description

OwLab logo

OwLab

ML experiments, tracked & notified.

A Python toolkit for the full lifecycle of machine learning experiments — experiment tracking with SwanLab, notifications & data management with Lark (Feishu), and local storage.

PyPI swanlab Static Badge License Python 3.9+


✨ Features

📈 Metrics and Tracking: Embed minimal code into your ML pipeline to track and record key training metrics based on SwanLab.
📊 Data Management: Automatically organize your experiment directory structure based on experiment type and tags, enabling better management of experimental data.
📢 Message Notifications: Automatic push notifications are sent when the experiment starts, ends, or is interrupted, keeping you informed of the latest progress.
💾 Backup: Back up your data in the cloud and locally to prevent data loss.


🚀 Quick Start

📦 Installation

pip install owlab
# or: uv pip install owlab
# or: use source code
# git clone https://github.com/Lounwb/OwLab.git && cd OwLab && pip install -e .

⚙️ Configuration

To enable Lark and Swanlab, you need to configure the relevant tokens and secrets. Owlab supports both configuration files and environment variables, providing you with flexible options:

  • Configuration file: ~/.owlab/config.json or ./.owlab/config.json, here is an example:
// configure your lark and swanlab in .owlab/config.json
{
    "lark": {
      "webhook": {
        "webhook_url": "<your webhook url>",
        "signature": "<your webhook signature>"
      },
      "api": {
        "app_id": "<your app id>",
        "app_secret": "<your app secret>",
        "root_folder_token": "<your root folder token>"
      }
    },
    "swanlab": {
      "api_key": "<your swanlab api key>"
    },
    "storage": {
      "local_path": "./output",
      "csv_path": "./output/csv",
      "model_path": "./output/models"
    },
    "logging": {
      "level": "INFO",
      "format": null,
      "file": "./logs/owlab.log"
    }
  }
  
  • Environment: OWLAB_LARK__WEBHOOK__WEBHOOK_URL, OWLAB_LARK__API__APP_ID, etc.

📖 Usage

1. Initialize

from owlab import OwLab

owlab = OwLab()
owlab.init(
    project="my_project",           # Required
    experiment_name="exp_001",      # Optional; defaults to project
    description="Short description",
    type="baseline",                # e.g. baseline / debug / ablation — used for folder naming
    version="1.0",                 # Experiment version
    tags=["baseline"],             # Optional tags
    config={
        "methods": [...],          # Method definitions for result tables
        "datasets": [...],
        "metrics": [...],
        "measures": [...],
        "experiment_params": {"learning_rate": 0.01, "batch_size": 32},
        "seed": 42,
    },
)

2. Log metrics during training

for epoch in range(100):
    owlab.log({"loss": loss, "accuracy": acc}, step=epoch)

3. Finish and save results

Call finish(results=...) with a list of result rows. Each row can include method, dataset, measure, and metric values. These are written to local files and, when configured, to Feishu spreadsheets.

owlab.finish(results=[
    {
        "method": "method1",
        "dataset1": {"measure": "MCM", "accuracy": 0.95, "loss": 0.05},
        "dataset2": {"measure": "MCM", "accuracy": 0.92, "loss": 0.08},
        "Average": {"measure": "MCM", "accuracy": 0.935, "loss": 0.065},
    },
    # ...
])

4. Sync PyTorch TensorBoard to SwanLab

Like SwanLab’s swanlab.sync_tensorboard_torch(): call after init() and before creating SummaryWriter. Then writer.add_scalar() / add_scalars() also log to the current SwanLab run.

owlab.init(project="my_project", experiment_name="exp_1", ...)
owlab.sync_tensorboard_torch()

from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter(log_dir="./runs")
writer.add_scalar("loss", loss, step)   # also sent to SwanLab
writer.add_scalar("acc", acc, step)

5. Output layout

  • Local: ./output/<type>/<experiment_name>_<timestamp>/
    • results.csv, results.json, owlab.log, model/
  • Lark: Notifications via webhook; result tables written to Feishu via API (when configured).
  • SwanLab: Metrics and runs visible in your SwanLab project (when api_key is set).

📄 License & Links


🙏 Acknowledgments

⭐ Star History

Star History Chart

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

owlab-0.1.3.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

owlab-0.1.3-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file owlab-0.1.3.tar.gz.

File metadata

  • Download URL: owlab-0.1.3.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for owlab-0.1.3.tar.gz
Algorithm Hash digest
SHA256 50bfce0a86cd32eb3b80bc4df41ff2c4cc3c36e0c5e396e94b4f5c2d0ccc857a
MD5 6fa483ea7027e2c0a01893559f6ce59b
BLAKE2b-256 43b7e67e20e80509645586441472f96c3dce735dcb05d27374a879e13c3fa96d

See more details on using hashes here.

File details

Details for the file owlab-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: owlab-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for owlab-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cb576037f5e168dfcbda9bce29db5b3561ba5035afa205492b1b230b2987618e
MD5 b162c5f02f8a6fc964f634c35b548978
BLAKE2b-256 5f05100f8a8322d164256492dacfe2b52c92472cadd3137a849e800a5085d837

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page