pywry.auth.token_store¶
Pluggable token storage backends for OAuth2 tokens.
TokenStore (ABC)¶
pywry.auth.token_store.TokenStore
¶
Bases: ABC
Abstract base class for OAuth2 token storage.
All methods are async to support both local and network-backed stores.
Functions¶
save
abstractmethod
async
¶
Save tokens under the given key.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Unique identifier (e.g., user ID or session key).
TYPE:
|
tokens
|
The token set to persist.
TYPE:
|
load
abstractmethod
async
¶
Load tokens for the given key.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OAuthTokenSet or None
|
The stored token set, or None if not found. |
delete
abstractmethod
async
¶
Delete tokens for the given key.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Unique identifier.
TYPE:
|
exists
abstractmethod
async
¶
Check if tokens exist for the given key.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if tokens are stored for this key. |
list_keys
abstractmethod
async
¶
List all stored token keys.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
All keys with stored tokens. |
MemoryTokenStore¶
pywry.auth.token_store.MemoryTokenStore
¶
Bases: TokenStore
In-memory token store for development and single-process use.
Thread-safe via asyncio.Lock, same pattern as MemorySessionStore.
Initialize the memory token store.
Functions¶
KeyringTokenStore¶
pywry.auth.token_store.KeyringTokenStore
¶
Bases: TokenStore
OS keyring-backed token store for persistent native credentials.
Requires the keyring package: pip install pywry[auth]
| PARAMETER | DESCRIPTION |
|---|---|
service_name
|
Service name for keyring storage (default "pywry-oauth").
TYPE:
|
Initialize the keyring token store.
RedisTokenStore¶
pywry.auth.token_store.RedisTokenStore
¶
RedisTokenStore(redis_url: str = 'redis://localhost:6379/0', prefix: str = 'pywry', pool_size: int = 10)
Bases: TokenStore
Redis-backed token store for multi-worker deployments.
Uses Redis hash keys with optional TTL based on token expires_in.
| PARAMETER | DESCRIPTION |
|---|---|
redis_url
|
Redis connection URL.
TYPE:
|
prefix
|
Key prefix for namespacing (default "pywry").
TYPE:
|
pool_size
|
Connection pool size (default 10).
TYPE:
|
Initialize the Redis token store.
Functions¶
Factory¶
pywry.auth.token_store.get_token_store
¶
get_token_store(backend: str = 'memory', **kwargs: Any) -> TokenStore
Factory function for token stores.
Returns a singleton instance. Call reset_token_store() to clear
the cached instance (e.g. in tests).
| PARAMETER | DESCRIPTION |
|---|---|
backend
|
Storage backend: "memory", "keyring", or "redis".
TYPE:
|
**kwargs
|
Additional keyword arguments passed to the store constructor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TokenStore
|
A configured token store instance. |