How wagnerrp/pytmdb3 works
1. Repository purpose
PyTMDB3 is a Python client library for TheMovieDb v3 API. It is not an application; it is a package that exposes a domain model for movies, TV series, people, studios, images, and related metadata.
2. Public package boundary
The tmdb3 package is the main API surface. tmdb3/__init__.py likely re-exports the common entry points described in the README, such as set_key, set_cache, set_locale, search helpers, and entity constructors like Movie, Person, and Studio.
3. API request flow
Calls from user code flow into tmdb3/tmdb_api.py and tmdb3/request.py. This is the core client boundary that turns high-level operations like search, direct lookup, or property access into TMDB HTTP requests.
4. Lazy-loaded domain objects
The library is object-centric: Movie, Person, Collection, Series, Season, Episode, and related types are exposed as properties and populate data on demand. That means object creation and data retrieval are separated; objects act as handles until a field is accessed.
5. Search and pagination subsystem
Search results are not returned as plain arrays. tmdb3/pager.py supports list-like result sets that fetch additional TMDB pages automatically as the caller iterates or indexes beyond the current page. This is the main mechanism for handling the API’s paged search endpoints.
6. Caching boundary
tmdb3/cache_engine.py, tmdb3/cache.py, tmdb3/cache_file.py, and tmdb3/cache_null.py form a pluggable cache layer. The request path consults this cache before hitting TMDB, with cache entries keyed by request URL. The default file-backed cache persists data locally; the null cache disables persistence for debugging.
7. Locale handling
tmdb3/locales.py centralizes locale state and locale objects. Locale affects how requests are formed and how localized fields are resolved across subsequent queries. The library supports a global default locale plus per-call overrides that propagate through related object fetches.
8. Authentication and API key management
tmdb3/tmdb_auth.py handles API key configuration and any future auth-related hooks. The README says authenticated user actions such as rating and watchlists are defined in the model, but full authentication support is not yet implemented.
9. Error and utility layer
tmdb3/tmdb_exceptions.py defines the package-specific exception types used across request, cache, and object access paths. tmdb3/util.py contains shared helpers used by the rest of the library, likely for parsing, normalization, and common conversions.
10. Data model breadth
The library models multiple TMDB entities and relationships: images (Backdrop, Poster, Profile, Logo), media relations (Cast, Crew, Genre, Release, Translation), and TV structures (Series, Season, Episode). These are not separate services; they are a unified object graph backed by the API.
11. Image and trailer handling
Images and trailers are represented as first-class objects with URL generation and size selection logic. This is an important architectural boundary because the library does not just fetch metadata; it also constructs download URLs for remote assets served by TMDB and related hosts.
12. Support scripts and packaging
scripts/populate_locale.py and scripts/pytmdb3.py are auxiliary tools rather than runtime components. setup.py and MANIFEST.in indicate this is distributed as a Python package, with the scripts and package modules bundled for installation and reuse.
Main entry points: tmdb_api.py API client · request.py Request · __init__.py tmdb3 · cache_engine.py Cache engine
Components 23
Public API
Top-level package entry points exposed to user code.
- tmdb3 · Main package surface re-exporting common entry points.
tmdb3/__init__.py
Core Runtime
Request execution, paging, and locale/auth context.
- API client · High-level TMDB API operations and object construction.
tmdb3/tmdb_api.py - Request · Builds and executes TMDB HTTP requests.
tmdb3/request.py - Pager · List-like result set that fetches additional pages on demand.
tmdb3/pager.py - Locales · Global and per-call locale configuration.
tmdb3/locales.py - Auth · API key and future auth-related hooks.
tmdb3/tmdb_auth.py - Util · Common parsing and conversion helpers.
tmdb3/util.py - Exceptions · Package-specific exception hierarchy.
tmdb3/tmdb_exceptions.py
Cache Layer
Pluggable request caching implementations.
- Cache engine · Selects and consults the active cache backend.
tmdb3/cache_engine.py - Cache API · Shared cache interface used by request handling.
tmdb3/cache.py - File cache · Default file-backed cache implementation.
tmdb3/cache_file.py - Null cache · Disables persistence for debugging or testing.
tmdb3/cache_null.py
Domain Model
Lazy TMDB entities and related media objects.
- Movie · Lazy-loaded movie handle backed by TMDB data.
- Person · People and credit metadata.
- Series · TV series root object.
- Season · Season-level TV object.
- Episode · Episode-level TV object.
- Images · Backdrop, poster, profile, and logo image objects.
- Relations · Cast, crew, genre, release, and translation objects.
- Collection · Grouped movie collection object.
Support
Packaging and auxiliary scripts.
- Populate locale · Auxiliary locale data population script.
scripts/populate_locale.py - CLI script · Support script entry point for the package.
scripts/pytmdb3.py - setup.py · Package build and installation metadata.
setup.py
Connections 25
- tmdb3 → API client: re-exports · Top-level package exposes client entry points through the API layer.
- tmdb3 → Locales: configures · Package surface exposes locale selection and defaults.
- tmdb3 → Auth: configures · Package surface exposes API key setup.
- API client → Request: uses · High-level operations are translated into HTTP requests.
- API client → Pager: returns · Search and list endpoints yield paged result objects.
- API client → Movie: creates · API layer constructs media entity handles.
- API client → Person: creates · API layer constructs people entities.
- API client → Series: creates · API layer constructs TV series entities.
- API client → Collection: creates · API layer constructs collection entities.
- Request → Cache engine: consults · Requests check the configured cache before remote calls.
- Cache engine → Cache API: abstracts · Cache orchestration is built around a shared cache contract.
- Cache engine → File cache: selects · Default backend persists responses on disk.
- Cache engine → Null cache: selects · Null backend disables persistence.
- Request → Locales: applies · Locale state influences request formation and localized fields.
- Request → Auth: includes · Request construction includes API key and auth context.
- Request → Exceptions: raises · Transport and API failures surface as package exceptions.
- Request → Util: uses · Shared helpers support request parsing and normalization.
- Pager → Request: fetches · Additional pages are retrieved through the request layer.
- Movie → Images: exposes · Media entities surface image resources and URLs.
- Movie → Relations: contains · Media entities include cast, crew, genres, releases, and translations.
- Series → Season: contains · TV series are composed of seasons.
- Season → Episode: contains · Seasons are composed of episodes.
- CLI script → tmdb3: invokes · Auxiliary script uses the package entry points.
- Populate locale → Locales: populates · Locale utility script works through locale state and data.
- setup.py → tmdb3: packages · Packaging metadata distributes the library modules.