Skip to content

Modify get params to use api_key defined in params#85

Closed
harshulsahni wants to merge 5 commits into
celiao:masterfrom
harshulsahni:modify_get_params
Closed

Modify get params to use api_key defined in params#85
harshulsahni wants to merge 5 commits into
celiao:masterfrom
harshulsahni:modify_get_params

Conversation

@harshulsahni
Copy link
Copy Markdown

the _get_params function only relied on tmdb.API_KEY = ... to set an API key. This PR aims to add functionality so that the user can specify an API key in every function to eliminate this global dependency.

See the test test_tmdb_get_params_no_api_with_search in test_base.py for example usage.

Also, this PR simplifies some boolean and string logic to for conciseness.

Comment thread tests/test_base.py
tmdb.API_KEY = None
with self.assertRaises(tmdb.base.APIKeyError):
tmdb_no_api_defined._get_params(params={})
tmdb.API_KEY = API_KEY
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everytime I change the API_KEY to None, I "reset" it like so to preserve the other tests

@celiao
Copy link
Copy Markdown
Owner

celiao commented Jan 25, 2022

@harshulsahni Why do you want to use more than one API Key?

@harshulsahni
Copy link
Copy Markdown
Author

@celiao I don't want to use more than one API key, but rather I would like the endpoint functions (e.g. search.movie()) to be used without having to define the API key at the top of some file. It would be much cleaner (in my opinion) to have the API key defined in the arguments of these functions so they can be more modular.

@celiao
Copy link
Copy Markdown
Owner

celiao commented May 25, 2026

Thank you @harshulsahni for the contribution and the thoughtful implementation! The code itself is clean and the tests are thorough.

After consideration, we're going to keep authentication simple — the global tmdb.API_KEY = 'your_key' pattern is intentional and central to the tmdbsimple philosophy. Adding a second way to authenticate risks confusing users (particularly students, who are a part of our audience) about which approach to use.

For the rare multi-tenant use case, users can always save and restore the global key around their calls. Closing for now, but genuinely appreciate your suggestion and PR!

@celiao celiao closed this May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants