python requests-cache github

Python Requests-Cache Github

Python Requests-Cache is a package that allows you to cache the responses of your requests to external APIs or websites. It saves the responses in memory, on disk, or in a database, which can help improve the performance of your application and reduce the number of requests made to your server.

Installing Python Requests-Cache

To install Python Requests-Cache, you can use pip:

pip install requests-cache

Using Python Requests-Cache

Using Python Requests-Cache is very easy. You just need to import the package and wrap your requests with the requests_cache.CachedSession() function:


import requests_cache

# Enable cache
requests_cache.install_cache()

# Make a request
response = requests.get('https://www.example.com')

# The response is now cached
response = requests.get('https://www.example.com')

You can also pass some options to the CachedSession() function:

  • expire_after: sets the expiration time for cached responses.
  • cache_name: sets the name of the cache. You can have multiple cache instances with different names.
  • backend: sets the cache backend to use (memory, sqlite, or redis).

If you want to clear the cache, you can use the clear() function:

requests_cache.clear()

Python Requests-Cache Github Repository

The Python Requests-Cache package is open-source and can be found on Github.

You can download the package or contribute to the project by creating pull requests or opening issues on the repository.

Here is the link to the Python Requests-Cache repository on Github:

https://github.com/reclosedev/requests-cache