Pottery

3.0.1 · active · verified Wed Apr 15

Pottery is a Python library that provides Pythonic interfaces to Redis, enabling developers to use Redis data structures and patterns like distributed locks, caches, and queues with familiar Python `dict`, `list`, and `set` semantics. Currently at version 3.0.1, it maintains an active release cadence with frequent updates and bug fixes, supporting modern Python versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to Redis and use `Pottery`'s `RedisDict` which behaves like a standard Python dictionary but is backed by Redis. It covers initialization, adding, accessing, and deleting elements.

import os
from redis import Redis
from pottery import RedisDict

# Ensure Redis is running, e.g., via Docker: docker run -p 6379:6379 redis
# For demonstration, we connect to a local Redis instance.
# In production, use environment variables for Redis URL.
redis_url = os.environ.get('REDIS_URL', 'redis://localhost:6379/1')
redis = Redis.from_url(redis_url)

# Create a Redis-backed dictionary
tel = RedisDict({'jack': 4098, 'sape': 4139}, redis=redis, key='telephone_book')

# Use it like a regular Python dictionary
tel['guido'] = 4127
print(f"Current telephone book: {tel}")
print(f"Jack's number: {tel['jack']}")

del tel['sape']
print(f"After deleting sape: {tel}")

# Check if a key exists
print(f"'guido' in tel: {'guido' in tel}")

# Clean up (optional for quickstart)
redis.delete('telephone_book')

view raw JSON →