Skip to main content

Simple HTTP cache for Python Requests

Project description

HTTP, like all well designed standards, has multiple confusing mechanisms for caching. This module is a HTTP cache that knows how to use HTTP headers and status codes to correctly cache your HTTP traffic. It’s built for use with the excellent Requests library, because if you’re not using Requests you’re probably prepared to roll your own caching library too.

It’s gloriously easy to use. Store your cache entries like this:

from httpcache import HTTPCache
cache = HTTPCache(capacity=50)
cache.store(response)

And retrieve them like this:

cached_response = cache.retrieve(request)

Simple.

Features

  • Tight integration with Requests data structures.

  • Understands Expires and Cache-Control headers.

  • Knows how to interpret 304 Not Modified responses.

  • Can send If-Modified-Since headers.

  • Aware of HTTP verbs, e.g. POST.

  • RFC 2616-compliant.

Installation

To install http-cache, you want to run:

$ pip install http-cache

If you can’t do that, and you really must have http-cache, and you can’t install pip, then you can try:

$ easy_install http-cache

I strongly recommend you don’t do that though.

Contribute

Contributions are always welcome! Please abide by the following rules when contributing:

  1. Check that no-one has opened an issue already covering your bug. If you open a duplicate issue, the maintainer will give you a stern look.

  2. Fork the Github repository and start writing your tests. If you’re fixing a bug, I recommend writing a failing test first and working until it passes. If you’re adding a feature, you’re free to add tests after you write the functionality, but please test the functionality thoroughly.

  3. Send a Pull Request. If I don’t respond within a couple of days, please shout at me on Twitter or via email until I do something about it.

History

Nothing to see here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

httpcache-0.0.1.tar.gz (5.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page