Skip to main content

RERO Invenio Thumbnails.

Project description

rero-invenio-thumbnails

CI GitHub tag PyPI downloads License Coveralls uv managed

RERO Invenio extension to discover book thumbnail URLs from multiple providers.

Features

  • Multiple Providers: Chainable providers query external services in order and return the first available thumbnail URL
  • Built-in Providers: FilesProvider (local files), OpenLibraryProvider, BnfProvider, DnbProvider, GoogleBooksProvider, GoogleApiProvider
  • Plugin Architecture: Extensible via entry points - register custom providers without modifying core code
  • Smart Caching: Redis-based caching with configurable TTL
  • Robust HTTP Handling: Configurable retry logic with exponential backoff for external providers
  • RESTful API: JSON endpoint for thumbnail URL retrieval

Custom Providers

You can register custom thumbnail providers via entry points. Create a provider that inherits from BaseProvider:

from rero_invenio_thumbnails.contrib.api import BaseProvider

class MyCustomProvider(BaseProvider):
    def get_thumbnail_url(self, isbn):
        # Your implementation here
        url = f"https://example.com/covers/{isbn}.jpg"
        return (url, "custom")

Register it in your pyproject.toml:

[project.entry-points."rero_invenio_thumbnails.providers"]
custom = "my_package.providers:MyCustomProvider"

Then reference it in your configuration:

RERO_INVENIO_THUMBNAILS_PROVIDERS = ["custom", "files", "open library"]

Quick start

Install:

pip install rero-invenio-thumbnails

Configure the providers and files dir in your application config:

# Provider configuration (optional - if not set, all discovered providers are used)
RERO_INVENIO_THUMBNAILS_PROVIDERS = ["files", "open library", "bnf", "dnb", "google books", "google api"]

# Files provider configuration
RERO_INVENIO_THUMBNAILS_FILES_DIR = "/path/to/thumbnails"

# Cache configuration
RERO_INVENIO_THUMBNAILS_CACHE_EXPIRE = 3600

# Retry config (defaults shown)
RERO_INVENIO_THUMBNAILS_RETRY_ENABLED = True
RERO_INVENIO_THUMBNAILS_RETRY_ATTEMPTS = 5
RERO_INVENIO_THUMBNAILS_RETRY_BACKOFF_MULTIPLIER = 0.5
RERO_INVENIO_THUMBNAILS_RETRY_BACKOFF_MIN = 1
RERO_INVENIO_THUMBNAILS_RETRY_BACKOFF_MAX = 10
# Disable retries globally via env (e.g., for tests)
# export RERO_THUMBNAILS_DISABLE_RETRIES=true

Initialize the extension:

from rero_invenio_thumbnails import REROInvenioThumbnails

ext = REROInvenioThumbnails()
ext.init_app(app)

API

Get a thumbnail URL for an ISBN:

from rero_invenio_thumbnails.api import get_thumbnail_url

# Returns a tuple: (url, provider_name)
url, provider = get_thumbnail_url("9780134685991")
print(f"Found thumbnail at {url} from {provider}")

HTTP Endpoints

GET /thumbnails-url/<isbn> - Returns JSON with thumbnail URL

Returns JSON containing the thumbnail URL and provider name if found, or 404 if no thumbnail is available:

{
    "url": "https://covers.openlibrary.org/b/isbn/9780134685991-L.jpg",
    "isbn": "9780134685991",
    "provider": "open library"
}

Example:

curl http://localhost/thumbnails-url/9780134685991

GET /thumbnails/<isbn> - Serves the actual thumbnail image file

Returns the thumbnail image file directly from local storage with appropriate MIME type (image/jpeg or image/png). Supports client-side caching with ETag and Last-Modified headers, along with conditional requests (If-None-Match, If-Modified-Since) returning 304 Not Modified when appropriate. Returns 404 if the file is not found.

Example:

# First request - returns 200 with ETag and Last-Modified headers
curl -v http://localhost/thumbnails/9780134685991 -o thumbnail.jpg

# Subsequent requests can use conditional headers for efficient caching
curl -H "If-None-Match: \"abc123...\"" http://localhost/thumbnails/9780134685991

Testing

Run the test-suite using the project's uv-based tooling:

uv sync
uv run poe run_tests

Contributing

Contributions are welcome. Please follow the repository CONTRIBUTING.md and open pull requests against the staging branch.

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

rero_invenio_thumbnails-0.1.0.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

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

rero_invenio_thumbnails-0.1.0-py3-none-any.whl (55.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rero_invenio_thumbnails-0.1.0.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rero_invenio_thumbnails-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63e11da4cad64b1180f7dded9c1bc5619f0f80a3c160ec1611ac99751ea097ba
MD5 100b2a229c15271ffa6507f6cec10316
BLAKE2b-256 a581b8b2d4ebb15662113517d37f7e14acaf8f8bf4aabb8f6b024781f21495e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rero_invenio_thumbnails-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 55.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rero_invenio_thumbnails-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d133be19210d83f9085d3f5d85a7a17b29048f7e10ee70139e31300e4d39387
MD5 987e9d9beae9f71711fad89c13d281e9
BLAKE2b-256 1ed3b9d40193448b910326eec17b7d6a3b20c88ef8d0eee147a548d1c4c9eee6

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