Name | cacheia-client JSON |
Version |
1.0.0.post3
JSON |
| download |
home_page | None |
Summary | Client for cacheia service that allows invalidation and other shenanigans |
upload_time | 2024-07-24 17:50:14 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.12 |
license | None |
keywords |
client
cache
http
service
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Cacheia CLient
This module contains a client that is responsible for communicating with the Cacheia API. It is a simple wrapper around the API endpoints, providing a more user-friendly interface for the user.
## Installation
Install core with "schemas" optional to download schemas dependencies:
```bash
pip install -e ./client[schemas]
```
## Client Methods
- `cache`: Takes instance (CreateRequest), creator (Infostar) and backend to create a new cache instance in the provided backend.
- `get`: Retrieves all cached values with optional filters group (str), expires_range (tuple[float, float]) and creation_range(tuple[datetime, datetime]);
- `get_key`: Fetches the cached value associated with key (str) - Optionally accepts `allow_expired` parameter to return a cached value even if expired.
- `flush`: Clears all keys from the cache using with optional filters group (str), expires_range (tuple[float, float]) and creation_range(tuple[datetime, datetime]) and return the count of deleted records.
- `flush_key`: Removes a single key from the cache using key (str).
- `clear`: Removes all cached values from cache without any validation.
## Code
The library exposes single functions that are similar to `requests` and `httpx` and also exposes a `Client` class that can be used to define default value for API URL.
## Examples
To create a cache instance with the client:
```python
from cacheia_client import Client
from cacheia_schemas import CachedValue
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
instance = CachedValue(key="key", value="value")
client.cache(instance=instance)
```
Or using the helper functions:
```python
from cacheia_client import cache, configure
from cacheia_schemas import CachedValue
configure("http://localhost:5000")
instance = CachedValue(key="key", value="value")
cache(instance=instance)
```
Notice that when calling directly the functions, it is necessary to call "configure"
with the desired URL. Otherwise, it will fail.
---
To get all cached values:
```python
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
for v in client.get_all():
print(v)
```
---
To get a single cached value:
```python
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
print(client.get(key="key"))
```
---
To flush all keys:
```python
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
result = client.flush()
print(result.deleted_count)
```
---
To flush some keys:
```python
from datetime import datetime
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
now = datetime.now().timestamp()
result = client.flush(expires_range=(now-10, now+10))
print(result.deleted_count)
```
---
To flush a single key:
```python
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
result = client.flush_key(key="key")
print(result.deleted_count)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "cacheia-client",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "client, cache, http, service",
"author": null,
"author_email": "TeiaLabs <contato@teialabs.com>",
"download_url": "https://files.pythonhosted.org/packages/db/12/f2586a4fea1a0baf59e468996acf9ccd200197a7f23e85e5804095851f32/cacheia_client-1.0.0.post3.tar.gz",
"platform": null,
"description": "# Cacheia CLient\n\nThis module contains a client that is responsible for communicating with the Cacheia API. It is a simple wrapper around the API endpoints, providing a more user-friendly interface for the user.\n\n## Installation\n\nInstall core with \"schemas\" optional to download schemas dependencies:\n\n```bash\npip install -e ./client[schemas]\n```\n\n## Client Methods\n\n- `cache`: Takes instance (CreateRequest), creator (Infostar) and backend to create a new cache instance in the provided backend.\n- `get`: Retrieves all cached values with optional filters group (str), expires_range (tuple[float, float]) and creation_range(tuple[datetime, datetime]);\n- `get_key`: Fetches the cached value associated with key (str) - Optionally accepts `allow_expired` parameter to return a cached value even if expired.\n- `flush`: Clears all keys from the cache using with optional filters group (str), expires_range (tuple[float, float]) and creation_range(tuple[datetime, datetime]) and return the count of deleted records.\n- `flush_key`: Removes a single key from the cache using key (str).\n- `clear`: Removes all cached values from cache without any validation.\n\n## Code\n\nThe library exposes single functions that are similar to `requests` and `httpx` and also exposes a `Client` class that can be used to define default value for API URL.\n\n## Examples\n\nTo create a cache instance with the client:\n\n```python\nfrom cacheia_client import Client\nfrom cacheia_schemas import CachedValue\n\n\ndefault_url: str = \"http://localhost:5000\"\n\nclient = Client(url=default_url)\ninstance = CachedValue(key=\"key\", value=\"value\")\n\nclient.cache(instance=instance)\n```\n\nOr using the helper functions:\n\n```python\nfrom cacheia_client import cache, configure\nfrom cacheia_schemas import CachedValue\n\n\nconfigure(\"http://localhost:5000\")\n\ninstance = CachedValue(key=\"key\", value=\"value\")\ncache(instance=instance)\n```\n\nNotice that when calling directly the functions, it is necessary to call \"configure\"\nwith the desired URL. Otherwise, it will fail.\n\n---\n\nTo get all cached values:\n\n```python\nfrom cacheia_client import Client\n\n\ndefault_url: str = \"http://localhost:5000\"\nclient = Client(url=default_url)\n\nfor v in client.get_all():\n print(v)\n```\n\n---\n\nTo get a single cached value:\n\n```python\nfrom cacheia_client import Client\n\n\ndefault_url: str = \"http://localhost:5000\"\nclient = Client(url=default_url)\nprint(client.get(key=\"key\"))\n```\n\n---\n\nTo flush all keys:\n\n```python\nfrom cacheia_client import Client\n\n\ndefault_url: str = \"http://localhost:5000\"\nclient = Client(url=default_url)\n\nresult = client.flush()\nprint(result.deleted_count)\n```\n\n---\n\nTo flush some keys:\n\n```python\nfrom datetime import datetime\nfrom cacheia_client import Client\n\n\ndefault_url: str = \"http://localhost:5000\"\nclient = Client(url=default_url)\n\nnow = datetime.now().timestamp()\nresult = client.flush(expires_range=(now-10, now+10))\nprint(result.deleted_count)\n```\n\n---\n\nTo flush a single key:\n\n```python\nfrom cacheia_client import Client\n\n\ndefault_url: str = \"http://localhost:5000\"\nclient = Client(url=default_url)\n\nresult = client.flush_key(key=\"key\")\nprint(result.deleted_count)\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Client for cacheia service that allows invalidation and other shenanigans",
"version": "1.0.0.post3",
"project_urls": null,
"split_keywords": [
"client",
" cache",
" http",
" service"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f8348deb5de5b0f9b915023e675ae5b34d935672ce04a59b83db71bc23513067",
"md5": "41badd51cdc2a3885886c4c7d1ef4031",
"sha256": "9257bdad859a8cf4a3914daf01c185b129ce8b1778c524251d279e7d7218d2de"
},
"downloads": -1,
"filename": "cacheia_client-1.0.0.post3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "41badd51cdc2a3885886c4c7d1ef4031",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 4094,
"upload_time": "2024-07-24T17:50:11",
"upload_time_iso_8601": "2024-07-24T17:50:11.757707Z",
"url": "https://files.pythonhosted.org/packages/f8/34/8deb5de5b0f9b915023e675ae5b34d935672ce04a59b83db71bc23513067/cacheia_client-1.0.0.post3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "db12f2586a4fea1a0baf59e468996acf9ccd200197a7f23e85e5804095851f32",
"md5": "a765cd95157b543be544bf6ab4ebcb26",
"sha256": "1ca9ced65ff88e1e2ecda69c42e7ec3550c52c8891776413b5f916826b391081"
},
"downloads": -1,
"filename": "cacheia_client-1.0.0.post3.tar.gz",
"has_sig": false,
"md5_digest": "a765cd95157b543be544bf6ab4ebcb26",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 3619,
"upload_time": "2024-07-24T17:50:14",
"upload_time_iso_8601": "2024-07-24T17:50:14.375143Z",
"url": "https://files.pythonhosted.org/packages/db/12/f2586a4fea1a0baf59e468996acf9ccd200197a7f23e85e5804095851f32/cacheia_client-1.0.0.post3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-24 17:50:14",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "cacheia-client"
}