Update api.py

- improve conditional handling of passed 'from'