token storage made simple
Project description
SimpleTokenStore
The easiest way to manage session tokens.
Are you tired of retrieving session tokens when developing your API interfaces? Do you end up retrieving a new one every time you debug your code? Does your AWS lambda function need to store an api key temporarily? Look no further!
Use Cases:
If you're developing locally and working with api tokens, or using a serverless function like an AWS lambda, you probably want to store session tokens. This library allows you to use them without any overhead. You don't have to worry about token expiry, or storing them in a local file and reading it.
Setup
There are only 2 parts of this libray to interface with
1. Instantiate the token store.
You have a function used to retrieve a new session token, instanitate the token store and pass this in as 'get_new_token_function', for example, if 'new_session' is my function to get a new session token I would write:
resource = SimpleTokenStore(get_new_token=new_session)
(note, it's not new_session(), which would return the result of that call, it's the function itself, a callable).
2. Getting a new token
Call 'collect_token' to retrieve a token, this handles retrieving cached tokens for you. Like this
session_token = resource.collect_token()
Now every time you call resource.collect_token() it will get a token for you, using a cached token if available, and getting a new one when required.
Configuration
To make things super-easy, there are 2 assumptions made if you don't change any settings when using the library.
- tokens are valid for 30 minutes
- you only want to store one token at a time
If either of these are not true, here's how you change it.
Changing token lifetime
Tokens are stored alongside an expiry time, if you want a custom time just add the expires_in_minutes argument to the instanitation. For example
resource = SimpleTokenStore(get_new_token=new_session, expires_in_minutes=60)
would make any stored token valid for 60 minutes from its first saving. Any call to resource.collect_token() after this call for 60 minutes will use the stored token rather than the using the new_session call.
Storing multiple tokens
If you're storing more than one session token, just pass in a value when calling 'collect_token', future calls will store and retrieve a session token from this same key.
For example if I want to store a 'beta' key I would call
resource.collect_token('beta')
and this would store the token separately from the calls to
resource.collect_token('prod')
If I have different methods for retrieving tokens I would create different instances of the SimpleTokenStore, and use different calls to collect_token (passing in different strings) to make sure their stored session tokens don't overwrite each other.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simpletokenstore-1.0.tar.gz.
File metadata
- Download URL: simpletokenstore-1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7d5734096c11acd0ee64a89f7ec414a34dee04d5a82c3cedf5f10e43f2b2965
|
|
| MD5 |
52c665a942ffdb1416997b4fc52600c0
|
|
| BLAKE2b-256 |
b0ffae85876f3f62150099d0bef55a6b6fd477c5a124844765bc27c6c4a94ec1
|
File details
Details for the file simpletokenstore-1.0-py3-none-any.whl.
File metadata
- Download URL: simpletokenstore-1.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9857e48fe62d9c03da314fb1505aef6c034d69489a6dd0f01d3ee21891765c50
|
|
| MD5 |
8b6af8afd0f500a120bc43af6e385a5d
|
|
| BLAKE2b-256 |
9f8c434a00df716a7b51fe8e57b25a183d1789b3388375fdfe6198f4126025c1
|