Skip to main content

Create your OPDS catalog with Python

Project description

OPDS python library

PyPI - Downloads PyPI - Version PyPI - Python Version PyPI - License Pipeline

This package allows you to easily compose an OPDS version 1.2 catalog.

No reason to touch any xml yourself, everything is wrapped in semantic Python classes.

Installation

Install from PyPI

pip install opds

If you prefer to use lxml over the stdlib xml for parsing, use the 'lxml' extra

pip install opds[lxml]

Usage

First of all check out the the official OPDS catalog spec documentation.

It has a lot of useful and instructive examples that will help you understand what to add to your catalog.

A single OPDS catalog file is represented by the OPDSCatalog class

opds_catalog = opds.OPDSCatalog(title="Example")

The catalog comes with all required metadata configured by initialization. It is stored in the metadata member, you can use all methods of the list container to add more.

For example

summary = opds.Metadata(name="summary", value="An example OPDS catalog")
opds_catalog.metadata.append(summary)

Every catalog comes with 3 default namespaces: Atom (default), DublinCore (dc) and OPDS (opds). Add more by adding them to the attributes of the OPDSCatalog. You typically won't need to.

As special type of metadata one typically wants to add links for navigation to other catalogs of the same server. For quality of life there are Link subclasses for the most common link types.

other_catalog_link = opds.AcquisitionFeedLink(href="/other-catalog", rel=Link.Rel.SUBSECTION)
self_link = opds.NavigationFeedLink(href="/this-url", role=Link.Rel.SELF)
start_link = opds.NavigationFeedLink(href="/root-url", role=Link.Rel.START)
opds_catalog.links.extend([ other_catalog_link, self_link, start_link ])

The difference between navigation and acquisition feeds is explained in the OPDS spec.

After all metadata is defined, we add the entries to the catalog.

entry_1 = opds.Entry(title="Book 1", uid="book_1")
opds_catalog.entries.append(summary)

Entries hold metadata and links just like the catalog. Adding and manipulating them is completely analogous.

After everything is set up, write the catalog to xml bytes

opds_bytes = opds_catalog.write()

Done.

Disclaimer

There was no AI used in creating this package. Every single line was typed by human hand.

The source code was originally created for the Cata-Log project and later externalized for use across other projects.

License

This software is proudly released under the GNU Affero General Public License v3.0 or later (AGPLv3) open-source license.

Any contributions will be subject to the same licensing.

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

opds-0.1.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

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

opds-0.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: opds-0.1.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.13 Linux/5.15.154+

File hashes

Hashes for opds-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fc13daafe8cd03ffca2d286b44a584e25891499fe06a42d2bec0df55697cde12
MD5 683a3bd358826ef648b0efa42c7d876e
BLAKE2b-256 16b193f705aeb04992312ec938579bd0e18e7865a1fa101e4351c3fc495bbc9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: opds-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.13 Linux/5.15.154+

File hashes

Hashes for opds-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 978477df2e272309e9e77afed1c304dbded1278c1b9137afc38d0b3f6a79152e
MD5 53404e917685c065a47cbdb3c9b426d3
BLAKE2b-256 45f4e17a66e5913bf438b716da734c7a76adaffba65cec9091dbae584ad831fb

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