Skip to main content

BachtrackAPI

A Python web scraper and REST API for extracting classical music opera events from Bachtrack.com.

Overview

BachtrackAPI provides two complementary ways to access opera event data:

  1. Scraper Module - Direct web scraping of Bachtrack opera listings
  2. FastAPI Backend - RESTful API endpoints for searching and filtering events

Search by work ID (e.g., 12285 for Gianni Schicchi) or freetext (e.g., "La Traviata").

Installation

pip install -r requirements.txt

Quick Start

1. Using the Scraper Directly

from bachtrackapi.scraper import BachtrackScraper

scraper = BachtrackScraper()

# Search by work ID
events = scraper.search_operas(12285)  # Gianni Schicchi
print(f"Found {len(events)} events")

# Search by freetext
events = scraper.search_operas("La Traviata")
for event in events:
    print(f"{event['title']} - {event['city']} @ {event['venue']}")

Output:

Found 28 events
Gianni Schicchi - Berlin @ Deutsche Oper
Gianni Schicchi - Winterthur @ Stadttheater Winterthur
...

2. Using the FastAPI Backend

Start the server:

uvicorn bachtrackapi.backend.main:app --reload

Example API Requests:

# Freetext search
curl "http://localhost:8000/api/v1/events/get_operas?q=gianni%20schicchi"

# Work ID search
curl "http://localhost:8000/api/v1/events/get_operas?q=12285"

# POST search
curl -X POST "http://localhost:8000/api/v1/events/search" \
  -H "Content-Type: application/json" \
  -d '{"work_id": 12285}'

Response:

{
  "query": "12285",
  "total_results": 28,
  "results": [
    {
      "title": "Gianni Schicchi",
      "city": "Berlin",
      "date": "2026-04-05T00:00:00",
      "venue": "Deutsche Oper",
      "detail_url": "https://bachtrack.com/opera-event/..."
    }
  ]
}

Available Endpoints

  • GET /api/v1/events/get_operas?q=<search> - Raw scraper output
  • GET /api/v1/events/search?work_id=<id> - Search by work ID
  • GET /api/v1/events/search?q=<term> - Freetext search
  • POST /api/v1/events/search - JSON body search
  • GET /docs - Interactive API documentation
  • GET /health - Health check

Testing

# Run scraper tests
python tests/test_scraper.py

# Run full API integration tests
pytest tests/test_api.py -v -s

Project Structure

bachtrackapi/
  ├── scraper/
  │   └── scraper.py           # Core scraping logic
  └── backend/
      ├── main.py                    # FastAPI app factory
      ├── routes/events.py           # API endpoints
      ├── models/event.py            # Pydantic models
      └── services/opera_service.py  # Service layer
tests/                           # Unit and integration tests

License

MIT License - see LICENSE file for details

Metadata

Release files for bachtrackapi 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bachtrackapi 0.1.3
File Size Uploaded Provenance
bachtrackapi-0.1.3.tar.gz 11.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bachtrackapi 0.1.3
File Interpreter ABI Platform
bachtrackapi-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.8 kB

Release files / bachtrackapi-0.1.3.tar.gz

Download URL bachtrackapi-0.1.3.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
92fd4e96d72230c06212a8b8c490a32b58ab350c81cb11fb2f99cf7988bf0d94
BLAKE2b-256 checksum
How to use checksums
3217ba68f0748a2b1aac13a14962a86462ac93440c2f8b3c9b454df231f26cff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Release files / bachtrackapi-0.1.3-py3-none-any.whl

Download URL bachtrackapi-0.1.3-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0fdde2dc1eae74f7fb57d52b32b1df214aced4ea99a94a88eb293f9eee6cd45
BLAKE2b-256 checksum
How to use checksums
3a4f5fbb6c10325f09b991bb38765addcd0b29f9cf074140f04efde3a353982e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Security for bachtrackapi 0.1.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page