Skip to content

Commit

Permalink
docs: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
leandcesar committed Mar 21, 2023
1 parent f6e33af commit 9f5c1e0
Showing 1 changed file with 73 additions and 52 deletions.
125 changes: 73 additions & 52 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
themoviedb
==========

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

- `Overview <#overview>`__
- `Getting started <#getting-started>`__
- `Configuration <#configuration>`__

--------------
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 an asynchronous wrapper, written in Python, for The
Movie Database (TMDb) API v3.
The **themoviedb** is a synchronous and asynchronous wrapper, written in Python,
for The Movie Database (TMDb) API v3.

`The Movie Database (TMDb) <https://www.themoviedb.org>`__ is a
community built movie and TV database.
Expand Down Expand Up @@ -62,80 +57,106 @@ obtain a key, follow these steps:
Usage
-----

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

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

import asyncio
from themoviedb import TMDb
.. code:: python
async def main():
tmdb = TMDb(key="YOUR_API_KEY")
movies = await tmdb.search().movies("fight club")
for movie in movies:
print(movie)
tmdb = TMDb(key="YOUR_API_KEY", language="pt-BR", region="BR")
asyncio.run(main())
Alternatively, set after initialize.

.. code:: python
Alternatively, you can export your API key as an environment variable.
tmdb = TMDb()
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.

.. code:: bash
$ 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.

And then you will no longer need to set your API key.
.. code:: python
tmdb = TMDb() # implicit env var: TMDB_KEY="YOUR_API_KEY"
# TMDB_LANGUAGE="pt-BR"
# TMDB_REGION="BR"
Examples
~~~~~~~~

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

.. code:: py
import asyncio
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).

.. code:: py
import asyncio
from themoviedb import aioTMDb
async def main():
# implicit env var: TMDB_KEY="YOUR_API_KEY"
tmdb = TMDb()
movies = await tmdb.movies().now_playing()
tmdb = aioTMDb()
movies = await tmdb.tvs().popular()
for movie in movies:
print(movie)
asyncio.run(main())
Configuration
=============

Initialize a TMDb object and set your API Key, language and region.
Discover movies by different types of data.

.. code:: py
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.

.. code:: bash
from themoviedb import TMDb
$ export TMDB_KEY="YOUR_API_KEY"
$ export TMDB_LANGUAGE="pt-BR" # ISO 639-1
$ export TMDB_REGION="BR" # ISO-3166-1
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)
And then you will no longer need to set your API key, language and region.
Get the details of movie for a search.

.. code:: py
# 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.
import asyncio
from themoviedb import aioTMDb
.. code:: py
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)
# implicit env vars: TMDB_KEY="YOUR_API_KEY" TMDB_LANGUAGE="pt-BR" TMDB_REGION="BR"
tmdb = TMDb(key="ANOTHER_API_KEY", language="en-US", region="US")
tvs = await tmdb.tvs().popular() # with en-US / US
asyncio.run(main())
.. |Code Quality Score| image:: https://api.codiga.io/project/36067/score/svg
:target: https://app.codiga.io/hub/project/36067/themoviedb
Expand Down

0 comments on commit 9f5c1e0

Please sign in to comment.