A Python SDK package for using The One API
The package can be found on PyPi here: https://pypi.org/project/lotrsdkbybnelson0/1.0.0/ and can be install using pip like this:
pip install lotrsdkbybnelson0-
Get an
api-keyfrom The One Ring. -
Set the
api-keyas an environment variable. There are lots of ways to do this in Python. I recommend using python-dotenv. See that documenation for additional info. The following steps will reference this method. -
Create a .env file in the root of your project directory. The contents will look like this:
# .env file
lotrsdk-api-key = "YOUR_KEY_HERE"
- Import the
lotrsdkobjects (packages) into your project.
from lotrsdk import Movie, Quote- In your python project, using
dotenv, load the.envfile which contains the key
from dotenv import load_dotenv
load_dotenv()- (Optional) You can validate the api-key loaded with the following
import os
print(os.environ.get('lotrsdk-api-key'))# Returns a Movie object
movie = Movie.get_by_id('5cd95395de30eff6ebccde5b')
print(movie) # This is an object, but has a string representation
# Returns a Collection object of Movies
movies = Movie.get_all()
print(movies) # This is an object, but has a string representation
print(movies.total)
print(movies.entities[0])
# Returns a Quote object
quote = Quote.get_by_id('5cd96e05de30eff6ebcce834')
print(quote) # This is an object, but has a string representation
# Returns a Collection object of Quotes
quotes = Quote.get_all()
print(quotes) # This is an object, but has a string representation
print(quotes.total)
print(quotes.entities[0])
# Returns a Collection object of Quotes by movie id
# Paging and additional parameters can be passed
movie_quotes = Movie.get_quotes('5cd95395de30eff6ebccde5b', {'page': 2})
print(movie_quotes) # This is an object, but has a string representation
print(movie_quotes.total)
print(movie_quotes.entities[0])This package uses the unittest python package which is standard
$ python -m unittest