oplogger
A minimal library for capturing ML/NLP operation traces for later training data export.
Installation
pip install oplogger
# With PostgreSQL support
pip install oplogger[postgres]
# With export features (pandas, HuggingFace datasets)
pip install oplogger[export]
Note: The package is installed as
oploggerbut imported asoplog.
Quick Start
from oplog import configure, op, run, db, export
# Configure once at startup
configure(project="my_project", backend="sqlite:///traces.db")
# Log standalone operations
op("classify") \
.model("setfit-intent") \
.input(text="hello world") \
.output(label="greeting", score=0.95) \
.save()
# Log grouped operations within a run (with run-level metadata for A/B testing)
with run(strategy="rerank_v2", experiment="exp_042") as r:
op("retrieve") \
.model("bge-m3") \
.input(query="capital of France?", k=10) \
.output(candidates=["Paris is the capital..."]) \
.save()
op("rerank") \
.model("bge-reranker-base") \
.input(query="capital of France?", candidates=[...]) \
.output(ranked=["Paris is the capital..."], scores=[0.94]) \
.meta(latency_ms=42) \
.save()
# A run row is created on entry; its meta lives there (not on the ops).
# Data discovered mid-run can be appended: r.add_meta(outcome="ok")
# Flag the run itself (lands on the run row, not its operations)
db.flag(run_id=r.id, reason="training", note="clean example")
# Query runs
flagged_runs = db.runs(flagged_for="training")
run_row = db.get_run(r.id)
# Query and export
records = db.query(operation="rerank", flagged_for="training")
export.to_jsonl(records, "training_data.jsonl")
API Reference
Configuration
configure(project="name", backend="sqlite:///traces.db")
Backend formats:
- SQLite:
sqlite:///path/to/traces.db(auto-creates file and parent directories) - PostgreSQL:
postgresql://user:pass@host:port/dbname
Operations
op("operation_type") # Start building an operation
.model("model-name") # Model identifier
.input(**kwargs) # Input data (JSON)
.output(**kwargs) # Output data (JSON)
.meta(**kwargs) # Metadata (latency, tokens, etc.)
.tags("tag1", "tag2") # Categorical tags
.save() # Persist and return operation ID
Runs
with run() as r: # Auto-generated run ID
op(...).save() # seq=0
op(...).save() # seq=1
print(r.id) # Access run ID
with run("custom-id"): # Explicit run ID
...
# Run-level metadata (propagates to all operations in the run)
with run(strategy="methodA", experiment_id="exp123") as r:
op("test").save() # meta={"strategy": "methodA", "experiment_id": "exp123"}
op("test").meta(latency_ms=42).save() # meta includes both run + op metadata
Run metadata is merged with operation metadata. Operation-level values override run-level on conflicts.
Database Operations
# Query
records = db.query(
operation="rerank", # Filter by operation type
model="model-name", # Filter by model
run_id="...", # Filter by run
flagged_for="training", # Filter by flag
tags=["tag1", "tag2"], # Filter by tags (AND logic)
limit=100, # Pagination
offset=0,
)
# Runs (first-class rows: run-level meta, flags, and notes live here)
run_row = db.get_run("...")
rows = db.runs(project="...", flagged_for="review", limit=50)
# Flag — ids target operation rows; run_id targets the run row itself
db.flag(ids=[...], reason="training", note="optional note")
db.flag(run_id="...", reason="review", note="odd resolution")
# Unflag
db.unflag(ids=[...])
db.unflag(run_id="...")
Export
# JSONL
export.to_jsonl(records, "output.jsonl")
# CSV
export.to_csv(records, "output.csv")
# pandas DataFrame
df = export.to_dataframe(records)
# HuggingFace Dataset
dataset = export.to_dataset(records)
# Field selection (dot notation for nested fields)
export.to_jsonl(records, "output.jsonl", fields=["inputs.query", "outputs.score"])
Multi-Tracer Usage
For multiple projects or explicit control:
from oplog import Tracer
tracer = Tracer(project="my_project", backend="sqlite:///traces.db")
tracer.op("classify").input(...).save()
with tracer.run() as r:
tracer.op("rerank").input(...).save()
License
MIT
Metadata
Release files for oplogger 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oplogger-0.2.1.tar.gz | 29.1 kB | Without provenance | Details for oplogger-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oplogger-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for oplogger-0.2.1-py3-none-any.whl |
Total release size: 45.6 kB
Release files / oplogger-0.2.1.tar.gz
| Download URL | oplogger-0.2.1.tar.gz |
|---|---|
| Size | 29.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f0e5e7c200f06f3d9fe602c59fc4a56c1d687a5942d2af7e452f758042613692
|
|
BLAKE2b-256 checksum How to use checksums |
f20ac309f1eb81aa1814fb6a1a76000e31d4d7381d2ac12ea784798aaab29fa3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / oplogger-0.2.1-py3-none-any.whl
| Download URL | oplogger-0.2.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64cbf7d7a0268189dd9291a0055d165e3e84102d152aa588f38b017e6cd38e9c
|
|
BLAKE2b-256 checksum How to use checksums |
aa3989585e581e4799057186537ea377c4c2fe46cb318d029979e88e0a7ebb4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for oplogger 0.2.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.