Python SDK for mcache — HTTP and gRPC clients
Project description
mcache-sdk-python
Python SDK for mcache — supports both HTTP and gRPC transports.
Installation
pip install mcache-sdk
Or from source:
pip install -e ".[dev]"
Quick Start
HTTP Client
from mcache.http_client import HttpClient
with HttpClient("http://localhost:8080") as c:
# insert with 60-second TTL
c.insert("user/profile/name", "alice", ttl_seconds=60)
# get by exact prefix
item = c.get("user/profile/name")
print(item.data) # alice
print(item.created_at) # datetime
# update
c.update("user/profile/name", "bob")
# list all children under a path
items = c.list_by_prefix("user/profile")
for it in items:
print(it.prefix, it.data)
# delete
c.delete("user/profile/name")
gRPC Client
from mcache.grpc_client import GrpcClient
with GrpcClient("localhost:9090") as c:
c.insert("user/profile/name", {"age": 30}, ttl_seconds=300)
item = c.get("user/profile/name")
print(item.data) # {"age": 30}
API Reference
Both HttpClient and GrpcClient implement the same CacheClient interface:
| Method | Description |
|---|---|
insert(prefix, data, *, ttl_seconds=0) |
Create a cache entry. Raises AlreadyExistsError if prefix exists. |
get(prefix) |
Get entry by exact prefix. Raises NotFoundError if missing or expired. |
update(prefix, data, *, ttl_seconds=0) |
Update existing entry. Raises NotFoundError if missing. |
delete(prefix) |
Delete entry. Raises NotFoundError if missing. |
list_by_prefix(prefix) |
List all direct children under a prefix path. |
close() |
Release connections. Called automatically via context manager. |
Exceptions
| Exception | When |
|---|---|
mcache.NotFoundError |
Prefix not found or expired |
mcache.AlreadyExistsError |
Duplicate insert |
mcache.McacheError |
Other server or transport errors |
Item fields
@dataclass
class Item:
prefix: str
data: Any # JSON-deserialized value
created_at: datetime
updated_at: datetime
expire_time: Optional[datetime] # None if no TTL set
Requirements
- Python >= 3.9
requests >= 2.31(HTTP client)grpcio >= 1.64(gRPC client)protobuf >= 4.25(gRPC client)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mcache_sdk-0.1.0.tar.gz
(7.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcache_sdk-0.1.0.tar.gz.
File metadata
- Download URL: mcache_sdk-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d89f717ac44a295410f303bc449947db27813dff1ecdd32b322dd6b17902be6
|
|
| MD5 |
59d855803b0b08ac24ae1ed527e284c1
|
|
| BLAKE2b-256 |
f34788d6dc159b6add89ec255c10bbd862a30848136d25d837c8737e9324fd04
|
File details
Details for the file mcache_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcache_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76807af1656983c57a6f192075fc3230ebff46038ad014c3b935eca58987e806
|
|
| MD5 |
cb29e0272b8b9534093a5c9b0fa3c260
|
|
| BLAKE2b-256 |
0a9d600e10e200e3e9ec6ea40a9551402e74f57252c4af76c446e06698a83f32
|