Skip to main content

A modern and easy to use API wrapper for The Movie Database (TMDb) API v3 written in Python

Project description

PyPI Version PyPI License Code style: black

themoviedb

A modern and easy to use API wrapper for The Movie Database (TMDb) API v3 written in Python.


Overview

The themoviedb is an asynchronous wrapper, written in Python, for The Movie Database (TMDb) API v3.

The Movie Database (TMDb) is a community built movie and TV database.

The TMDb API service is for those of you interested in using our movie, TV show or actor images and/or data in your application.

A TMDb user account is required to request an API key.

Getting started

Requirements

  • python (Python >=3.7)

  • pip (Python package manager)

Install

The easiest way to install themoviedb is via pip.

pip install themoviedb

API Key

You will need an API key to The Movie Database to access the API. To obtain a key, follow these steps:

  1. Register for and verify an account.

  2. Log into your account.

  3. Select the API section on left side of your account page.

  4. Click on the link to generate a new API key and follow the instructions.

Usage

The first step is to initialize a TMDb object and set your API Key.

import asyncio
from themoviedb import TMDb

async def main():
    tmdb = TMDb()
    tmdb.key = "YOUR_API_KEY"

    movies = await tmdb.search().movies("fight club")
    for movie in movies:
        print(movie)

asyncio.run(main())6

Alternatively, you can export your API key as an environment variable.

$ export TMDB_KEY="YOUR_API_KEY"

And then you will no longer need to set your API key.

import asyncio
from themoviedb import TMDb

async def main():
    # implicit env var: TMDB_KEY="YOUR_API_KEY"
    movies = await tmdb.movies().now_playing()
    for movie in movies:
        print(movie)

asyncio.run(main())

Configuration

Initialize a TMDb object and set your API Key, language and region.

tmdb = TMDb()
tmdb.key = "YOUR_API_KEY"
tmdb.language = "pt-BR"
tmdb.region = "BR"
tvs = await tmdb.tvs().on_the_air()

Alternatively, you can export your API key, language and region logger as an environment variable.

$ export TMDB_KEY="YOUR_API_KEY"
$ export TMDB_LANGUAGE="pt-BR"  # ISO 639-1
$ export TMDB_REGION="BR"  # ISO-3166-1

And then you will no longer need to set your API key, language and region.

# implicit env vars: TMDB_KEY="YOUR_API_KEY" TMDB_LANGUAGE="pt-BR" TMDB_REGION="BR"
tmdb = TMDb()
people = await tmdb.people().popular()

You also can set language and region on object instantiation.

# implicit env vars: TMDB_KEY="YOUR_API_KEY" TMDB_LANGUAGE="pt-BR" TMDB_REGION="BR"
tmdb = TMDb(key="ANOTHER_API_KEY")
tvs = await tmdb.tvs(language="en-US", region="US").popular()  # with en-US / US
tvs = await tmdb.tvs().popular()  # with pt-BR / BR

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

themoviedb-0.2.0b0.tar.gz (18.3 kB view hashes)

Uploaded Source

Built Distribution

themoviedb-0.2.0b0-py3-none-any.whl (34.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page