Connecting Jellyfin Backend with a Python Backend
Published: 2023-09-27 06:10:32

##Intro

 Setting up a connection between these two backend servers was a very tedious process to figure out if you are not familiar with the documentation already so I will breakdown a simple method to set up a connection.

##Jellyfin Setup
To start you should begin by installing the Jellyfin server onto your computer. You can follow the link here to get to the Jellyfin download page. [](https://jellyfin.org/downloads/windows) 

![Jellyfin Download Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/var2p8o6xhiic4nhgjxl.png)

After getting your OS specific version of Jellyfin you will follow the setup & installation steps. After it has completed installation you can run it from the Jellyfin application located in your tray unless you are going directly to your Jellyfin server address. The default endpoint will be **8096**. 


![Jellyfin On Your Windows Tray](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tda7d6ah0rpwwt2cpw2k.png)


You will be greeted by the signup page. If you already have done the initial signup Jellyfin you will instead be greeted by the Jellyfin signin page.


![Jellyfin Sign In](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jbtgt98z1fzyhbosign.png)

## Setting Up The API

After you have signed into your server you will now be able to use the regular Jellyfin functionality such as adding media files to your server for access on a client. 

To get access to your API you will need to press on the three bars located on the top left of your webpage than from the navigation panel that dropped down, click on "Administrator Dashboard".


![Homepage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z06cebtdjro095gq8eq9.png)



![Homepage plus Nav](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7g3c9pl0t72mfeau6ls.png)

In the Administrator Dashboard navigate the left side of your webpage until you find "API Key" within the "Advanced Settings" section. From there you simply need to press the big plus sign in the top left. You will then be prompted to input an application title so you better organize your keys. After entering the title your API Key will be generated. Copy the API key for later use.


![API Key page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/487bnvd2il505d0wgbm8.png)

I'm going to be going under the assumption that you already have you Python server setup and now just need to connect your API Key

## Connect to Python

As a good method as always keep your API Keys in a ".env" file within a ".gitignore" folder so you do not give the public access to your API Keys.



![.env file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4l24lfy1ocwlwmhzng3.png)

This next part is very important to follow. 

Set your URL for your fetch request in the following format. (In the example it is for the User endpoint. Look at the following documentation on the Jellyfin API for other endpoints. [](https://api.jellyfin.org/))

```
any_variable = "http://{server_address}:8096/Users?{api_key}
headers = {
        "Accept": "application/json",
        "Authorization": "MediaBrowser Token={api_key}"

        }
//"MediaBrowser" and "Token=" are mandatory in formatting of Authorization

```
Take a look below of this method being utilized in the following GET request.



![GET request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9mtw2ccui2niz1ynget.png)

For the flask-restful setup I used in my code I added the following line of code to make my GET request accessible.

`api.add_resource(Users, '/users')` 

There is further setup to use flask-restful, if you want to emulate my method, reference the following documentation [](https://readthedocs.org/projects/flask-restful/downloads/pdf/latest/)

As long as you have your Python server and Jellyfin server running you can now access your Jellyfin API in Python. 

I'm going to use Postman to display the API being fetched successfully. 

If you followed the setup correctly you should receive a 200 response code with the following information populate from your GET request.


![Postman preview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1j0c4gt8c8jjzjsx1lkq.png)

## Conclusion

Using a Python backend with a Jellyfin server is not mandatory, the API can be accessed directly from your frontend client. There are some benefits to using the dual server method. Python allows for easy API modification aswell as simple database management of your Jellyfin server. Actions such as adding media files can be done via your Python server through POST requests, as well as deleting files from your server via DELETE requests. The main benefit comes from the user information access. The jellyfin server allows administrators to see basic user information but the GET request allows you to see more detailed information such as the current password for each user, making a good alternative to having to reset your user's password each time they forget. Utitlizing the Python database allows for specified metadata to be organized and managed. Having the filtered metadata makes translating it to your frontend a breeze. 

TLDR: A Python server is not mandatory to access a Jellyfin server but using the two jointly allows for additional benefits from both servers, and adds simple access to the Jellyfin API  for your frontend.