Skip to main content

AioCache DynamoDB Backend using Aiobotocore

Project description

aiocache-dynamodb

PyPI Python Versions Ruff Coverage Status pre-commit

aiocache-dynamodb is an asynchronous cache backend for DynamoDB, built on top of aiobotocore and aiocache. It provides a fully asynchronous interface for caching data using DynamoDB, allowing for efficient and scalable caching solutions in Python applications.

For more information on aiocache:

For more information on aiobotocore:

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.
  • (Planned) S3 integration for large object storage.

Installation

Install the package using pip:

pip install aiocache-dynamodb

Usage

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())

Configuration

The DynamoDBCache class supports the following parameters:

  • table_name: Name of the DynamoDB table.
  • endpoint_url: Endpoint URL for DynamoDB (useful for LocalStack).
  • region_name: AWS region (default: us-east-1).
  • aws_access_key_id: AWS access key ID.
  • aws_secret_access_key: AWS secret access key.
  • 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).

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:

make

Setup

To setup the project, you can run the following commands:

make install

This will install the required dependencies for the project using 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:

pre-commit install

If you for some reason hate pre-commit, you can run the following command to lint the code:

make check

Testing

To run tests, you can use the following command:

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.

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

aiocache_dynamodb-0.0.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiocache_dynamodb-0.0.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file aiocache_dynamodb-0.0.1.tar.gz.

File metadata

  • Download URL: aiocache_dynamodb-0.0.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aiocache_dynamodb-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0720c56a845317487698931157bc13a7f4c2ea6acb036e4c548cf772432e2452
MD5 5ade69c62aa5a523eb0b506330507281
BLAKE2b-256 3b1dbbe05be3f12814d73c898f127e5977f9f4766a3252c36f33c8f645c065b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiocache_dynamodb-0.0.1.tar.gz:

Publisher: publish.yml on vonsteer/aiocache-dynamodb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiocache_dynamodb-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiocache_dynamodb-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90c44f07ae38df270f155510cf909e65686c21e743de1a7138469ef3c8313e52
MD5 35a963c79aff40d4fed2a9cf5a7d3b13
BLAKE2b-256 476646ff509f9e4eec032540205c84a7250ade43489220caa5803e41063860bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiocache_dynamodb-0.0.1-py3-none-any.whl:

Publisher: publish.yml on vonsteer/aiocache-dynamodb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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