aiocache-dynamodb


Nameaiocache-dynamodb JSON
Version 1.1.0 PyPI version JSON
download
home_pageNone
SummaryAioCache DynamoDB Backend using Aiobotocore
upload_time2025-07-16 16:07:08
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2025 Jesse Constante Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords aiobotocore aiocache asyncio aws backend cache dynamodb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiocache-dynamodb

[![PyPI](https://img.shields.io/pypi/v/aiocache-dynamodb)](https://pypi.org/project/aiocache-dynamodb/)
[![Python Versions](https://img.shields.io/pypi/pyversions/aiocache-dynamodb)](https://pypi.org/project/aiocache-dynamodb/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Coverage Status](./coverage-badge.svg?dummy=8484744)](./coverage-badge.svg)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

`aiocache-dynamodb` is an asynchronous cache backend for DynamoDB, built on top of [`aiobotocore`](https://github.com/aio-libs/aiobotocore) and [`aiocache`](https://github.com/aio-libs/aiocache). It provides a fully asynchronous interface for caching data using DynamoDB (+ S3), allowing for efficient and scalable caching solutions in Python applications.

[Documentation](https://aiocache.aio-libs.org/en/latest/caches.html#third-party-caches).

For more information on aiobotocore:
- [aiobotocore documentation](https://aiobotocore.readthedocs.io/en/latest/)

## Features

- Fully asynchronous operations using `aiobotocore`.
- TTL support for expiring cache items (even though DynamoDB only deletes items within 48hr of expiration, we double-check).
- Batch operations for efficient multi-key handling.
- Customizable key, value, and TTL column names.
- S3 Extension for large object storage (+400kb)
---

## Installation

Install the package using pip:

```bash
pip install aiocache-dynamodb
```

## Usage
```python
import asyncio
from aiocache_dynamodb import DynamoDBCache

async def main():
    cache = DynamoDBCache(
        table_name="my-cache-table",
        endpoint_url="http://localhost:4566",  # For local development
        aws_access_key_id="your-access-key",
        aws_secret_access_key="your-secret-key",
        region_name="us-east-1",
    )

    # Set a value with a TTL of 60 seconds
    await cache.set("my_key", "my_value", ttl=60)

    # Get the value
    value = await cache.get("my_key")
    print(value)  # Output: my_value

    # Delete the value
    await cache.delete("my_key")

    # Check if the key exists
    exists = await cache.exists("my_key")
    print(exists)  # Output: False

    # Close the cache
    await cache.close()

asyncio.run(main())
```
To use the S3 extension feature:
```python
import asyncio
from aiocache_dynamodb import DynamoDBCache

async def main():
    cache = DynamoDBCache(
        table_name="my-cache-table",
        bucket_name="this-is-my-bucket",
        region_name="us-east-1",
    )

    large_value = "x" * 1024 * 400  # 400KB
    # Set a value with a TTL of 60 seconds
    # Deletion of item on S3 is not managed by the TTL
    # Please use lifecycle policies on the bucket
    await cache.set("my_key", large_value, ttl=60)

    # Get the value
    value = await cache.get("my_key")
    print(value)  # Output: large_value

    # Delete the value (both on dynamodb + S3)
    await cache.delete("my_key")

    # Close the cache
    await cache.close()

asyncio.run(main())
```

## Configuration
The `DynamoDBCache` class supports the following parameters:

- `serializer`: Serializer to use for serializing and deserializing values (default: `aiocache.serializers.StringSerializer`).
- `plugins`: List of plugins to use (default: `[]`).
- `namespace`: Namespace to use for the cache (default: `""`).
- `timeout`: Timeout for cache operations (default: `5`).
- `table_name`: Name of the DynamoDB table to use for caching.
- `bucket_name`: Name of the S3 bucket to use for large object storage (default: `None`).
- `endpoint_url`: Endpoint URL for DynamoDB (useful for LocalStack) (default: `None`).
- `region_name`: AWS region (default: `"us-east-1"`).
- `aws_access_key_id`: AWS access key ID (default: `None`).
- `aws_secret_access_key`: AWS secret access key (default: `None`).
- `key_column`: Column name for the cache key (default: `"cache_key"`).
- `value_column`: Column name for the cache value (default: `"cache_value"`).
- `ttl_column`: Column name for the TTL (default: `"ttl"`).
- `s3_key_column`: Column name for the S3 key, only used if bucket_name is provided (default: `"s3_key"`).
- `s3_client`: Aiobotocore S3 client to use for large object storage, if not provided it'll be created lazily on first call or on `__aenter__` (default: `None`).
- `dynamodb_client`: Aiobotocore DynamoDB client to use, if not provided it'll be created lazily on first call or on `__aenter__` (default: `None`).


# Local Development:
We use make to handle the commands for the project, you can see the available commands by running this in the root directory:
```bash
make
```

## Setup
To setup the project, you can run the following commands:
```bash
make dev
```
This will install the required dependencies for the project using uv + pip.

## Linting
We use pre-commit to do linting locally, this will be included in the dev dependencies.
We use ruff for linting and formatting, and pyright for static type checking.
To install the pre-commit hooks, you can run the following command:
```bash
pre-commit install
```
If you for some reason hate pre-commit, you can run the following command to lint the code:
```bash
make check
```

## Testing
To run tests, you can use the following command:
```bash
make test
```
In the background this will setup localstack to replicate the AWS services, and run the tests.
It will also generate the coverage badge.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "aiocache-dynamodb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "aiobotocore, aiocache, asyncio, aws, backend, cache, dynamodb",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/c1/7b/b4ec5501bce861c3e855fd0e46ab53def0d8850592ecdb879f314429ec77/aiocache_dynamodb-1.1.0.tar.gz",
    "platform": null,
    "description": "# aiocache-dynamodb\n\n[![PyPI](https://img.shields.io/pypi/v/aiocache-dynamodb)](https://pypi.org/project/aiocache-dynamodb/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/aiocache-dynamodb)](https://pypi.org/project/aiocache-dynamodb/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Coverage Status](./coverage-badge.svg?dummy=8484744)](./coverage-badge.svg)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n\n`aiocache-dynamodb` is an asynchronous cache backend for DynamoDB, built on top of [`aiobotocore`](https://github.com/aio-libs/aiobotocore) and [`aiocache`](https://github.com/aio-libs/aiocache). It provides a fully asynchronous interface for caching data using DynamoDB (+ S3), allowing for efficient and scalable caching solutions in Python applications.\n\n[Documentation](https://aiocache.aio-libs.org/en/latest/caches.html#third-party-caches).\n\nFor more information on aiobotocore:\n- [aiobotocore documentation](https://aiobotocore.readthedocs.io/en/latest/)\n\n## Features\n\n- Fully asynchronous operations using `aiobotocore`.\n- TTL support for expiring cache items (even though DynamoDB only deletes items within 48hr of expiration, we double-check).\n- Batch operations for efficient multi-key handling.\n- Customizable key, value, and TTL column names.\n- S3 Extension for large object storage (+400kb)\n---\n\n## Installation\n\nInstall the package using pip:\n\n```bash\npip install aiocache-dynamodb\n```\n\n## Usage\n```python\nimport asyncio\nfrom aiocache_dynamodb import DynamoDBCache\n\nasync def main():\n    cache = DynamoDBCache(\n        table_name=\"my-cache-table\",\n        endpoint_url=\"http://localhost:4566\",  # For local development\n        aws_access_key_id=\"your-access-key\",\n        aws_secret_access_key=\"your-secret-key\",\n        region_name=\"us-east-1\",\n    )\n\n    # Set a value with a TTL of 60 seconds\n    await cache.set(\"my_key\", \"my_value\", ttl=60)\n\n    # Get the value\n    value = await cache.get(\"my_key\")\n    print(value)  # Output: my_value\n\n    # Delete the value\n    await cache.delete(\"my_key\")\n\n    # Check if the key exists\n    exists = await cache.exists(\"my_key\")\n    print(exists)  # Output: False\n\n    # Close the cache\n    await cache.close()\n\nasyncio.run(main())\n```\nTo use the S3 extension feature:\n```python\nimport asyncio\nfrom aiocache_dynamodb import DynamoDBCache\n\nasync def main():\n    cache = DynamoDBCache(\n        table_name=\"my-cache-table\",\n        bucket_name=\"this-is-my-bucket\",\n        region_name=\"us-east-1\",\n    )\n\n    large_value = \"x\" * 1024 * 400  # 400KB\n    # Set a value with a TTL of 60 seconds\n    # Deletion of item on S3 is not managed by the TTL\n    # Please use lifecycle policies on the bucket\n    await cache.set(\"my_key\", large_value, ttl=60)\n\n    # Get the value\n    value = await cache.get(\"my_key\")\n    print(value)  # Output: large_value\n\n    # Delete the value (both on dynamodb + S3)\n    await cache.delete(\"my_key\")\n\n    # Close the cache\n    await cache.close()\n\nasyncio.run(main())\n```\n\n## Configuration\nThe `DynamoDBCache` class supports the following parameters:\n\n- `serializer`: Serializer to use for serializing and deserializing values (default: `aiocache.serializers.StringSerializer`).\n- `plugins`: List of plugins to use (default: `[]`).\n- `namespace`: Namespace to use for the cache (default: `\"\"`).\n- `timeout`: Timeout for cache operations (default: `5`).\n- `table_name`: Name of the DynamoDB table to use for caching.\n- `bucket_name`: Name of the S3 bucket to use for large object storage (default: `None`).\n- `endpoint_url`: Endpoint URL for DynamoDB (useful for LocalStack) (default: `None`).\n- `region_name`: AWS region (default: `\"us-east-1\"`).\n- `aws_access_key_id`: AWS access key ID (default: `None`).\n- `aws_secret_access_key`: AWS secret access key (default: `None`).\n- `key_column`: Column name for the cache key (default: `\"cache_key\"`).\n- `value_column`: Column name for the cache value (default: `\"cache_value\"`).\n- `ttl_column`: Column name for the TTL (default: `\"ttl\"`).\n- `s3_key_column`: Column name for the S3 key, only used if bucket_name is provided (default: `\"s3_key\"`).\n- `s3_client`: Aiobotocore S3 client to use for large object storage, if not provided it'll be created lazily on first call or on `__aenter__` (default: `None`).\n- `dynamodb_client`: Aiobotocore DynamoDB client to use, if not provided it'll be created lazily on first call or on `__aenter__` (default: `None`).\n\n\n# Local Development:\nWe use make to handle the commands for the project, you can see the available commands by running this in the root directory:\n```bash\nmake\n```\n\n## Setup\nTo setup the project, you can run the following commands:\n```bash\nmake dev\n```\nThis will install the required dependencies for the project using uv + pip.\n\n## Linting\nWe use pre-commit to do linting locally, this will be included in the dev dependencies.\nWe use ruff for linting and formatting, and pyright for static type checking.\nTo install the pre-commit hooks, you can run the following command:\n```bash\npre-commit install\n```\nIf you for some reason hate pre-commit, you can run the following command to lint the code:\n```bash\nmake check\n```\n\n## Testing\nTo run tests, you can use the following command:\n```bash\nmake test\n```\nIn the background this will setup localstack to replicate the AWS services, and run the tests.\nIt will also generate the coverage badge.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2025 Jesse Constante  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "AioCache DynamoDB Backend using Aiobotocore",
    "version": "1.1.0",
    "project_urls": {
        "source": "https://github.com/vonsteer/aiocache-dynamodb"
    },
    "split_keywords": [
        "aiobotocore",
        " aiocache",
        " asyncio",
        " aws",
        " backend",
        " cache",
        " dynamodb"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3e1d2e89881e11ca091245a81704a44bf8a9cc4e85222125de8ffe95cbcce345",
                "md5": "d8510eaa4df9a5cde4159542b18994b1",
                "sha256": "4e89e129cb7355c269503e8346d93742f3ac869e3d8fc3719ac2726f8c1329b5"
            },
            "downloads": -1,
            "filename": "aiocache_dynamodb-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d8510eaa4df9a5cde4159542b18994b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 13130,
            "upload_time": "2025-07-16T16:07:07",
            "upload_time_iso_8601": "2025-07-16T16:07:07.148758Z",
            "url": "https://files.pythonhosted.org/packages/3e/1d/2e89881e11ca091245a81704a44bf8a9cc4e85222125de8ffe95cbcce345/aiocache_dynamodb-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c17bb4ec5501bce861c3e855fd0e46ab53def0d8850592ecdb879f314429ec77",
                "md5": "cda3f7ceb9103f5839e3bcf0265f6a20",
                "sha256": "2ff17699bb7881fcdd592ad2cb5f1883006e884e6c86a4f7808baa266301b177"
            },
            "downloads": -1,
            "filename": "aiocache_dynamodb-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "cda3f7ceb9103f5839e3bcf0265f6a20",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 130033,
            "upload_time": "2025-07-16T16:07:08",
            "upload_time_iso_8601": "2025-07-16T16:07:08.404596Z",
            "url": "https://files.pythonhosted.org/packages/c1/7b/b4ec5501bce861c3e855fd0e46ab53def0d8850592ecdb879f314429ec77/aiocache_dynamodb-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-16 16:07:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vonsteer",
    "github_project": "aiocache-dynamodb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiocache-dynamodb"
}
        
Elapsed time: 1.72582s