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('asdasjdkhasdjlkasdj').libraries

# works also with the user name
jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).user.of('niels').libraries

# don't be afraid, go crazy
jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).user.of('niels').id

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)

Let's get the User ID by name or ID

The id is a UUID to get the str just use the attribute hex

uuid = jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).user.by_name('niels').id.hex

jellyfin.api(os.getenv("JELLYFIN_URL"), os.getenv("JELLYFIN_API_KEY")).user.by_id(uuid).name

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.3.tar.gz (780.8 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.3-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jellyfin_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4ad82fc6233d41c9abb2695a8cff5e01f19f70706de6cb7222b0c989b860d80a
MD5 55b11731b8f4f28cf5aa31b483619585
BLAKE2b-256 76925eb4e0b6234222288e483ef324c47c4e33188f7bf99a8e78dc0841925ce1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jellyfin_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3c5333bda7fadb618183d72dcf42ba885522cc9224ef4533c22e349fa097f80b
MD5 52213a25c0d60b73abbb9d483181256c
BLAKE2b-256 cfff8de5548822de18e06335e9945227eb34162c32ce919a32bc7d057b35095e

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