Skip to main content

High-performance cache client with automatic authentication and multi-tenancy

Project description

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 ygg

Quick Start

import os
import ygg

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

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

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

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

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

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

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

# Close connection
ygg.close()

Advanced Operations

Custom Cache Commands

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

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

Pipeline Operations

# Batch operations for better performance
with ygg.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 ygg.set(key, value, ex?) Set key-value pair with optional expiration
get ygg.get(key) Get value by key
delete ygg.delete(key) Delete a key
exists ygg.exists(key) Check if key exists
expire ygg.expire(key, seconds) Set expiration for key
ttl ygg.ttl(key) Get time to live for key
cache ygg.cache(command, *args) Execute any cache command
pipeline ygg.pipeline() Create pipeline for batch operations

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

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

ygglib-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ygglib-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ygglib-0.1.0.tar.gz.

File metadata

  • Download URL: ygglib-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ygglib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 53874bb1890d421b864aa3b295321ec5bb9c4ae756dde03e1f2fb31613c8a1e5
MD5 746906a356fd23860f3dbb0061a3f89e
BLAKE2b-256 bff3e11f07e6c2e294749800c161b6dbbc1af072c6dbe78bdcc59a5b58e60b9a

See more details on using hashes here.

File details

Details for the file ygglib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ygglib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ygglib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cdd684a92ac6eb3282fd3b8615b2eee149c3bec80a21aefcd06006757250f87
MD5 9ab3e26a5fa2595e151074e7aaae2fc0
BLAKE2b-256 a932e961113f701f6645d1fcb409a4a9e051899f3d2b11c850fa8007854f12a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page