Welcome to TMDB API Library
TMDB API Python Library: A comprehensive Python library for interacting with TheMovieDB API, enabling easy access to movie and TV show data, including details, ratings, and more. Simplify your movie-related projects with this powerful Python tool.
- TMDB API Getting Started
- Information about TMDB API: Include meta data about the TMDB API and methods, request format.
- Contribution Bible - TMDB
Features
- Supports both TMDB API version 3 and 4, including all methods.
- Provide all parameters in TMDB API methods.
- Includes parameter checking for methods.
- Offers credential management.
Installation
-
Install from PyPI
pip install TMDB-Py
-
Download the latest release from Release v1.1.1
pip install TMDB-Py-1.1.1.tar.gz
Getting Started
-
Set your credentials
The simplest way is to provide an API key. An API key authorizes access to TMDB API version 3. If an access token is given, it allows access to both version 3 and version 4.
import tmdbapi cred = tmdbapi.Credential() # Initialize a credential management object cred.set(api_key="your_api_key") # Set the API key tmdbapi.setting.use_cred(cred) # Load the credential
-
Now, You can now access API version 3 easily:
from tmdbapi import api3, pprint response = api3.movies.details(155) # Send the request pprint(response) # Pretty print the response
-
To access both version 3 and 4, you need to set access_token.
cred.set(access_token="your_access_token", account_object_id="your_account_object_id") response = tmdbapi.api4.account.favorite_movies() # Get a list of your favorite movies. pprint(response)
Contributing
Thank you for considering contributing to the TMDB API Library! Your contributions are highly valued and can help make this project even more powerful.
Ways to Contribute
1. Reporting Issues
If you discover any bugs, issues, or have suggestions for improvements, please open an issue. When reporting issues, be sure to provide detailed information about the problem, including steps to reproduce it.
2. Adding Tests
Robust test coverage is crucial for maintaining a stable project. You can contribute by adding more test cases to ensure that the code behaves correctly in various scenarios. We use pytest for testing.
3. Implementing High-Level Functions
If you have ideas for high-level functions that can improve the library's usability or provide new features, feel free to implement them and create a pull request.
4. Adding Features and Enhancements
Contributions that introduce new features or enhance existing ones are always welcome.
Tutorial
-
Credential Management
The credential management provides methods to save and load credentials from files and manage credentials in system environment variables.
-
Set the credential
import tmdbapi cred = tmdbapi.Credential() # Initialize credential management object # You can also provide multiple pieces of information at once cred.set(api_key="your_api_key", access_token="your_access_token", session_id="your_access_token",)
All available information:
access_token, api_key, session_id, account_id, account_object_id -
Save credentials to a file:
# Choose one option: cred.save("path/to/file") # For unencrypted storage cred.save_encrypt("path/to/file") # For encrypted storage
-
With this file, next time you can load credentials from this file:
cred = tmdbapi.Credential() # Create a new credential object cred.load("path/to/file") # Load the credential file (unencrypted) cred.load_encrypt("path/to/file") # Load the encrypted credential file
-
In some case you would like to put and get this credential information on environment variable:
cred.cred.cred_to_env() # put on environment variables cred.load_env_var() # load from environment variables
-
-
Settings
-
Load the credential:
After setting up the credential object, TMDB API still needs to be aware of your credentials. You must add them to the settings:
tmdbapi.setting.use_cred(cred) # Inform TMDB API that you are using these credentials
-
Choose what you want to use for authorization when sending a request:
# If access token was given you can set use_access_token to True tmdbapi.setting.use_access_token(True)
-
Set the request timeout:
tmdbapi.setting.timeout(5) # Set a timeout to 5 seconds
-
Set the default language:
When you request method have language parameter and no language given, it will use the default language to the parameter.
tmdbapi.setting.language('en-US') # Set the default language to 'en-US'
-
Set the default region (works similarly to default language):
tmdbapi.setting.region('US') # Set the default region to 'US'
-
Choose whether to use cookies or not:
More information: requests.Session
tmdbapi.setting.use_session(True) # Use requests.Session() tmdbapi.setting.use_session(False) # Send requests without cookies
-
Enable or disable the logging:
tmdbapi.setting.log('directory/to/save/the/log') # Enable the log file output tmdbapi.setting.log(None) # Disable the log file output (Default)
To change the log level:
import logging tmdbapi.LOGGER.setLevel(logging.INFO) # Change the log level to INFO
-
-
API Library
-
tmdbapi.api3
TMDB API version 3 methods and endpoints. Import the
api3sub-package to access the modules. Each module contains a category of methods, and each function in the module is an API method, with categories matching those of the TMDB API.from tmdbapi import api3 api3.catalog_name.method_name()
-
tmdbapi.api4
TMDB API version 4 methods and endpoints, structured and used in the same way as
api3.from tmdbapi import api4 api4.catalog_name.method_name()
-
tmdbapi.integration
This section provides high-level functions and integration features to simplify interactions with TMDB.
# Example from tmdbapi.integration import auth auth.create_access_token()
-
Known Issues
Issue: Error when Using api3.lists.delete
When using the api3.lists.delete request to delete a list on TheMovieDB, you may encounter the following error response:
response 500 - Internal Server Error
response json:
{
"success": false,
"status_code": 11,
"status_message": "Internal error: Something went wrong, contact TMDb."
}
The error is at TMDB API, please use api4 instead, or you may need to catch the exception. Issue on TMDB support
Unit Test
Run unit test:
python run_test.py
Metadata
Release files for TMDB-Py 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| TMDB-Py-1.1.1.tar.gz | 47.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| TMDB_Py-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 126.6 kB
Release files / TMDB-Py-1.1.1.tar.gz
| Download URL | TMDB-Py-1.1.1.tar.gz |
|---|---|
| Size | 47.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5d6fbc7d115a2fa90e08f8f816dca64d2de89dffe886e5a9bb252025f3aafee
|
|
BLAKE2b-256 checksum How to use checksums |
db064c21d8a59e0ac6356ff97fbbaad3fa9cf0d0d9f5952659210615ed3204cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / TMDB_Py-1.1.1-py3-none-any.whl
| Download URL | TMDB_Py-1.1.1-py3-none-any.whl |
|---|---|
| Size | 78.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
297d608e1654615af190b00c959ee49ffab1854b7c351d7db00f35c857c350be
|
|
BLAKE2b-256 checksum How to use checksums |
4fe7035b8ef6d1b72f6026c0b39c576dd390b175d2755f47319db6d94be2fd0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|