Async Cache CDN client implementation
Project description
Cache CDN Client
A Python client library for interacting with the Cache CDN service based on CAFS, allowing efficient pushing and pulling of cached content.
Installation
pip install cafs-cache-cdn-client
Features
- Asynchronous API for high-performance operations
- Push local directories to cache
- Pull cached content to local directories
- Check existence of cached references
- Tag references for easier access
- Attach additional files to existing references
- Delete references when no longer needed
Usage Example
import asyncio
import logging
from pathlib import Path
from cafs_cache_cdn_client import CacheCdnClient, CompressionT
# Configure logging to see detailed operation information
logging.basicConfig(level=logging.DEBUG)
async def main():
# Initialize the client with the server URL
# The connection_per_cafs_server parameter controls concurrency
client = CacheCdnClient(
'http://cache-server.example.com:8300',
connection_per_cafs_server=10,
verbose_debug=True,
)
# Use as an async context manager to ensure proper resource cleanup
async with client:
# Push a local directory to cache with a 2-hour TTL and preferred ZSTD compression
await client.push('project_name', 'build_artifacts',
'/path/to/build/output', ttl_hours=2,
comment='Build artifacts from CI run #123',
compression=CompressionT.ZSTD)
# Check if a reference exists
exists = await client.check('project_name', 'build_artifacts')
print(f"Reference exists: {exists}")
# Pull cached content to a local directory
await client.pull('project_name', 'build_artifacts',
'/path/to/destination')
# Tag a reference for easier access later
await client.tag('project_name', 'build_artifacts', 'latest_stable')
# Attach an additional file to an existing reference
await client.attach('project_name', 'build_artifacts',
Path('/path/to/metadata.json'))
# Delete a reference when no longer needed
await client.delete('project_name', 'old_artifacts')
# Run the example
if __name__ == '__main__':
asyncio.run(main())
API Reference
CacheCdnClient
-
Constructor:
CacheCdnClient(server: str, connection_per_cafs_server: int = 1)server: URL of the cache serverconnection_per_cafs_server: Number of concurrent connections per CAFS serverlogger: Optional logger for custom loggingverbose_debug: Enable verbose debug logging (default:False)
-
Methods:
push(repo: str, ref: str, directory: Path | str, ttl_hours: int = 0, comment: str | None = None, compression: CompressionT = CompressionT.NONE)- Push a local directory to cachepull(repo: str, ref: str, directory: Path | str)- Pull cached content to a local directorycheck(repo: str, ref: str) -> bool- Check if a reference existstag(repo: str, ref: str, tag: str)- Create a tag for a referenceattach(repo: str, ref: str, file_path: Path)- Attach a file to an existing referencedelete(repo: str, ref: str)- Delete a reference
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
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 cafs_cache_cdn_client-1.0.11.tar.gz.
File metadata
- Download URL: cafs_cache_cdn_client-1.0.11.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/23.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03e756dde00803b296c659cffd1cbf39b2dc553e3860b8810880cb489e63b194
|
|
| MD5 |
e145e6cebad1d93b38f8fb645613758d
|
|
| BLAKE2b-256 |
9c61bedee2f6b26c079ce253fc544560ef80de5946c9ea34ec1b394fc56362ff
|
File details
Details for the file cafs_cache_cdn_client-1.0.11-py3-none-any.whl.
File metadata
- Download URL: cafs_cache_cdn_client-1.0.11-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/23.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43e02b70cd102a7825db876062eee4cd73a930181b77358c0d02d0634662ad6b
|
|
| MD5 |
5430c923bce3d669460f62c4f8c06098
|
|
| BLAKE2b-256 |
f7c3005515153fc2cbc996e3a45bfdb1f1eb5139f091f48b06e925b46cca8583
|