Skip to main content

Python client and service layer for Open Opus API with caching and normalized models

Project description

Open Opus

A lightweight Python package that provides a stable interface to the Open Opus API.

This project exists to decouple application code from the Open Opus API's raw response formats and availability characteristics.


Requirements

  • Python >= 3.10

Installation

Library only:

pip install openopus

Quick Start

from openopus import OpenOpus

svc = OpenOpus()

# List all composers
composers = svc.composers()

# Search by name (partial match)
results = svc.composers_by_name("Bach")

# Fetch a single composer
bach = svc.composer(196)

# Get all works by a composer
works = svc.works(196)

# Get works filtered by genre
keyboard_works = svc.works(196, genre="Keyboard")

# Get detailed info for a single work
work = svc.work_detail(1234)

# Get all valid period names
periods = svc.periods()

# Get composers from a specific period
baroque = svc.composers_by_period("Baroque")

# Pick a random composer or work
surprise = svc.random_composer()
surprise_work = svc.random_work(196)

API Reference

OpenOpus(cache=None)

Main service class. Accepts an optional cache instance (defaults to an in-memory TTLCache with a 1-hour TTL).

Composer methods

Method Description
composers() Return all composers
composer(composer_id) Return a single Composer by ID
composers_by_name(name) Partial-match search by name
composers_by_period(period) Filter by classical period
random_composer() Return a randomly selected composer
periods() Return the set of valid period strings

Work methods

Method Description
works(composer_id, genre="all") Return works by a composer, optionally filtered by genre
work_detail(work_id) Return detailed info for a single work
random_work(composer_id) Return a randomly selected work by a composer

Models

Composer

Field Type Description
id int Unique composer ID
name str Full name
birth str | None Birth year/date
death str | None Death year/date
epoch str Musical period
portrait str | None Portrait image URL

Work

Field Type Description
id int Unique work ID
title str Work title
genre str Genre (e.g. "Keyboard", "Orchestral")
subtitle str | None Subtitle or nickname

Caching

All responses are cached automatically. The default cache is TTLCache(ttl_seconds=3600). You can supply your own compatible object (anything with get(key) and set(key, value) methods), or use the built-in cache control methods:

from openopus.cache import TTLCache

cache = TTLCache(3600)
svc = OpenOpus(cache=cache)

# Remove a single entry
cache.invalidate("composers")

# Wipe everything
cache.clear()

Error Handling

Exception When raised
openopus.errors.OpenOpusError Non-200 HTTP response from the API, or invalid argument (e.g. unknown period)
openopus.errors.UpstreamUnavailable Network timeout or connection failure
from openopus.errors import OpenOpusError, UpstreamUnavailable

try:
    works = svc.works(196)
except UpstreamUnavailable:
    print("API unreachable, try again later")
except OpenOpusError as e:
    print(f"API error: {e}")

Development

# Install dependencies
pip install -e ".[dev]"

# Run tests
pytest

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

openopus-0.0.4.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

openopus-0.0.4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file openopus-0.0.4.tar.gz.

File metadata

  • Download URL: openopus-0.0.4.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openopus-0.0.4.tar.gz
Algorithm Hash digest
SHA256 aa6e82f4fcada5c5c4fa6c01660ccf05b84be89c4e4c1073a68c159c836d5307
MD5 a93d88b0aa6e0a728a2f71e92deea82f
BLAKE2b-256 6776a6e06547e82aba68cb35f3d397f8485ce882db578283edc36d8568243cc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for openopus-0.0.4.tar.gz:

Publisher: python-package.yml on boonjo/Open-Opus-Service

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

File details

Details for the file openopus-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: openopus-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openopus-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 57217463bfeb35a7859fd8b1b0d54cb581e426bc8149e5ab4a17d4b3bed91b8c
MD5 e7a2a5be9de059f8bf478df58bd794bd
BLAKE2b-256 8e6bbbb42fbd2191068987e8e8137da5e32dacaa8e05c0c47598cc2c5def6420

See more details on using hashes here.

Provenance

The following attestation bundles were made for openopus-0.0.4-py3-none-any.whl:

Publisher: python-package.yml on boonjo/Open-Opus-Service

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