Skip to main content
LittleLogger Logo
A lightweight, zero-setup decorator for logging ML experiments to a JSONL file.

This tool is for the solo data scientist, student, or hobbyist in a Jupyter Notebook who just wants to keep track of their experiments without setting up a database or heavy framework.

Quick Setup

Get started in 30 seconds.

1. Install from PyPI:

pip install littlelogger

2. Import and use the decorator:

from littlelogger import log_run

# NOTE: for this to work, we need the training function to input the parameters that need to be logged
# and output the performance metric e.g., f1_score, accuracy_score, etc.
@log_run(log_file="my_experiments.jsonl")
def train_model(learning_rate, n_estimators):
    # Your training logic...
    f1 = 0.80
    return {"f1_score": f1}

# Just run your function as normal
train_model(0.1, 100)
train_model(0.05, 200)

3. Check your results: A my_experiments.jsonl file will be created, logging every run.

See it in Action

Want to see how it works? Check out the Demo Notebook to see a real-world example of logging experiments from different models into one file.

The Problem

You're tuning a model and your notebook looks like this:

# metrics = train_model(max_depth=5, n_estimators=100) # f1: 0.82
# metrics = train_model(max_depth=7, n_estimators=100) # f1: 0.81
metrics = train_model(max_depth=5, n_estimators=200) # f1: 0.83
print(metrics)

A day later, you've lost track of your best run.

The Solution

Wrap your function with the @log_run decorator.

from littlelogger import log_run

@log_run(log_file="experiment_log.jsonl")
def train_model(max_depth, n_estimators):
    # ... your training logic ...
    f1_score = 0.83 # Your metric
    return {"f1": f1_score}

# Run your experiments
train_model(max_depth=5, n_estimators=100)
train_model(max_depth=7, n_estimators=100)
train_model(max_depth=5, n_estimators=200)

This will create a experiment_log.jsonl file with one line per experiment:

{"timestamp": "2025-11-01T16:30:00...", "runtime_seconds": 12.3, "params": {"max_depth": 5, "n_estimators": 100}, "metrics": {"f1": 0.82}}
{"timestamp": "2025-11-01T16:32:12...", "runtime_seconds": 14.1, "params": {"max_depth": 7, "n_estimators": 100}, "metrics": {"f1": 0.81}}
{"timestamp": "2025-11-01T16:34:45...", "runtime_seconds": 23.5, "params": {"max_depth": 5, "n_estimators": 200}, "metrics": {"f1": 0.83}}

Analyzing Your Results

You can easily load your results back into pandas to find your best run. The key is using load_log() from littlelogger

from littlelogger import load_log

log_df = load_log(PATH_TO_LOG_FILE)

# Find your best run!
log_df.sort_values(by="metric_f1_score", ascending=False)

API Reference

@log_run(log_file="experiment_log.jsonl")

This is the main decorator. You place it above your function definition.

Parameters:

  • log_file (str): The path to the .jsonl file where logs will be written.
    • Default: "experiment_log.jsonl"
    • Behavior: The decorator will append to this file. It does not overwrite.

What is Logged?

The decorator will write a single JSON line to the file for each function call, containing:

  • timestamp: An ISO 8601 formatted UTC timestamp.
  • function_name: The name of the function that was run (e.g., train_model).
  • runtime_seconds: The execution time of the function (in seconds).
  • params: A dictionary of all arguments (including defaults) passed to your function.
  • metrics: The value returned by your function. This is expected to be a dictionary (e.g., {"f1": 0.8, "accuracy": 0.9})

⚠️ Important Limitations

This tool is built for simplicity and has intentional trade-offs:

  1. Not Thread-Safe: This logger is NOT designed for concurrency. If you run functions in parallel (using multiprocessing or threading from the same script), they will try to write to the log file at the same time, which will corrupt the file. It is for single-process, iterative experiments only.
  2. JSON-Serializable Data Only: The decorator assumes your function arguments and return values are "JSON-serializable" (strings, ints, floats, lists, dicts). If you return a complex object (like a scikit-learn model), the logger will fail to serialize it.
  3. Best-Effort Logging (No Retries): If logging fails (due to a non-serializable object or a file permission error), littlelogger will not crash your script. It will print a UserWarning to your console and let your function return its value, prioritizing your main script's execution over logging.

License & Contributing

  • License: This project is licensed under the MIT License. See the LICENSE file for details.
  • Contributing: Feel free to open an issue or submit a pull request!

Metadata

Release files for littlelogger 1.1.1

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

Source distribution (sdist)

Source distribution for littlelogger 1.1.1
File Size Uploaded Provenance
littlelogger-1.1.1.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for littlelogger 1.1.1
File Interpreter ABI Platform
littlelogger-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / littlelogger-1.1.1.tar.gz

Download URL littlelogger-1.1.1.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d574feb56043fc19b67001cd748fbdf916330b8dd099c1e398124d2c25120e7f
BLAKE2b-256 checksum
How to use checksums
09a0f1656843dbbccffe60f6a40dc7af574f2b6949e738861830374cae7b4f98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.9 Linux/6.11.0-1018-azure

Release files / littlelogger-1.1.1-py3-none-any.whl

Download URL littlelogger-1.1.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4220056fd793b41819c8b1e065c2314b33a8afd327ea4e337fd9130b3f7ee32
BLAKE2b-256 checksum
How to use checksums
a5b16d21bc14579920711f3f90e43b4c9c2fafde705bbf9e7bf89b208a2a3a9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.9 Linux/6.11.0-1018-azure

Security for littlelogger 1.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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