I'm not a big fan of a single argument containing two different type of values (either a path or a string), but if we proceed with this approach I would rather check if `key` is a file file path like this:

```python
is_file_path = os.path.exists(keypath) and os.path.isfile(keypath)
...
```