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.5.0.tar.gz (11.9 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.5.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openrelik_api_client-0.5.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.6.0

File hashes

Hashes for openrelik_api_client-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e6985a52c88ff6277bb15332aef4c6f40ba33b0cb7b889754386f9dfa678bc3a
MD5 b6d7ec3a6be64d3f188d2a97088bee87
BLAKE2b-256 dc5fa4a8a2b258c0f970542f974d07bb196a79bd7855387216781fec657ce491

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrelik_api_client-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50bc19f5ae3c2c3126bbe72f27983f477230c29dc254eaf32aada59a263c5b92
MD5 43ac0c7e42dec38414c52e6e4399b6f6
BLAKE2b-256 90c607ab49368c3e1ec91f88942ef3883985052a34fd001623426705940d58f0

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