Giter Site home page Giter Site logo

kgk / requests-cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from requests-cache/requests-cache

0.0 0.0 0.0 358 KB

Transparent persistent cache for http://python-requests.org/ library ⛺

Home Page: http://pypi.python.org/pypi/requests-cache

License: BSD 2-Clause "Simplified" License

Python 100.00%

requests-cache's Introduction

requests-cache

Requests-cache is a transparent persistent cache for the requests library (version 2+).

Build Coverage Documentation PyPI PyPI - Python Versions PyPI - Format Code Shelter

Installation

Install with pip:

pip install requests-cache

Usage example

import requests_cache

requests_cache.install_cache('demo_cache')

And all responses with headers and cookies will be transparently cached to demo_cache.sqlite. For example, following the code will take only 1-2 seconds instead of 10, and will run instantly on next launch:

import requests

for i in range(10):
    requests.get('http://httpbin.org/delay/1')

It can be useful when you are creating some simple data scraper with constantly changing parsing logic or data format, and don't want to redownload pages or write complex error handling and persistence.

For more complex workflows, it is possible to cache different requests with different expiration times, or disable caching for a specific request completely:

For more complex workflows, it is possible to cache different requests with different expiry times, or disable caching for a specific request completely:

import time
import requests
import requests_cache

requests_cache.install_cache('demo_cache')

# Hits the URL only 2 times
for i in range(10):
    requests.get('http://httpbin.org/delay/1', expire_after=1)
    time.sleep(0.2)

Related Projects

If requests-cache isn't quite what you need, you can help make it better! See the Contributing Guide for details.

You can also check out these other python cache projects:

  • CacheControl: An HTTP cache for requests that caches according to uses HTTP headers and status codes
  • aiohttp-client-cache: An async HTTP cache for aiohttp, based on requests-cache
  • aiohttp-cache: A server-side async HTTP cache for the aiohttp web server
  • diskcache: A general-purpose (not HTTP-specific) file-based cache built on SQLite
  • aiocache: General-purpose (not HTTP-specific) async cache backends

Links

requests-cache's People

Contributors

aaron-mf1 avatar andrewkittredge avatar ar90n avatar borisdan avatar chengguangnan avatar christopher-dg avatar craigls avatar edwardbetts avatar fdemmer avatar femtotrader avatar garrett-r avatar jacebrowning avatar jkwill87 avatar jwcook avatar kkvilekval avatar libbkmz avatar mbarkhau avatar meowcoder avatar mgax avatar mgedmin avatar michaelbeaumont avatar mjhea0 avatar msabramo avatar olivierdalang avatar reclosedev avatar rgant avatar shoeffner avatar themiurgo avatar yetanothernerd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.