Mock API requests with and obtain a pre-saved response object.
With this package you can mock the behavior of the requests
library. You can write code that looks identical to the one you'd be using in an actual request, but which in reality loads pre-saved response objects with matching request parameters.
pandas>=0.23.0
requests>=2.21.0
This package is not yet available in PyPy, but you can still install it using pip
. First clone the repo, navigate into the repo directory, and then issue
$ pip install mock_request --user
in your terminal.
Until a more complete of examples is available, you can get a good sense of how to use this package by working through the mock-request/tests/files/yelp-api-request.ipynb
notebook.
This package was originally created for online courses, where it became necessary for several reasons:
- hitting an API thousands of time a day from the same IP and/or with the same authentication will hit the daily download limit
- the online course will not rely on the API servers, and will continue to work even if they're down or if the API changes
- it shortens the execution time of online exercises
However, this package can be used for more generic situations. One good example would be to write unit tests for code performing API requests but without actually executing the requests.
I'll be happy (and proud!) if you'd like to contribute to this package. Feel free to open an issue explaining the fix/improvement/expansion you'd like to develop and let's discuss it.