cachepot


Namecachepot JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/kitsuyui/cachepot
SummaryYet another Python cache library
upload_time2023-10-06 04:59:28
maintainer
docs_urlNone
authorYui Kitsu
requires_python>=3.8
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cachepot

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)
[![PyPI](https://img.shields.io/pypi/v/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)
[![Lint and Test Python](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml/badge.svg)](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml)
[![codecov](https://codecov.io/gh/kitsuyui/cachepot/branch/main/graph/badge.svg?token=mdzEJ8cwcB)](https://codecov.io/gh/kitsuyui/cachepot)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

Yet another Python cache library. This has Python 3 typing hints.

## Installation

```
$ pip install cachepot
```

## Usage

```python
>>> from cachepot.store import CacheStore
>>> from cachepot.backend.filesystem import FileSystemCacheBackend
>>> from cachepot.serializer.pickle import PickleSerializer
>>> store = CacheStore(
...     namespace='testing',
...     key_serializer=PickleSerializer(),
...     value_serializer=PickleSerializer(),
...     backend=FileSystemCacheBackend('/tmp'),
...     default_expire_seconds=3600,
... )
>>> store.put({'some': 'key'}, {'some': 'value'})
>>> store.get({'some': 'key'})
{'some': 'value'}
>>> store.put({'some': 'short expiring key'}, {'some': 'value'}, expire_seconds=10)
```

### Proxy method

```python
result = store.proxy(some_func)(some_args)
```

is the equivalent of

```python
result = store.get(some_arg)
if result is None:
    result = some_func(some_args)
    store.set(result)
```

In short, this works as proxy. This helps to make codes straight forward.
proxy method can be passed two arguments `cache_key` and `expire_seconds`.

## Core idea

Serializers convert python objects into bytes.
Backends save/load bytes.
So serializers and backends are independent.
CacheStore is the facade of them.

- Python3 typing supports
- namespaces
- Proxy method

## Features

### Serializers

- str ... [cachepot.serializer.str.StringSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/str.py)
- [pickle](https://docs.python.org/3/library/pickle.html) ... [cachepot.serializer.pickle.PickleSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/pickle.py)
- [JSON](https://tools.ietf.org/html/rfc8259) ... [cachepot.serializer.json.JSONSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/json.py)

And more serializers you can define.

### Backends

- Save to files ... [cachepot.backend.filesystem.FileSystemCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/filesystem.py)
- Save to SQLite3 DB records ... [cachepot.backend.sqlite.SQLiteCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/sqlite.py)
- Save to Redis DB ... [cachepot.backend.redis.RedisCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/redis.py)

Of course you can define own backend.

## Development

You can install requirements with poetry.

```shell
$ poetry install
```

### Test

```shell
$ poetry poe check  # lint and type check
$ poetry poe test  # run tests
```

# LICENSE

The 3-Clause BSD License. See also LICENSE file.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kitsuyui/cachepot",
    "name": "cachepot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Yui Kitsu",
    "author_email": "kitsuyui+github@kitsuyui.com",
    "download_url": "https://files.pythonhosted.org/packages/c4/e0/fd2a7a65dff30d7ef3b2b36aabf4fc6862e6072a81e27811dd7192a6fa5b/cachepot-0.3.0.tar.gz",
    "platform": null,
    "description": "# cachepot\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)\n[![PyPI](https://img.shields.io/pypi/v/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)\n[![Lint and Test Python](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml/badge.svg)](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml)\n[![codecov](https://codecov.io/gh/kitsuyui/cachepot/branch/main/graph/badge.svg?token=mdzEJ8cwcB)](https://codecov.io/gh/kitsuyui/cachepot)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n\nYet another Python cache library. This has Python 3 typing hints.\n\n## Installation\n\n```\n$ pip install cachepot\n```\n\n## Usage\n\n```python\n>>> from cachepot.store import CacheStore\n>>> from cachepot.backend.filesystem import FileSystemCacheBackend\n>>> from cachepot.serializer.pickle import PickleSerializer\n>>> store = CacheStore(\n...     namespace='testing',\n...     key_serializer=PickleSerializer(),\n...     value_serializer=PickleSerializer(),\n...     backend=FileSystemCacheBackend('/tmp'),\n...     default_expire_seconds=3600,\n... )\n>>> store.put({'some': 'key'}, {'some': 'value'})\n>>> store.get({'some': 'key'})\n{'some': 'value'}\n>>> store.put({'some': 'short expiring key'}, {'some': 'value'}, expire_seconds=10)\n```\n\n### Proxy method\n\n```python\nresult = store.proxy(some_func)(some_args)\n```\n\nis the equivalent of\n\n```python\nresult = store.get(some_arg)\nif result is None:\n    result = some_func(some_args)\n    store.set(result)\n```\n\nIn short, this works as proxy. This helps to make codes straight forward.\nproxy method can be passed two arguments `cache_key` and `expire_seconds`.\n\n## Core idea\n\nSerializers convert python objects into bytes.\nBackends save/load bytes.\nSo serializers and backends are independent.\nCacheStore is the facade of them.\n\n- Python3 typing supports\n- namespaces\n- Proxy method\n\n## Features\n\n### Serializers\n\n- str ... [cachepot.serializer.str.StringSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/str.py)\n- [pickle](https://docs.python.org/3/library/pickle.html) ... [cachepot.serializer.pickle.PickleSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/pickle.py)\n- [JSON](https://tools.ietf.org/html/rfc8259) ... [cachepot.serializer.json.JSONSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/json.py)\n\nAnd more serializers you can define.\n\n### Backends\n\n- Save to files ... [cachepot.backend.filesystem.FileSystemCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/filesystem.py)\n- Save to SQLite3 DB records ... [cachepot.backend.sqlite.SQLiteCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/sqlite.py)\n- Save to Redis DB ... [cachepot.backend.redis.RedisCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/redis.py)\n\nOf course you can define own backend.\n\n## Development\n\nYou can install requirements with poetry.\n\n```shell\n$ poetry install\n```\n\n### Test\n\n```shell\n$ poetry poe check  # lint and type check\n$ poetry poe test  # run tests\n```\n\n# LICENSE\n\nThe 3-Clause BSD License. See also LICENSE file.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Yet another Python cache library",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/kitsuyui/cachepot"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8586a53da8585c8205b97996e988144f38e3151fa5388dba77c5bb7a1918e49",
                "md5": "52ed00609bad1ae7cca9488a1cd516bc",
                "sha256": "449a17d9af0bd7e9da252f932d5e8bd535428669ad336d7e71834da3f82f70ae"
            },
            "downloads": -1,
            "filename": "cachepot-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "52ed00609bad1ae7cca9488a1cd516bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13501,
            "upload_time": "2023-10-06T04:59:27",
            "upload_time_iso_8601": "2023-10-06T04:59:27.055475Z",
            "url": "https://files.pythonhosted.org/packages/c8/58/6a53da8585c8205b97996e988144f38e3151fa5388dba77c5bb7a1918e49/cachepot-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4e0fd2a7a65dff30d7ef3b2b36aabf4fc6862e6072a81e27811dd7192a6fa5b",
                "md5": "7c21dab4362252b492440f8768a9fe00",
                "sha256": "7ba7ffdc2ddcb4b4bfb3ae4fcffc53b7b756d213615c5d5cdd9b453320e674f5"
            },
            "downloads": -1,
            "filename": "cachepot-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7c21dab4362252b492440f8768a9fe00",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 30489,
            "upload_time": "2023-10-06T04:59:28",
            "upload_time_iso_8601": "2023-10-06T04:59:28.762566Z",
            "url": "https://files.pythonhosted.org/packages/c4/e0/fd2a7a65dff30d7ef3b2b36aabf4fc6862e6072a81e27811dd7192a6fa5b/cachepot-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-06 04:59:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kitsuyui",
    "github_project": "cachepot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cachepot"
}
        
Elapsed time: 0.12798s