Skip to main content

WXYC library catalog access and operations — CatalogSource protocol, SQLite export, artist enrichment, label extraction.

Project description

wxyc-catalog

WXYC library catalog access and operations. This package defines the CatalogSource protocol — a read-only interface to the WXYC library catalog — with implementations for tubafrenzy (MySQL) and Backend-Service (PostgreSQL). It also provides CLI tools that produce pipeline inputs for downstream services: library.db (SQLite with FTS5), library_artists.txt, and library_labels.csv.

CatalogSource Protocol

CatalogSource is a @runtime_checkable Protocol that abstracts over the two catalog databases. Both implementations return identical data structures despite different underlying schemas.

class CatalogSource(Protocol):
    def fetch_library_rows(self) -> list[dict[str, Any]]:
        """Library releases. Keys: id, title, artist, call_letters,
        artist_call_number, release_call_number, genre, format,
        alternate_artist_name."""

    def fetch_alternate_names(self) -> set[str]:
        """Alternate artist names (e.g. 'Body Count' filed under Ice-T)."""

    def fetch_cross_referenced_artists(self) -> set[str]:
        """Artist names from both sides of the artist cross-reference table."""

    def fetch_release_cross_ref_artists(self) -> set[str]:
        """Artist names from library-level cross-references."""

    def fetch_library_labels(self) -> set[tuple[str, str, str]]:
        """(artist, title, label) triples from flowsheet plays."""

    def close(self) -> None:
        """Release the database connection."""

Implementations

Source Database Connection
TubafrenzySource MySQL 4.1+ (Kattare) pymysql
BackendServiceSource PostgreSQL (Backend-Service) psycopg

Use the factory function to create a source by name:

from wxyc_catalog import create_catalog_source

source = create_catalog_source("tubafrenzy", "mysql://user:pass@host/db")
# or
source = create_catalog_source("backend-service", "postgresql://user:pass@host/db")

MySQL 4.1 Compatibility

Kattare runs MySQL 4.1.22 with old-format password hashes. No modern Python MySQL driver supports this auth protocol. The daily library sync workflow (discogs-etl/scripts/sync-library.sh) uses the MariaDB mysql CLI client instead, which handles old auth natively. The connect_mysql() function in this package uses pymysql, which works with MySQL 5.x+ servers.

Installation

pip install wxyc-catalog

For MySQL support (tubafrenzy):

pip install "wxyc-catalog[mysql]"

CLI Tools

wxyc-export-to-sqlite

Exports the library catalog to a SQLite database with an FTS5 full-text search index on title, artist, and alternate_artist_name.

wxyc-export-to-sqlite \
    --catalog-source tubafrenzy \
    --catalog-db-url mysql://user:pass@host/db \
    --output library.db

wxyc-enrich-library-artists

Generates library_artists.txt containing all unique artist names, enriched with alternate names, cross-references, and contextual splitting of multi-artist entries (names with commas, slashes, ampersands) via wxyc_etl.

wxyc-enrich-library-artists \
    --library-db library.db \
    --catalog-source backend-service \
    --catalog-db-url postgresql://user:pass@host/db \
    --output library_artists.txt

wxyc-extract-library-labels

Extracts (artist, title, label) triples from flowsheet plays to CSV.

wxyc-extract-library-labels \
    --catalog-source tubafrenzy \
    --catalog-db-url mysql://user:pass@host/db \
    --output library_labels.csv

Programmatic Usage

from wxyc_catalog import create_catalog_source, export_rows_to_sqlite
from pathlib import Path

source = create_catalog_source("backend-service", "postgresql://user:pass@host/db")
rows = source.fetch_library_rows()
source.close()

export_rows_to_sqlite(rows, Path("library.db"))

Downstream Consumers

Repo Usage
discogs-etl CI tests import CatalogSource for integration/E2E tests. Pipeline scripts use enrich_library_artists and extract_library_labels. The daily sync workflow queries MySQL directly via CLI (bypassing Python drivers for MySQL 4.1 compatibility) but replicates the same SQLite schema as export_rows_to_sqlite.

Dependencies

  • psycopg[binary]>=3.1 — PostgreSQL driver
  • wxyc-etl>=0.1.0 — text normalization (split_artist_name_contextual, is_compilation_artist)
  • pymysql>=1.0 — MySQL driver (optional, [mysql] extra)

Development

pip install -e ".[dev]"
pytest
ruff check
ruff format --check

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

wxyc_catalog-0.1.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

wxyc_catalog-0.1.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file wxyc_catalog-0.1.0.tar.gz.

File metadata

  • Download URL: wxyc_catalog-0.1.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for wxyc_catalog-0.1.0.tar.gz
Algorithm Hash digest
SHA256 140e3725787a9cf94563ed3f7b83edb102e148edfc682e0b7cb59d4d869025d4
MD5 539fed5046ce4a9692b68acf40208e7a
BLAKE2b-256 efd11de1bf59f0a58041473a6a771cb1438afd4e76e563b7aef693c6829c98ad

See more details on using hashes here.

File details

Details for the file wxyc_catalog-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wxyc_catalog-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for wxyc_catalog-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf1ce69a48ce3e9a3f94b5539941ff87c017018b06a6b73a4541ad7ec4354de0
MD5 193b3801ab4c742ef1952ad186d1bc60
BLAKE2b-256 a9637604c49a9591b3dba4f9c3fe87ce8fcb3b2230a3d579fb9ee99b46718bbf

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