Skip to main content

A Possible Official Python SDK for Jellyfin.

Project description

jellyfin-sdk-python


Logo Banner

A Possible Official Python SDK for Jellyfin.

Warning: This project is under active development, so API changes may occur.

This project is mainly inspired by good python library like these:

Main unique features:

  • Enables targeting a specific Jellyfin server version to ensure compatibility and prevent breaking changes.
  • Supports accessing multiple servers, each potentially running different Jellyfin versions.
  • Allows reducing the level of abstraction to access advanced or unavailable options through lower-level interfaces.
  • Works like AWS CDK Constructs Level, more abstraction, more simple.

Install

pip install jellyfin-sdk

or

uv add jellyfin-sdk

Usage

Drop-in replacement for jellyfin-apiclient-python

This library includes the old legacy client (which is almost unmaintained) to help with migration:

pip uninstall jellyfin-apiclient-python
pip install jellyfin-sdk
# change from
from jellyfin_apiclient_python import JellyfinClient
from jellyfin_apiclient_python.api import API

# to this
from jellyfin.legacy import JellyfinClient
from jellyfin.legacy.api import API

Login

To get started with login, in most cases you only need to do something simple:

import os

os.environ["JELLYFIN_URL"] = "https://jellyfin.example.com"
os.environ["JELLYFIN_API_KEY"] = "MY_TOKEN"

Lean optimized access

import jellyfin

api = jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY"))

print(api.system.info.version, api.system.info.server_name)

Generated Binding with OpenAPI Specification

from jellyfin.generated.api_10_10 import Configuration, ApiClient, SystemApi

client = ApiClient(
    Configuration(host = os.getenv("JELLYFIN_URL")), 
    header_name='X-Emby-Token', 
    header_value=os.getenv("JELLYFIN_API_KEY")
)
system_info = SystemApi(client).get_system_info()

print(system_info.version, system_info.server_name)

Legacy (jellyfin-apiclient-python)

from jellyfin.legacy import JellyfinClient
client = JellyfinClient()
client.authenticate(
    {"Servers": [{
        "AccessToken": os.getenv("JELLYFIN_API_KEY"), 
        "address": os.getenv("JELLYFIN_URL")
    }]}, 
    discover=False
)
system_info = client.jellyfin.get_system_info()

print(system_info.get("Version"), system_info.get("ServerName"))

Jellyfin Server API Version

This is important because when a new API version is released, breaking changes can affect the entire project. To avoid this, you can set an API target version, similar to how it's done in Android development:

from jellyfin.api import Version
import jellyfin

# this will use the default which is the lastest stable
jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY"))

# now let's test the new API (version 10.11) for breaking changes in same endpoint
jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY"), Version.V10_11)

# but keep simple
jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY"), '10.11')

# let's test a wrong version
jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY"), '99')

List all libraries of an user

When using API_KEY some endpoints need the user_id (don't me ask why!), almost all issues with jellyfin is around this. To help to identify this not-so-much-edge-cases we raise a exception to help with that:

jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).user.libraries

>>> jellyfin.api('https://video.webysther.org', 'f674245b80ea4a3ea9c011e01ce73ef9').user.libraries
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/code/jellyfin-sdk-python/src/jellyfin/user.py", line 16, in libraries
    return self.views
  File "/code/jellyfin-sdk-python/src/jellyfin/user.py", line 21, in views
    raise ValueError("User ID is not set. Use the 'of(user_id)' method to set the user context.")
ValueError: User ID is not set. Use the 'of(user_id)' method to set the user context.


jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).user.of('asdasjdkhasdjlkasdjalsdjklasjdk').libraries

List all items

Item can be any object in the server, in fact that's how works, one huge table recursive linked.

jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).items.all

We still don't give you the automatic pagination with a Iterator, for this cases use the filter. In this example will be returned 10k items. For slice the pagination use start_index.

jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).items.filter(limit=10000)

Supported Jellyfin Versions

SDK Version Jellyfin API Target
0.1.x 10.10.x-10.11.x

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

jellyfin_sdk-0.1.2.tar.gz (780.2 kB view details)

Uploaded Source

Built Distribution

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

jellyfin_sdk-0.1.2-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file jellyfin_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: jellyfin_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 780.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.13

File hashes

Hashes for jellyfin_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 93ae13678f46d18cfc7adff092812eeddd03691f355a0efff1e44f51b4e19e68
MD5 48f213b765d2eb995779ffe8b1979f57
BLAKE2b-256 9f5a78b3000a9b0bfcf1ec99ead3b317b471ebfc7263e48de072d7fef8be0eed

See more details on using hashes here.

File details

Details for the file jellyfin_sdk-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for jellyfin_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 97044ed569bab01664d972451df014dbe1680c765568cbdaaf2ece56534ce8c1
MD5 b11f910f55128249da603aee39780314
BLAKE2b-256 d6abd3b1a433e87f5812d94674e5316ecc7a36ca7ba7a62f61550d9c607ab329

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