Skip to main content

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:

 import os
 from openrelik_api_client.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openrelik_api_client-0.2.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openrelik_api_client-0.2.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file openrelik_api_client-0.2.1.tar.gz.

File metadata

  • Download URL: openrelik_api_client-0.2.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.10.11-1rodete2-amd64

File hashes

Hashes for openrelik_api_client-0.2.1.tar.gz
Algorithm Hash digest
SHA256 98345b448e8931a86d79432aab0be65e4847cc213bcecb070c40ceaa1744adfc
MD5 d44aa738d9092b6ba0ca45aabe353f84
BLAKE2b-256 7e9cdf0d7a3aeaed6dfcc2b68c8e992d3d898792d7ed19a7688e195910e2ab17

See more details on using hashes here.

File details

Details for the file openrelik_api_client-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: openrelik_api_client-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.10.11-1rodete2-amd64

File hashes

Hashes for openrelik_api_client-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a92e9ae1df156a77e19dcda73cb3bdc758965b3e7137ff21c1c3a5bcd026d995
MD5 d7f2e8a75d1e975e140cc64be4e829ea
BLAKE2b-256 6bfad03e8b3ba19dbf9ea77a859991aafef66920e8ccc7d27a80a0c41a12a000

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page