A Python script to find rows in a Notion database where certain properties are empty, fetch metadata from The Movie Database (TMDB), and fill those properties automatically.
- Queries Notion for pages missing data in one or more fields
- Searches TMDB for movie or TV show details (including credits)
- Populates Notion properties like Poster URL, Genre, Director, Studio, etc.
- Handles new fields dynamically—just add them to your config map
- Caches TMDB requests and parallelizes updates for performance
- Python 3.8 or newer
- A terminal / command prompt
- Access to your Notion workspace
- A TMDB account with an API v4 Read Access Token
Clone this repo and cd into it
pip install -r requirements.txtCreate a file named .env in the project root and define the following variables.
Your TMDB API v4 Read Access Token. How to get it:
- Sign in at https://www.themoviedb.org/
- Go to your account settings → API
- Under “API v4 (Read Access Token)” click Create or Retrieve
- Copy the generated token (starts with eyJ…)
A Notion integration token with access to your database. How to get it:
- Visit https://www.notion.so/my-integrations and click New integration
- Give it a name and select the workspace
- Click Submit and copy the Internal Integration Token
** Make sure to add your workspace to your integrations **
The ID of the database you want to update. How to get it:
- Open your database in Notion
- Click ••• → Copy link
- The URL will look like
https://www.notion.so/My-DB-Name-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?v=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
or
https://www.notion.so/<long_hash_1>?v=<long_hash_2>
- Extract the 32-character string after your name (the part marked
xxxxxxxx…or<long_hash_1>) - Add dashes in the 8-4-4-4-12 pattern if needed:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
The name of your title property in Notion (defaults to Name).
A JSON object mapping each Notion property name to its filter type. At minimum include all the fields you want to fill. Example:
NOTION_EMPTY_PROPERTY_MAP='{
"Poster":"rich_text",
"Genre":"multi_select",
"Director":"rich_text",
"Studio / Distributor":"multi_select",
"Type":"select"
}'Example .env
TMDB_TOKEN=eyJxxxYOUR_TMDB_TOKENxxx
NOTION_TOKEN=secret_xxxYOUR_NOTION_TOKENxxx
NOTION_DB=25ee7153-f4b9-80b2-9dfd-cea91237d4b1
NOTION_DB_TITLE="Movie / Series"
NOTION_EMPTY_PROPERTY_MAP={"Poster":"rich_text","Genre":"multi_select","Director":"rich_text","Studio / Distributor":"multi_select","Type":"select"}Run the updater script:
python notion_tmdb_updater.pyYou should see logs like:
2025-08-30 14:22:01 INFO Found 5 pages to update
2025-08-30 14:22:01 INFO Updated 'The Big Lebowski'
...
Add the new property name and filter type to NOTION_EMPTY_PROPERTY_MAP in your .env.
In handlers.py, register a new entry in PROP_HANDLERS:
PROP_HANDLERS["Revenue"] = lambda info: {"number": info["revenue"]}Re-run the script—it will now query pages missing Revenue and attempt to populate them.
If you see 400 Bad Request errors, verify your property names and types in Notion match your map.
Use logging output to identify pages that failed.
Confirm your .env is in the same directory where you launch the script.