Skip to main content

Golden dataset management

Project description

golden-dataset

A Python library for creating, managing, and sharing golden datasets.

Overview

Golden datasets are curated samples of data used for testing, development, and demonstration purposes. This library provides a simple way to create, export, and load golden datasets in a consistent format.

Features

  • Define dataset generators with a simple @golden decorator
  • Track dependencies between datasets
  • Support for both SQLModel and SQLAlchemy models
  • Generate datasets programmatically or via CLI
  • Export datasets to JSON files
  • Import datasets into any SQLAlchemy or SQLModel session

Installation

From PyPI

# Basic installation
pip install golden-dataset

# With SQLModel support
pip install golden-dataset[sqlmodel]

# With SQLAlchemy support
pip install golden-dataset[sqlalchemy]

# With CLI support
pip install golden-dataset[cli]

# With async support
pip install golden-dataset[async]

# With all optional dependencies
pip install golden-dataset[all]

From source

# Using uv (recommended)
uv pip install .

# With specific optional dependencies
uv pip install ".[sqlmodel]"
uv pip install ".[sqlalchemy]"
uv pip install ".[all]"

# Or using pip
pip install .
pip install ".[sqlmodel]"

Usage

Creating a golden dataset

# base_dataset.py
from golden_dataset import golden
from myapp.models import EventType

@golden
def base(session):
    event_type1 = EventType.model_validate({"id": 0, "name": "Purchase"})
    event_type2 = EventType.model_validate({"id": 1, "name": "Landing page"})
    event_type3 = EventType.model_validate({"id": 2, "name": "Sign-Up"})
    event_type4 = EventType.model_validate({"id": 3, "name": "Lead"})
    event_type5 = EventType.model_validate({"id": 99, "name": "Other"})
    session.add(event_type1)
    session.add(event_type2)
    session.add(event_type3)
    session.add(event_type4)
    session.add(event_type5)

Creating a dataset with dependencies

# bloom_organics_dataset.py
from golden_dataset import golden
from myapp.models import Brand, Font, Brandkit

@golden(dependencies=["base"])
def bloom_organics(session):
    brand = Brand.model_validate({
        "code": "bloom_organics",
        "name": "Bloom Organics",
        "description": "Clean, plant-based skincare formulated with certified organic ingredients.",
        # ... more fields
    })
    session.add(brand)
    session.refresh(brand)
    
    font1 = Font.model_validate({
        "brand_id": brand.id,
        "font_family": "Cormorant Garamond",
        "font_weight": 500,
        "font_style": "normal",
        "source": "https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500&display=swap"
    })
    session.add(font1)
    # ... add more objects

Generating datasets programmatically

from golden_dataset import generate_dataset

# Generate a dataset and its dependencies
dataset = generate_dataset("bloom_organics_dataset:bloom_organics", "output_dir")

Loading datasets into a database

from golden_dataset import load_dataset
from sqlmodel import Session, create_engine

# Create a database engine
engine = create_engine("sqlite:///app.db")

# Define a session factory
def session_factory():
    return Session(engine)

# Load the dataset
load_dataset("output_dir/bloom_organics", session_factory)

Using the CLI

# Generate a dataset
golden-dataset generate "bloom_organics_dataset:bloom_organics" --output-dir datasets

# List available datasets
golden-dataset list-datasets --datasets-dir datasets

# Import a dataset (demo only)
golden-dataset import-dataset bloom_organics --datasets-dir datasets

Development

Development setup

# Using uv (recommended)
uv venv
uv sync --all --dev

# Or using pip (traditional approach)
pip install -e ".[dev,all]"

Code formatting and linting

# Format code with Ruff
ruff format src tests

# Run Ruff linter
ruff check src tests

# Auto-fix issues where possible
ruff check --fix src tests

Running tests

pytest

Running with code coverage

pytest --cov=golden_dataset

Type checking

mypy src

License

MIT Dataset for testing" --version "1.0.0"


Add a record to a dataset:

```bash
golden-dataset add-record 1 content.json --metadata-file metadata.json

List all datasets:

golden-dataset list-datasets

Export a dataset to JSON:

golden-dataset export-dataset 1 dataset_export.json

Python API

from golden_dataset.database import Database
from golden_dataset.models import Dataset, Record

# Initialize the database
db = Database("sqlite:///golden.db")
db.create_tables()

# Create a new dataset
dataset = Dataset(
    name="My Test Dataset",
    description="A dataset for testing",
    version="1.0.0",
    metadata={"source": "manual", "category": "test"}
)
db.add(dataset)

# Add a record to the dataset
record = Record(
    content={"key": "value", "test": True, "count": 42},
    metadata={"quality": "high"},
    dataset_id=dataset.id
)
db.add(record)

# Query datasets
test_datasets = db.query(Dataset, name="My Test Dataset")
for dataset in test_datasets:
    print(f"Dataset: {dataset.name} (version {dataset.version})")
    print(f"Records: {len(dataset.records)}")

Publishing to PyPI or a Private Registry

Setting up for publishing

  1. Create a PyPI account if publishing to the public PyPI
  2. Generate an API token for the registry
  3. Set up GitHub Actions for automated publishing (see .github/workflows/publish.yml)

Publishing with uv

Using uv for publishing:

# Build the package
uv build

# Publish to PyPI
uv publish

# Publish to a private registry
uv publish --repository-url https://your-private-registry/simple

Publishing with twine

Alternatively, you can use twine:

# Build the package
python -m build

# Publish to PyPI
twine upload dist/*

# Publish to a private registry
twine upload --repository-url https://your-private-registry/simple dist/*

Development

Running tests

pytest

Running with code coverage

pytest --cov=golden_dataset

Code formatting and linting

# Format code with Ruff
ruff format src tests

# Run Ruff linter
ruff check src tests

# Auto-fix issues where possible
ruff check --fix src tests

Type checking

mypy src

License

MIT

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

golden_dataset-1.0.5.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

golden_dataset-1.0.5-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file golden_dataset-1.0.5.tar.gz.

File metadata

  • Download URL: golden_dataset-1.0.5.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for golden_dataset-1.0.5.tar.gz
Algorithm Hash digest
SHA256 20663fba0ae3649837ba518acd1b7023de3c704fecb7402c37dbcfd0ae0c45f3
MD5 5bb7376bed46c250ebbdf48ab28d9d18
BLAKE2b-256 90169956e7debdd8937b20d50ffe083043d290596795e2434c336fe938571d08

See more details on using hashes here.

Provenance

The following attestation bundles were made for golden_dataset-1.0.5.tar.gz:

Publisher: publish.yml on sethyates/golden-dataset

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file golden_dataset-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: golden_dataset-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for golden_dataset-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 100784a49d157a7f273969e4790e1a1c60951f8c2ae2e337bb54ee0d02391b8b
MD5 900eacbe71246b16f2f581b3b29d1ce3
BLAKE2b-256 21e1eaa3130b2744c54091acc2ae4e8fbd42a45c79014e451f0c7d9c10d96302

See more details on using hashes here.

Provenance

The following attestation bundles were made for golden_dataset-1.0.5-py3-none-any.whl:

Publisher: publish.yml on sethyates/golden-dataset

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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