Giter Club home page Giter Club logo

themoviedb's Introduction

Code Quality Score Code Grade Code Coverage PyPI Version Code style: black PyPI License

themoviedb

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

Overview

The themoviedb is a synchronous and 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.8)
  • 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

Sync mode

from themoviedb import TMDb

Async mode

from themoviedb import aioTMDb

Configuration

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

tmdb = TMDb(key="YOUR_API_KEY", language="pt-BR", region="BR")
# or: tmdb = aioTMDb(key="YOUR_API_KEY", language="pt-BR", region="BR")

Alternatively, set after initialize.

tmdb = TMDb()
# or: tmdb = aioTMDb()
tmdb.key = "YOUR_API_KEY"
tmdb.language = "pt-BR"     # default: en-US
tmdb.region = "BR"          # default: US

Alternatively too, 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.

tmdb = TMDb()   # from env: TMDB_KEY="YOUR_API_KEY", TMDB_LANGUAGE="pt-BR", TMDB_REGION="BR"
# or: tmdb = aioTMDb()

Examples

Get the list of top rated movies (sync mode).

from themoviedb import TMDb

tmdb = TMDb()
movies = tmdb.movies().top_rated()
for movie in movies:
    print(movie)

Get the list of popular TV shows (async mode).

import asyncio
from themoviedb import aioTMDb

async def main():
    tmdb = aioTMDb()
    movies = await tmdb.tvs().popular()
    for movie in movies:
        print(movie)

asyncio.run(main())

Discover movies by different types of data.

from themoviedb import TMDb

tmdb = TMDb()
movies = tmdb.discover().movie(
    sort_by="vote_average.desc",
    primary_release_date__gte="1997-08-15",
    vote_count__gte=10000,
    vote_average__gte=6.0,
)
for movie in movies:
    print(movie)

Get the details of movie for a search.

import asyncio
from themoviedb import aioTMDb

async def main():
    tmdb = aioTMDb()
    movies = await tmdb.search().movies("fight club")
    movie_id = movies[0].id  # get first result
    movie = await tmdb.movie(movie_id).details(append_to_response="credits,external_ids,images,videos")
    print(movie.title, movie.year)
    print(movie.tagline)
    print(movie.poster_url)
    print(movie.external_ids.imdb_url)
    for person in movie.credits.cast:
        print(person.name, person.character)

asyncio.run(main())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.