Skip to main content

YGG Python Client

High-performance cache client with automatic authentication and multi-tenancy support for Python.

Visit ygg.kluglabs.net for more information about the YGG platform.

Installation

pip install ygglib

Import

Import the functions you need:

from ygglib import cache, init, set, get, delete, exists, expire, ttl, pipeline, close

Or import specific functions:

from ygglib import cache  # For cache operations
from ygglib import init   # For initialization

Quick Start

import os
from ygglib import cache, init, set, get, delete, exists, expire, ttl, pipeline, close

# Initialize with your API key
init(os.environ.get("YGG_API_KEY"))

# Basic operations
set("greeting", "Hello, World!")
set("user:123:name", "John Doe")
set("session:abc", "active", 3600)  # 1 hour expiration

# Retrieve values
greeting = get("greeting")
user_name = get("user:123:name")
session = get("session:abc")

print(f"Greeting: {greeting}")
print(f"User name: {user_name}")
print(f"Session: {session}")

# Check if keys exist
exists_greeting = exists("greeting")
print(f"Greeting exists: {exists_greeting}")

# Get TTL
ttl_value = ttl("session:abc")
print(f"Session TTL: {ttl_value} seconds")

# Cleanup
delete("greeting")
delete("user:123:name")
delete("session:abc")

# Close connection
close()

Advanced Operations

Custom Cache Commands

from ygglib import cache

# Hash operations
cache("HMSET", "user:123:profile", "age", "30", "city", "New York")
profile = cache("HMGET", "user:123:profile", "age", "city")
print(f"User profile: {profile}")

# List operations
cache("LPUSH", "notifications:123", "Welcome message")
cache("LPUSH", "notifications:123", "System update")
notifications = cache("LRANGE", "notifications:123", 0, -1)
print(f"Notifications: {notifications}")

Pipeline Operations

from ygglib import pipeline

# Batch operations for better performance
with pipeline() as pipe:
    pipe.set("batch:1", "value1")
    pipe.set("batch:2", "value2")
    pipe.set("batch:3", "value3")
    results = pipe.execute()

print(f"Pipeline results: {results}")

Configuration

Configure the client using environment variables:

  • YGG_API_KEY: Your authentication API key (required)
  • YGG_TIMEOUT: Request timeout in seconds (default: 30)
  • YGG_MAX_RETRIES: Maximum retry attempts (default: 3)
  • YGG_RETRY_DELAY: Delay between retries in seconds (default: 1.0)
  • YGG_POOL_SIZE: Connection pool size (default: 10)

Note: The API base URL is always https://ygg-api.kluglabs.net and cannot be changed.

API Reference

Operation Method Description
set set(key, value, ex?) Set key-value pair with optional expiration
get get(key) Get value by key
delete delete(key) Delete a key
exists exists(key) Check if key exists
expire expire(key, seconds) Set expiration for key
ttl ttl(key) Get time to live for key
cache cache(command, *args) Execute any cache command
pipeline pipeline() Create pipeline for batch operations

Import with: from ygglib import cache, set, get, delete, exists, expire, ttl, pipeline, init

Requirements

  • Python 3.7+
  • requests >= 2.25.0

Development

# Clone the repository
git clone https://github.com/Klug-Labs/ygg.git
cd ygg/clients/python

# Install in development mode
pip install -e .

# Run tests
python -m pytest tests/

License

MIT License - see LICENSE file for details.

Support

Metadata

Release files for ygglib 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ygglib 0.1.4
File Size Uploaded Provenance
ygglib-0.1.4.tar.gz 8.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ygglib 0.1.4
File Interpreter ABI Platform
ygglib-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / ygglib-0.1.4.tar.gz

Download URL ygglib-0.1.4.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3b0b76896e9979f917951abc6282f2760249e1538ab7c7d0feb532531a1ea107
BLAKE2b-256 checksum
How to use checksums
9e90fe37a313a363d180f8892f7c9648ac5736b23fc031422f6ed757af2cfae1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / ygglib-0.1.4-py3-none-any.whl

Download URL ygglib-0.1.4-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7d790aa9b12186603e35bbb4ec17f55d62c8431daf9ee10a969ea2d33ed7ab4
BLAKE2b-256 checksum
How to use checksums
50ed428626f3c4f59d668858d100648e81132cd5f9094227bc28641f1c365148
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for ygglib 0.1.4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page