Semcache Python SDK
A Python client library for Semcache
Installation
pip install semcache
Quick Start
from semcache import Semcache
# Initialize the client
client = Semcache(base_url="http://localhost:8080")
# Store a key-data pair
client.put("What is the capital of France?", "Paris")
# Retrieve data by semantic similarity
response = client.get("What's the capital city of France?")
print(response) # "Paris"
The above snippet requires a running Semcache server. You can start one using Docker:
docker run -p 8080:8080 ghcr.io/sensoris/semcache:latest
Configuration
client = Semcache(
base_url="http://localhost:8080", # Semcache server URL
timeout=30, # Request timeout in seconds
)
Usage Examples
Basic Usage
from semcache import Semcache
# Create a client instance
client = Semcache()
# Store some key-data pairs
client.put("What is Python?", "Python is a high-level programming language")
client.put("What is machine learning?", "Machine learning is a subset of AI that enables systems to learn from data")
# Retrieve data - exact match not required
response = client.get("Tell me about Python")
print(response) # "Python is a high-level programming language"
Error Handling
from semcache import Semcache, SemcacheConnectionError, SemcacheTimeoutError
client = Semcache(base_url="http://localhost:8080", timeout=5)
try:
client.put("test query", "test response")
except SemcacheConnectionError:
print("Failed to connect to Semcache server")
except SemcacheTimeoutError:
print("Request timed out")
API Reference
Semcache(base_url="http://localhost:8080", timeout=30)
Initialize a new Semcache client.
Parameters:
base_url(str): The base URL of the Semcache servertimeout(int): Request timeout in seconds
put(key: str, data: str) -> None
Store a key-data pair in the cache.
Parameters:
key(str): The key/query to cachedata(str): The data/response to cache
Raises:
SemcacheError: If the request fails
get(key: str) -> Optional[str]
Retrieve cached data for a key using semantic similarity.
Parameters:
key(str): The key/query to look up
Returns:
Optional[str]: The cached data if found, None otherwise
Raises:
SemcacheError: If the request fails
Exceptions
SemcacheError: Base exception for all Semcache errorsSemcacheConnectionError: Raised when unable to connect to the serverSemcacheTimeoutError: Raised when a request times outSemcacheAPIError: Raised when the API returns an error response
Development
Setup Development Environment
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
Run Tests
pytest
Format Code
black src tests
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a pull request.
Metadata
Release files for semcache 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| semcache-0.1.0.tar.gz | 7.2 kB | Without provenance | Details for semcache-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| semcache-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for semcache-0.1.0-py3-none-any.whl |
Total release size: 12.8 kB
Release files / semcache-0.1.0.tar.gz
| Download URL | semcache-0.1.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15ce98e173892b41cb65f1ab0cb6e7c6ba0b60f2c047e565c0eb658f718c11df
|
|
BLAKE2b-256 checksum How to use checksums |
7ba9eaa41d1c24c1837c9ed1c616d7b1d6c1317a1df977e5b7eda4cad2ca2881
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / semcache-0.1.0-py3-none-any.whl
| Download URL | semcache-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d753f16705a1552728635c64c668f86941a7c80299dab30d515bdb6c70a2a674
|
|
BLAKE2b-256 checksum How to use checksums |
a25b100d8dacf1dcc85de645d0970681c6c252979a4990dc788bd2a200934f26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Security for semcache 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.