aiohttp-client-cache


Nameaiohttp-client-cache JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/JWCook/aiohttp-client-cache
SummaryPersistent cache for aiohttp requests
upload_time2021-05-12 20:54:22
maintainer
docs_urlNone
authorJordan Cook
requires_python>=3.7,<4.0
licenseMIT
keywords aiohttp async asyncio cache cache-backends client http persistence requests sqlite redis mongodb dynamodb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiohttp-client-cache

[![Build status](https://github.com/JWCook/aiohttp-client-cache/workflows/Build/badge.svg)](https://github.com/JWCook/aiohttp-client-cache/actions)
[![Documentation Status](https://img.shields.io/readthedocs/aiohttp-client-cache/stable?label=docs)](https://aiohttp-client-cache.readthedocs.io/en/latest/)
[![Coverage Status](https://img.shields.io/coveralls/github/JWCook/aiohttp-client-cache)](https://coveralls.io/github/JWCook/aiohttp-client-cache?branch=main)
[![PyPI](https://img.shields.io/pypi/v/aiohttp-client-cache?color=blue)](https://pypi.org/project/aiohttp-client-cache)
[![PyPI - Python Versions](https://img.shields.io/pypi/pyversions/aiohttp-client-cache)](https://pypi.org/project/aiohttp-client-cache)
[![PyPI - Format](https://img.shields.io/pypi/format/aiohttp-client-cache?color=blue)](https://pypi.org/project/aiohttp-client-cache)

**aiohttp-client-cache** is an async persistent cache for [aiohttp](https://docs.aiohttp.org)
client requests.

See full documentation at https://aiohttp-client-cache.readthedocs.io

# Features
* **Ease of use:** Use as a [drop-in replacement](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html)
  for `aiohttp.ClientSession`
* **Customization:** Works out of the box with little to no config, but with plenty of options
  available for customizing cache
  [expiration](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html#cache-expiration)
  and other [behavior](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html#cache-options)
* **Persistence:** Includes several [storage backends](https://aiohttp-client-cache.readthedocs.io/en/latest/backends.html):
  SQLite, DynamoDB, MongoDB, and Redis.
  
# Development Status
**This library is a work in progress!**

Breaking changes should be expected until a `1.0` release, so version pinning is recommended.

I am developing this while also maintaining [requests-cache](https://github.com/reclosedev/requests-cache),
and my goal is to eventually have a similar (but not identical) feature set between the two libraries.
If there is a feature you want, if you've discovered a bug, or if you have other general feedback, please
[create an issue](https://github.com/JWCook/aiohttp-client-cache/issues/new/choose) for it!

# Quickstart
First, install with pip (python 3.7+ required):
```bash
pip install aiohttp-client-cache
```

## Basic Usage
Next, use [aiohttp_client_cache.CachedSession](https://aiohttp-client-cache.readthedocs.io/en/latest/modules/aiohttp_client_cache.session.html#aiohttp_client_cache.session.CachedSession)
in place of [aiohttp.ClientSession](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession).
To briefly demonstrate how to use it:                                      
                                                                                                       
**Replace this:**
```python
from aiohttp import ClientSession

async with ClientSession() as session:
    await session.get('http://httpbin.org/delay/1')                                                          
```                                                                                                    
                                                                                                       
**With this:**           
```python
from aiohttp_client_cache import CachedSession, SQLiteBackend

async with CachedSession(cache=SQLiteBackend('demo_cache')) as session:
    await session.get('http://httpbin.org/delay/1')                                                          
```

The URL in this example adds a delay of 1 second, simulating a slow or rate-limited website.
With caching, the response will be fetched once, saved to `demo_cache.sqlite`, and subsequent
requests will return the cached response near-instantly.

## Configuration
Several options are available to customize caching behavior. This example demonstrates a few of them:

```python
from aiohttp_client_cache import SQLiteBackend

cache = SQLiteBackend(
    cache_name='~/.cache/aiohttp-requests.db',  # For SQLite, this will be used as the filename
    expire_after=60*60,                         # By default, cached responses expire in an hour
    urls_expire_after={'*.fillmurray.com': -1}, # Requests for any subdomain on this site will never expire
    allowed_codes=(200, 418),                   # Cache responses with these status codes
    allowed_methods=('GET', 'POST'),            # Cache requests with these HTTP methods
    include_headers=True,                       # Cache requests with different headers separately
    ignored_params=['auth_token'],              # Keep using the cached response even if this param changes
    timeout=2.5,                                # Connection timeout for SQLite backend 
)
```

# More Info
To learn more, see:
* [User Guide](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html)
* [Cache Backends](https://aiohttp-client-cache.readthedocs.io/en/latest/backends.html)
* [API Reference](https://aiohttp-client-cache.readthedocs.io/en/latest/reference.html)
* [Examples](https://aiohttp-client-cache.readthedocs.io/en/latest/examples.html)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/JWCook/aiohttp-client-cache",
    "name": "aiohttp-client-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "aiohttp,async,asyncio,cache,cache-backends,client,http,persistence,requests,sqlite,redis,mongodb,dynamodb",
    "author": "Jordan Cook",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/27/ec/0f085c24b6e6593dcde880c3a57329a2dc8194f270512efe566269b33305/aiohttp-client-cache-0.4.0.tar.gz",
    "platform": "",
    "description": "# aiohttp-client-cache\n\n[![Build status](https://github.com/JWCook/aiohttp-client-cache/workflows/Build/badge.svg)](https://github.com/JWCook/aiohttp-client-cache/actions)\n[![Documentation Status](https://img.shields.io/readthedocs/aiohttp-client-cache/stable?label=docs)](https://aiohttp-client-cache.readthedocs.io/en/latest/)\n[![Coverage Status](https://img.shields.io/coveralls/github/JWCook/aiohttp-client-cache)](https://coveralls.io/github/JWCook/aiohttp-client-cache?branch=main)\n[![PyPI](https://img.shields.io/pypi/v/aiohttp-client-cache?color=blue)](https://pypi.org/project/aiohttp-client-cache)\n[![PyPI - Python Versions](https://img.shields.io/pypi/pyversions/aiohttp-client-cache)](https://pypi.org/project/aiohttp-client-cache)\n[![PyPI - Format](https://img.shields.io/pypi/format/aiohttp-client-cache?color=blue)](https://pypi.org/project/aiohttp-client-cache)\n\n**aiohttp-client-cache** is an async persistent cache for [aiohttp](https://docs.aiohttp.org)\nclient requests.\n\nSee full documentation at https://aiohttp-client-cache.readthedocs.io\n\n# Features\n* **Ease of use:** Use as a [drop-in replacement](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html)\n  for `aiohttp.ClientSession`\n* **Customization:** Works out of the box with little to no config, but with plenty of options\n  available for customizing cache\n  [expiration](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html#cache-expiration)\n  and other [behavior](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html#cache-options)\n* **Persistence:** Includes several [storage backends](https://aiohttp-client-cache.readthedocs.io/en/latest/backends.html):\n  SQLite, DynamoDB, MongoDB, and Redis.\n  \n# Development Status\n**This library is a work in progress!**\n\nBreaking changes should be expected until a `1.0` release, so version pinning is recommended.\n\nI am developing this while also maintaining [requests-cache](https://github.com/reclosedev/requests-cache),\nand my goal is to eventually have a similar (but not identical) feature set between the two libraries.\nIf there is a feature you want, if you've discovered a bug, or if you have other general feedback, please\n[create an issue](https://github.com/JWCook/aiohttp-client-cache/issues/new/choose) for it!\n\n# Quickstart\nFirst, install with pip (python 3.7+ required):\n```bash\npip install aiohttp-client-cache\n```\n\n## Basic Usage\nNext, use [aiohttp_client_cache.CachedSession](https://aiohttp-client-cache.readthedocs.io/en/latest/modules/aiohttp_client_cache.session.html#aiohttp_client_cache.session.CachedSession)\nin place of [aiohttp.ClientSession](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession).\nTo briefly demonstrate how to use it:                                      \n                                                                                                       \n**Replace this:**\n```python\nfrom aiohttp import ClientSession\n\nasync with ClientSession() as session:\n    await session.get('http://httpbin.org/delay/1')                                                          \n```                                                                                                    \n                                                                                                       \n**With this:**           \n```python\nfrom aiohttp_client_cache import CachedSession, SQLiteBackend\n\nasync with CachedSession(cache=SQLiteBackend('demo_cache')) as session:\n    await session.get('http://httpbin.org/delay/1')                                                          \n```\n\nThe URL in this example adds a delay of 1 second, simulating a slow or rate-limited website.\nWith caching, the response will be fetched once, saved to `demo_cache.sqlite`, and subsequent\nrequests will return the cached response near-instantly.\n\n## Configuration\nSeveral options are available to customize caching behavior. This example demonstrates a few of them:\n\n```python\nfrom aiohttp_client_cache import SQLiteBackend\n\ncache = SQLiteBackend(\n    cache_name='~/.cache/aiohttp-requests.db',  # For SQLite, this will be used as the filename\n    expire_after=60*60,                         # By default, cached responses expire in an hour\n    urls_expire_after={'*.fillmurray.com': -1}, # Requests for any subdomain on this site will never expire\n    allowed_codes=(200, 418),                   # Cache responses with these status codes\n    allowed_methods=('GET', 'POST'),            # Cache requests with these HTTP methods\n    include_headers=True,                       # Cache requests with different headers separately\n    ignored_params=['auth_token'],              # Keep using the cached response even if this param changes\n    timeout=2.5,                                # Connection timeout for SQLite backend \n)\n```\n\n# More Info\nTo learn more, see:\n* [User Guide](https://aiohttp-client-cache.readthedocs.io/en/latest/user_guide.html)\n* [Cache Backends](https://aiohttp-client-cache.readthedocs.io/en/latest/backends.html)\n* [API Reference](https://aiohttp-client-cache.readthedocs.io/en/latest/reference.html)\n* [Examples](https://aiohttp-client-cache.readthedocs.io/en/latest/examples.html)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Persistent cache for aiohttp requests",
    "version": "0.4.0",
    "split_keywords": [
        "aiohttp",
        "async",
        "asyncio",
        "cache",
        "cache-backends",
        "client",
        "http",
        "persistence",
        "requests",
        "sqlite",
        "redis",
        "mongodb",
        "dynamodb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "fadc5e66a4b4fcd84a2833667dde4848",
                "sha256": "bfc2594c65c226695a54c8d7f0f3d323881632dcd8f5fc580c0cec3878706503"
            },
            "downloads": -1,
            "filename": "aiohttp_client_cache-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fadc5e66a4b4fcd84a2833667dde4848",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 37224,
            "upload_time": "2021-05-12T20:54:23",
            "upload_time_iso_8601": "2021-05-12T20:54:23.462623Z",
            "url": "https://files.pythonhosted.org/packages/ac/56/4eb56bbeb4310555849a595d510ad6b80f7f73b56d9be970dd9d9b3078cf/aiohttp_client_cache-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "eebdf985000b2de5f2dac8c7d3428923",
                "sha256": "a4737dacb74002e3fbea51682d84786f7ff7004e790f4764e7b5f09504455680"
            },
            "downloads": -1,
            "filename": "aiohttp-client-cache-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "eebdf985000b2de5f2dac8c7d3428923",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 50428,
            "upload_time": "2021-05-12T20:54:22",
            "upload_time_iso_8601": "2021-05-12T20:54:22.212791Z",
            "url": "https://files.pythonhosted.org/packages/27/ec/0f085c24b6e6593dcde880c3a57329a2dc8194f270512efe566269b33305/aiohttp-client-cache-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-12 20:54:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "JWCook",
    "error": "Could not fetch GitHub repository",
    "lcname": "aiohttp-client-cache"
}
        
Elapsed time: 0.32450s