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.0.tar.gz (8.1 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.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openrelik_api_client-0.2.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.12.7 Darwin/24.1.0

File hashes

Hashes for openrelik_api_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5a246e6863d3673bb6450f47036a8657c6161faab0d2b7ebd278692a7fb7a51d
MD5 fc68138a0864e21d00c47f4751a43dad
BLAKE2b-256 973c0b72cfe47d8f563e38c15e958d0fec59a821b4e140cd02df0fa985824d4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrelik_api_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6d87b2ce121614917b71ad04b3de60b0f6d5004f1de104d8da1e363ae3e9608
MD5 0af42079d274535ccd2e059e9ffac3ef
BLAKE2b-256 582f1c57ceb6ba6797b8ac5eab68ad16f6e696467bdee81c4d98e90bef73233d

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