API client that automatically handles token refresh
Project description
OpenRelik API Client
This Python package provides a simple API client (APIClient
) that automatically handles token refresh on 401 (Unauthorized) responses.
- Automatic token refresh: Seamlessly refreshes expired access tokens using a refresh token.
- Easy-to-use interface: Simple methods for common HTTP requests (GET, POST, PUT, DELETE).
- Customizable: Allows you to specify the API server URL, API key, and API version.
Installation
pip install openrelik-api-client
Example: ```python import os from openrelik_api_client import APIClient
# Initialize the API client
api_server_url = "http://localhost:8710"
# API key from environment variable
api_key = os.getenv("OPENRELIK_API_KEY")
# Create the API client. It will handle token refreshes automatically.
api_client = APIClient(api_server_url, api_key)
# Example GET request
response = api_client.get("/users/me/")
print(response.json())
```
How it works:
The APIClient
utilizes a custom session class (TokenRefreshSession
) that intercepts requests and checks for 401 responses. If a 401 response is encountered, it automatically attempts to refresh the access token using the provided refresh token. If the refresh is successful, the original request is retried with the new access token.
Obligatory Fine Print
This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.
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
File details
Details for the file openrelik_api_client-2024.10.3.tar.gz
.
File metadata
- Download URL: openrelik_api_client-2024.10.3.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.1 CPython/3.12.3 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f3fbd26ba17c73f7e6bf07e688cbfcf32cd6acaad9911e1f4d72b136772de91 |
|
MD5 | d7c481265bd05924d692bc7a4809a2dc |
|
BLAKE2b-256 | 1bdc0b1dfd7aa2fa0bf901bcee99802bfcd50a3e759e73c68bd557518109c3ff |
File details
Details for the file openrelik_api_client-2024.10.3-py3-none-any.whl
.
File metadata
- Download URL: openrelik_api_client-2024.10.3-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.1 CPython/3.12.3 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0011123debb10ae71050ef9d659e9ed5190aee4cbcb12f55faaaea231a83212d |
|
MD5 | fb4588b79cfcf92d3a7ced24dcfbf555 |
|
BLAKE2b-256 | bb65aa2eecfee0491f64d2807c7407857492e28069e8bf36f306a8596dd247a9 |