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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa6e82f4fcada5c5c4fa6c01660ccf05b84be89c4e4c1073a68c159c836d5307
|
|
| MD5 |
a93d88b0aa6e0a728a2f71e92deea82f
|
|
| BLAKE2b-256 |
6776a6e06547e82aba68cb35f3d397f8485ce882db578283edc36d8568243cc6
|
Provenance
The following attestation bundles were made for openopus-0.0.4.tar.gz:
Publisher:
python-package.yml on boonjo/Open-Opus-Service
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openopus-0.0.4.tar.gz -
Subject digest:
aa6e82f4fcada5c5c4fa6c01660ccf05b84be89c4e4c1073a68c159c836d5307 - Sigstore transparency entry: 1512665547
- Sigstore integration time:
-
Permalink:
boonjo/Open-Opus-Service@b8ada4a99673e4660a3afc47f406ddbdbd87c6d1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/boonjo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@b8ada4a99673e4660a3afc47f406ddbdbd87c6d1 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57217463bfeb35a7859fd8b1b0d54cb581e426bc8149e5ab4a17d4b3bed91b8c
|
|
| MD5 |
e7a2a5be9de059f8bf478df58bd794bd
|
|
| BLAKE2b-256 |
8e6bbbb42fbd2191068987e8e8137da5e32dacaa8e05c0c47598cc2c5def6420
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openopus-0.0.4-py3-none-any.whl -
Subject digest:
57217463bfeb35a7859fd8b1b0d54cb581e426bc8149e5ab4a17d4b3bed91b8c - Sigstore transparency entry: 1512665796
- Sigstore integration time:
-
Permalink:
boonjo/Open-Opus-Service@b8ada4a99673e4660a3afc47f406ddbdbd87c6d1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/boonjo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@b8ada4a99673e4660a3afc47f406ddbdbd87c6d1 -
Trigger Event:
workflow_dispatch
-
Statement type: