STUPS Tokens
raw JSON → 1.1.19 verified Mon Apr 27 auth: no python maintenance
Python library to manage OAuth access tokens, primarily used within the STUPS infrastructure by Zalando. It retrieves tokens from a token service via OAuth2 client credentials flow. Latest version 1.1.19; no longer actively maintained.
pip install stups-tokens Common errors
error KeyError: 'OAUTH2_ACCESS_TOKEN_URL' ↓
cause Environment variable not set or misspelled.
fix
Export OAUTH2_ACCESS_TOKEN_URL before running your script.
error TypeError: __init__() got an unexpected keyword argument 'ignore_expiration' ↓
cause Using ignore_expiration parameter with an older version of the library.
fix
Upgrade stups-tokens to 1.0.14 or later: pip install --upgrade stups-tokens
error AttributeError: 'NoneType' object has no attribute 'decode' ↓
cause tokens.get() returned None due to token retrieval failure, and code assumed a string.
fix
Check if token is not None before calling .decode() or using it as a string.
Warnings
gotcha The library expects the token service URL via OAUTH2_ACCESS_TOKEN_URL or OAUTH_ACCESS_TOKEN_URL (fallback). If neither is set, it will silently fail with a confusing error. ↓
fix Set OAUTH2_ACCESS_TOKEN_URL before instantiation.
gotcha Token objects are strings, but get() may return None if token retrieval fails. Not checking for None leads to AttributeError. ↓
fix Always check if token is not None before use.
breaking In version 1.0.14, the 'ignore_expiration' flag was added. Code written before that version will not have this parameter, causing TypeError if passed. ↓
fix Upgrade to >=1.0.14 or conditionally pass the flag.
deprecated The library is no longer actively maintained. For new projects, consider alternatives like requests-oauthlib or authlib. ↓
fix Migrate to a maintained OAuth2 library.
Imports
- Tokens wrong
from stups import tokenscorrectfrom stups_tokens import Tokens
Quickstart
import os
from stups_tokens import Tokens
tokens = Tokens(
url=os.environ.get('OAUTH2_ACCESS_TOKEN_URL', ''),
client_id=os.environ.get('CLIENT_ID', ''),
client_secret=os.environ.get('CLIENT_SECRET', ''),
realm='services',
scope='uid'
)
token = tokens.get('myservice')
print(token)